Access to controller and request objects in controller specs (rails 3)

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?

Thanks

Steve

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs