why controller.should_receive(:before_filter_name) return error in rspec?
We uses controller.should_receive(:before_filter_name) in rspec to by pass
the before filter in our rails 3.2 rspec. But for some before filter,
rspec returns error.
Here is the def of before filter check_availability:
def check_availability
if find_config_const('sales_lead', 'customerx').nil? or
find_config_const('sales_lead', 'customerx') == 'false'
redirect_to authentify.signin_path, :notice => "Quit!"
end
end
To by-pass the check_availability, we put the following code in rspec for
the controller:
before(:each) do
controller.should_receive(:require_signin)
controller.should_receive(:check_availability)
end
Filter require_signin has no problem. However for the 2nd filter, there is
an error:
2) Customerx::SalesLeadsController GET 'new' should redirect user without
proper right
©[31mFailure/Error:©[0m
©[31mcontroller.should_receive(:check_availability)©[0m
©[31m(#<Customerx::SalesLeadsController:0x6fb3478>).check_availability(any
args)©[0m
©[31m expected: 1 time©[0m
©[31m received: 0 times©[0m
©[36m #
./spec/controllers/customerx/sales_leads_controller_spec.rb:7:in `block (2
levels) in <module:Customerx>'©[0m
We don't quite understand how should_receive works here. We have seen a
few cases like this and would like to find out what causes the rspec to
fail. Thanks for the help.
No comments:
Post a Comment