Comments (8)
@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.
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.
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.
Hey @bokmann. Just wondering if you ever did get round to using this in production? :)
from propono.
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.
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.
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.
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)
- Travis CI Build Failures Due to Bundler Version HOT 1
- wrong number of arguments (given 5, expected 4) HOT 3
- Asynchronous listen_to_queue HOT 2
- License info on gh-pages branch inconsistent with LICENSE.md HOT 1
- Use IAM role instead of access & secret keys HOT 3
- Need a way to pass Subject for the SNS payload HOT 9
- Way to use FIFO queues? HOT 5
- Should we merge iterum into Propono HOT 2
- Message Visibility Timeout is too short for some classes of tasks HOT 3
- Docs - Note about needing a subscriber before you publish
- Docs - Flowchart of corrupted/failed/etc queue logic
- Docs - Description/diagram of single-queue-multiple-listener vs fanout
- How do I use GoAWS? HOT 3
- Update repository HOT 1
- Javascript subscriber HOT 7
- ArgumentError: invalid configuration option `:use_iam_profile' HOT 2
- Queue size and oldest message? HOT 1
- Multiple listen blocks on the same file HOT 7
- Slow queue wait implementation causes delay in processing of new main queue messages HOT 2
- messages being processed multiple times by same worker name HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from propono.