croceldon
croceldon

Reputation: 4615

Why is mocha not stubbing this method in my Rails 3 integration test?

I have the following:

  setup do
    Capybara.current_driver = Capybara.javascript_driver
    @project.user = @user
    @project.save
    Project.any_instance.stubs(:price_all)
  end

And yet I have a test failing because the Project.price_all method is being run:

/Users/me/code/rails/myapp/app/models/project.rb:178:in `price_all'

This was working properly until I upgraded to Capybara 2 and the latest version of capybara-webkit.

Why is that method still being run? And how can I fix?

Upvotes: 0

Views: 237

Answers (1)

Cade
Cade

Reputation: 3181

When you say "the Project.price_all method is being run", is that a typo, or is price_all really a class method? If it is indeed a class method, you'll want to use Project.stubs(:price_all) instead of including any_instance so the stub is directly on the Project class rather than an instance of Project. If that's not your issue, I'm not sure what else to suggest based on the code sample you've provided.

Upvotes: 0

Related Questions