request testing with Warden/Devise

I have been strugging to get (rspec) test coverage on some Active Scaffold controllers. The problem is that there aren’t really any controllers that you can test with a controller test, and there are no .html.erb files either, so you can’t do a view test. In the Test:Unit days, one would have done a “functional” test, but it seemed at first that this didn’t exist in rspec.

Not so, you can use “request” tests, and with capybara it’s pretty readable too. But, still I was struggling, I kept getting:

1) Admin::Users GET /en/admin/users renders a list of users for admin to see Failure/Error: Unable to find matching line from backtrace NoMethodError: undefined method `env' for nil:NilClass # /var/lib/gems/1.9.1/gems/devise-1.5.4/lib/devise/test_helpers.rb:25:in `setup_controller_for_warden'

and I couldn’t figure this out. I litered my very elementary test case with debugger calls, and was surprised when my before(:each) wasn’t even called. I removed that as it seemed to be in the setup hooks that things were going bad. In the above line, @request is nil!

Finally, I removed: include Devise::TestHelpers from my spec file, and things started to work.

Aha, so the devise test helpers just can’t be used for signin. That’s okay, one should probably login the “normal” way anyway.