I would like to check if the action of the controller was actually called without redirecting in some before_filter file. Since the controller action itself can do a redirect, I want to stub the action to raise a specific error (SuccessfulActionError or the like), and then check this error as an indicator that the method has been called.
So, I added the following:
controller.stub!(:action).and_raise(SuccessfulActionError)
Somehow it works, an exception occurs, but the actual code in the method is still executing (for example, if I send the identifier of a nonexistent record to the "show" action, it throws an ActiveRecord :: RecordNotFound exception).
Why? I want to completely close the action, as if it were implemented as
def action raise SuccessfulActionError end
What am I doing wrong? Is this the wrong approach?
EDIT:
Using
controller.should_receive(:action)
doesn't work either.
I am rewriting the controller into the before_all filter like this to fix default_url_options that are not selected from ApplicationController:
class MyController def default_url_options(options = {}) { :locale => params[:locale] } end end
Could this be the culprit? Specifications do not work at all when I delete it, unfortunately.
source share