[rspec-users] Failure trying to test ApplicationController

Steve vertebrate at gmail.com
Tue Oct 16 01:07:47 EDT 2007


On Mon, 15 Oct 2007 23:46:32 -0500, David Chelimsky wrote:

> On 10/15/07, Steve <vertebrate at gmail.com> wrote:
>> I'm trying to write some tests for the ApplicationController as shared
>> tests that can be run in all of my other controller tests, but am getting
>> a nil.rewrite error. Below is what I have...
>>
>> describe AccountController do
>>   it_should_behave_like 'Application controller'
>> end
>>
>> describe 'Application controller', :shared => true do
>>
>>   it 'should fail require_login check if not logged in' do
>>     User.current = nil
>>     controller.require_login.should be_false
>>     response.should redirect_to(:controller => 'account', :action => 'logon')
>>   end
>> end
>>
>> def require_login
>>   return true if User.current.logged_in?
>>
>>   redirect_to :controller => "account", :action => "logon" and return false
>> end
>>
>> The line it's failing on is the redirect_to in require_login. What am I
>> doing wrong?
> 
> What's the error?

NoMethodError in 'AccountController should fail require_login check if not logged in'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.rewrite
trunk/app/controllers/application.rb:28:in `require_login'
./spec/controllers/application_controller_spec.rb:12:

The "redirect_to" call is line 28, and "controller.require_login.should"
is line 12.



More information about the rspec-users mailing list