How would one test that when an action in controller is being accessed, that controller's before_filter will be executed?
The before_filter is tested in separate example group so that there's no need to duplicate the tests for all actions that depend on the before_filter.
If I have
controller.should_receive(:my_before_filter)
in my example, it works fine. However, having the above expectation seems to cause that the logic in my_before_filter
is not being executed (it should assign an instance variable).
How to overcome this restriction or to mock behaviour of my_before_filter (it sets instance variable on controller)? Or is there some better way to do this?
As it's now clear I was doing it all wrong, I'd still like to know how one could mock the behaviour of before_filter that sets an instance variable. Surely it must be a possible to do this in a controller spec?
Testing the filter is looking too closely at the implementation, IMO. You want to ensure that the instance variable assignment is happening, not whether it takes place within a filter or within an action -- test the outcome, not the implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With