Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:45:58+00:00 2026-06-10T10:45:58+00:00

So based on my understanding, I beleive when you do Resque.inline = Rails.env.test? Your

  • 0

So based on my understanding, I beleive when you do

Resque.inline = Rails.env.test?

Your resque tasks will run synchronously. I am writing a test on resque task that gets enqueue during an after_commit callback.

after_commit :enqueue_several_jobs

#class PingsEvent < ActiveRecord::Base
...
   def enqueue_several_jobs
      Resque.enqueue(PingFacebook, self.id)
      Resque.enqueue(PingTwitter, self.id)
      Resque.enqueue(PingPinterest, self.id)
   end

In the .perform methd of my Resque task class, I am doing a Rails.logger.info and in my test, I am doing something like

..
Rails.logger.should_receive(:info).with("PingFacebook sent with id #{dummy_event.id}")
PingsEvent.create(params)

And I have the same test for PingTwitter and PingPinterest.

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 MockExpectationError telling me that Rails.logger did not receive .info for the other two tests. Anyone has had experience with this before?

EDIT

Someone mentioned that should_receive acts like a mock and that I should do .exactly(n).times instead. Sorry for not making this clear earlier, but I have my expectations in different it blocks and I don’t think a should_receive in one it block will mock it for the next it block? Let me know if i’m wrong about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:46:00+00:00Added an answer on June 10, 2026 at 10:46 am
    class A
      def bar(arg)
      end
    
      def foo
        bar("baz")
        bar("quux")
      end
    end
    
    describe "A" do
      let(:a) { A.new }
    
      it "Example 1" do
        a.should_receive(:bar).with("baz")
        a.foo # fails 'undefined method bar'
      end
      it "Example 2" do
        a.should_receive(:bar).with("quux")
        a.foo # fails 'received :bar with unexpected arguments
      end
      it "Example 3" do
        a.should_receive(:bar).with("baz")
        a.should_receive(:bar).with("quux")
        a.foo # passes
      end
      it "Example 4" do
        a.should_receive(:bar).with(any_args()).once
        a.should_receive(:bar).with("quux")
        a.foo # passes
      end
    end
    

    Like a stub, a message expectation replaces the implementation of the method. After the expectation is fulfilled, the object will not respond to the method call again — this results in ‘undefined method’ (as in Example 1).

    Example 2 shows what happens when the expectation fails because the argument is incorrect.

    Example 3 shows how to stub multiple invocations of the same method — stub out each call with the correct arguments in the order they are received.

    Example 4 shows that you can reduce this coupling somewhat with the any_args() helper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Gmail support RFC 821? I know it is using ESMTP. Based on understanding
Based on my understanding of the Java language, static variables can be initialized in
Normally ( Based on my understanding ) i have to follow a lot of
My understanding is that Java's implementation of regular expressions is based on Perl's. However,
I'm having difficulty understanding variable shadowing in JavaScript based on scopes. Consider this small
This question probably is based on my lack of understanding of the role of
I've been working with some ExternalDataExchange - based communication in WF recently. My understanding
Based on my understanding, SerializableAttribute provides no compile time checks, as it's all done
I am learning some basic in rails, and found a difficulty in understanding a
Based on my understanding, the basic difference between traps and interrupts is that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.