Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting expectation on resque .perform method. Task is enqueued in a Callback
    primarykey
    data
    text
    <p>So based on my understanding, I beleive when you do </p> <p><code>Resque.inline = Rails.env.test?</code></p> <p>Your resque tasks will run synchronously. I am writing a test on resque task that gets enqueue during an <code>after_commit</code> callback.</p> <p><code>after_commit :enqueue_several_jobs</code></p> <pre><code>#class PingsEvent &lt; ActiveRecord::Base ... def enqueue_several_jobs Resque.enqueue(PingFacebook, self.id) Resque.enqueue(PingTwitter, self.id) Resque.enqueue(PingPinterest, self.id) end </code></pre> <p>In the <code>.perform</code> methd of my Resque task class, I am doing a <code>Rails.logger.info</code> and in my test, I am doing something like</p> <pre><code>.. Rails.logger.should_receive(:info).with("PingFacebook sent with id #{dummy_event.id}") PingsEvent.create(params) </code></pre> <p>And I have the same test for <code>PingTwitter</code> and <code>PingPinterest</code>.</p> <p>I am getting failure on the 2nd and third expectation because it seems like the tests actually finish before all the resque jobs get run. Only the first test actually passes. RSpec then throws a <code>MockExpectationError</code> telling me that <code>Rails.logger</code> did not receive <code>.info</code> for the other two tests. Anyone has had experience with this before? </p> <h1>EDIT</h1> <p>Someone mentioned that <code>should_receive</code> acts like a <code>mock</code> and that I should do <code>.exactly(n).times</code> instead. Sorry for not making this clear earlier, but I have my expectations in different <code>it</code> blocks and I don't think a <code>should_receive</code> in one <code>it</code> block will mock it for the next <code>it</code> block? Let me know if i'm wrong about this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload