Coder Social home page Coder Social logo

testing strategies? about propono HOT 8 CLOSED

ihid avatar ihid commented on August 18, 2024
testing strategies?

from propono.

Comments (8)

iHiD avatar iHiD commented on August 18, 2024

@bokmann Yeah, basically.

For example, in one app this code:

def foobar(id)
  Propono.publish(:videos, { entity: "video", action: "processed", video_id: id})
end

might get tested in rspec with:

Propono::Publisher.expects(:publish).with(:videos, { entity: "video", action: "processed", video_id: "123" } )
foobar(123)

If you don't know a param in advance (e.g. if you're testing a callback), it gets slightly trickier. For example, we test this extract:

class KnowledgeBank::QuestionCreator
  #...
  def create
    @question = @user.knowledge_bank_questions.create(@params)
    message = { entity: "question", action: "created", question_id: @question.id}
    Propono.publish(:knowledge_bank, message)
  end
end

with this:

let(:user) {create :user}
let(:title) {"Foobar"}
it "should publish to Propono" do
  Propono::Publisher.should_receive(:publish).once.with do |topic, payload, options|
    question = KnowledgeBank::Question.last
    topic == 'knowledge_bank' &&
    payload == { entity: "question", action: "created", question_id: question.id} &&
    options == {}
  end
  KnowledgeBank::QuestionCreator.create!(user, title: title, content: content)
end

That make sense?

from propono.

iHiD avatar iHiD commented on August 18, 2024

And yeah, the listener is similar:

From a project that uses minitest:

topic = "my-topic"
queue_suffix = "_test"
queue_name = "#{topic}#{queue_suffix}"
id = "9"
message = { id: id, action: "send_email"}
Propono.expects(:listen_to_queue).with(queue_name).yields(message, {:id => "1234"})

from propono.

bokmann avatar bokmann commented on August 18, 2024

Thanks for the feedback! I'm days away from using this for realz. I'd like to contribute something back to the readme once I work out the testing... I might even build some kind of capture for development, kinda like the letter_opener gem does for email.

from propono.

iHiD avatar iHiD commented on August 18, 2024

Hey @bokmann. Just wondering if you ever did get round to using this in production? :)

from propono.

bokmann avatar bokmann commented on August 18, 2024

Using the gem? kinda. Short story - using the acts_as_state_machine gem, we are running code triggered by the entry into a state. We know when we get volume on the site this will be a pain-point; the code runs within the rails request/response cycle as it stands currently. Ideally I want to change that so that entry into the state publishes an event, and a propano listener does something with it later. We haven't had the volume that makes us worry yet, so we haven't introduced this yet. The tests we wrote simple expect a Propano.publish; we haven't done anything to test receiving the events, and I haven't explored the 'capture' concept I was previously talking about.

from propono.

iHiD avatar iHiD commented on August 18, 2024

Thanks for the update. If you do start using it more fully and want to bounce any ideas or questions around, please let us know!

from propono.

bokmann avatar bokmann commented on August 18, 2024

Have you seen ActiveJob? https://github.com/rails/activejob This isn't quite a full job-queue implementation, but it would be an interesting piece of one...

from propono.

jcabasc avatar jcabasc commented on August 18, 2024

Hey @iHiD pretty cool gem, I'm wondering how you guys do tests around listeners, specifically in the callbacks. do you happen to have an example with rspec or another library? Thanks so much.

from propono.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.