Hey everyone I am trying to get Rspec to test if an action calls a specific method in a model I have which inherits from ActiveMailer but have been having no luck. So as a quick mockup I have the following scenario. Model UserNotifier:
class UserNotifier < ActionMailer::Base
def foobaz
end
end
Controller Password Controller:
class PasswordsController < ApplicationController
def foobar
UserNotifier.foobaz
end
And the spec:
describe "GET 'foobar'" do
it "should call the UserNotifier foobaz method" do
UserNotifier.should_receive(:foobaz)
get :foobar
end
end
but I always end up with this failure:
1) PasswordsController GET 'foobar' should call the UserNotifier foobaz method
Failure/Error: UserNotifier.should_receive(:foobaz)
(<UserNotifier (class)>).foobaz(any args)
expected: 1 time
received: 0 times
Can anyone enlighten me as to why RSpec does not register that the UserNotifier.foobaz method is being called?
Answered in the comments by Ryan Bigg. Ended up being a before_filter which was causing the method to never be run
I've got exactly the same problem, but it's not due to any filters (not using any). One difference is that I'm calling an action on ApplicationController, though I don't see why that would matter. The foobaz method definitely gets called, given that the rspec run includes output I insert there, yet Rspec doesn't see the call. Any other ideas for what could be wrong?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.