[rspec-users] Access to controller and request objects in controller specs (rails 3)

David Chelimsky dchelimsky at gmail.com
Sun Mar 14 11:15:22 EDT 2010


On Mar 12, 2010, at 9:44 AM, stevehodgkiss wrote:

> Hi
> 
> Rails 3 provides @controller and @request as instance variables in
> controller tests, whats the equivalent in rspec controller tests?
> 
> I'm using warden for authentication and need to be able to stub
> @request.env['warden'] with something so that controllers can be
> tested. Currently @request is nil (error: undefined method `env' for
> nil:NilClass).
> 
> If I remember correctly the default controller specs in rails 2/rspec
> 1 contained this assertion:
> 
> controller.should be_an_instance_of(MyController)
> 
> This fails with rails 3/rspec 2 beta 3 because controller is nil.
> 
> Any ideas?

Right now, rspec-2 controller specs include rails integration test behaviour, not rails controller test behaviour. Before rails-3 and rspec-rails-2 go final, we'll figure out a way to provide access to a controller object, but things are a bit fluid right now on both fronts, so it might not be available for a bit.

There is a ticket about this on lighthouse:

https://rspec.lighthouseapp.com/projects/5645/tickets/963

Please feel free to follow that ticket and/or weigh in on it.

Cheers,
David


More information about the rspec-users mailing list