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 8497455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:07:50+00:00 2026-06-11T00:07:50+00:00

I am setting up a test that should expect calls on two subscriber instances:

  • 0

I am setting up a test that should expect calls on two “subscriber” instances:

  it "sends out sms to all the subscribers" do
    @user.subscribers.create!
    @user.subscribers.create!

    Subscriber.any_instance.should_receive(:send_message).with(@message).times(2)
    post :create, {:broadcast => valid_attributes}   
  end

The actual code is:

  def create
    @broadcast = Broadcast.new(params[:broadcast])
    current_user.subscribers.each do |subscriber|
      subscriber.send_message(@broadcast.message)
    end

    ...

The error:

  Failure/Error: post :create, {:broadcast => valid_attributes}
     ArgumentError:
       wrong number of arguments (1 for 0)
     # ./app/controllers/broadcasts_controller.rb:41:in `block in create'
     # ./app/controllers/broadcasts_controller.rb:40:in `create'
     # ./spec/controllers/broadcasts_controller_spec.rb:73:in `block (4 levels) in <top (required)>'

For some reason, if I add the line: Subscriber.any_instance.should_receive(:send_message).with(@message).times(2), it fails with that error message. If I remove that line, the test runs smoothly (no wrong number of argument problem). What am I doing wrong?

  • 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-11T00:07:52+00:00Added an answer on June 11, 2026 at 12:07 am

    The error you’re getting is because the ‘times’ method is expected to be chained onto one of the other “receive count” expectations. You can use any one of the following:

    should_receive(:send_message).with(@message).exactly(2).times
    should_receive(:send_message).with(@message).at_most(2).times
    

    You can also use one of the other alternatives that does not require the ‘times’ method:

    should_receive(:send_message).with(@message).twice
    should_receive(:send_message).with(@message).at_most(:twice)
    

    More on that can be found in the rspec-mocks documentation

    You may need to set the expectation BEFORE creating the subscribers:

    it "sends out sms to all the subscribers" do
      Subscriber.any_instance.should_receive(:send_message).with(@message).twice
    
      @user.subscribers.create!
      @user.subscribers.create!
    
      post :create, {:broadcast => valid_attributes}   
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting up a simple test page in Python. I only have two
I've been looking into setting up a Selenium test suite recently but all of
I want to test that setting a certain property (or more generally, executing some
I am setting up unit tests to run methods that should generate an NSError.
I have a simple RabbitMQ test program that sends and then receives a message
HI, I want to have set configuration settings for a unit test project that
In EL, I want to access the value ${settings_123456.settingsMap[test].value} The problem is that settings_123456
I'm developing an alternate backend for the canvas interface. I started setting up test
I am having a problem setting up a simple test project for SignalR. I
I'm a bit confused on setting up the boost test library. Here is my

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.