Skip to content

controller is nil in global before(:each, :type => :controller) hook #23

Closed
zealoushacker opened this Issue May 3, 2011 · 4 comments

4 participants

@zealoushacker

RSpec version: 2.4.0

I've defined method in ApplicationController, which is called via a before_filter.

I then added the following to spec_helper.rb:

RSpec.configure do |config|
  config.before(:each, :type => :controller) do
    controller.stub(:method)
  end
end

Every spec example throws the following:

FAn expectation of :method was set on nil. Called from spec/spec_helper.rb:75:in `block (2 levels) in <top (required)>'. Use allow_message_expectations_on_nil to disable warnings.

This leads me to conclude that controller is nil in global before(:each, :type => :controller) hooks.

@davidgrieser

+1

Still seems to happen in RSpec 2.5.1 as well.

@trkoch
trkoch commented Jun 5, 2011

+1

Observed in RSpec 2.6.3

@dchelimsky
Owner

This is not going to be fixed in rspec-rails-1.x as it would require some re-architecting.

See rspec/rspec-rails#391 for info on same issue in rspec-rails-2.

@dchelimsky dchelimsky closed this Jun 5, 2011
@zealoushacker

David, thanks for the feedback. I'll be watching the issue in rspec-rails-2 more closely. wdso thank you for re-opening this issue in the appropriate place.

Cheers,
Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.