[rspec-users] disabling before filters in rspec?

jollyroger timo.roessner at googlemail.com
Sun Jan 3 19:56:26 EST 2010

Hey guys,

i have this before-filter in my application-controller:

  def login_required
    if !current_user
      redirect_to join_welcome_path and return

This before-filter is prepended before all other before-filters in my
application_controller.rb like this

 prepend_before_filter :login_required,

Now i want  to test  a controller which should only be accessible if
the user is logged in like that:

  describe "new action" do

    describe "before-filter requirements are not met" do

      before(:each) do

      it "should redirect to join_welcome_path if not logged in" do
        get :new
        response.should redirect_to(join_welcome_path)

The thing is, I would have expected this spec to pass - a call to
"new" invokes the login-required before-filter which redirects to the

Instead i get:

NoMethodError in 'Shopping::PaymentsController new action before-
filter requirements are not met should redirect to join_welcome_path
if not logged in'
undefined method `current_cart_size' for nil:NilClass

which is from a before-filter which is triggered _after_ the login-
required before-filter.

How do I even get there?
As far as I understood the docs, this line:


should cause a redirect, so how do i even get to subsequent before-

In a nutshell:

Why do I even reach subsequent before-filters?
What am I doing wrong here?

More information about the rspec-users mailing list