I have a similar error posted here, but all will not fix my problem.
My file 'spec/request/news_controller_spec.rb' looks like:
require 'spec_helper'
describe "NewsController" do
include Devise::TestHelpers
describe "GET /news" do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = Factory.create(:user)
@user.confirm!
sign_in @user
end
it "after login should show the latest news an screen" do
page.should have_content("News")
end
end
end
If I run the test I'll get:
Failures:
1) Campaigns GET /news works!
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /Users/.../gems/devise-1.5.3/lib/devise/test_helpers.rb:25:in `setup_controller_for_warden'
# /Users/.../gems/rspec-rails-2.8.1/lib/rspec/rails/adapters.rb:15:in `block (2 levels) in setup'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:35:in `instance_eval'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:35:in `run_in'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `block in run_all'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `each'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:70:in `run_all'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/hooks.rb:368:in `run_hook'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `block in run_before_each_hooks'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `each'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:292:in `run_before_each_hooks'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example.rb:217:in `run_before_each'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example.rb:79:in `block in run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example.rb:173:in `with_around_hooks'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example.rb:77:in `run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:355:in `block in run_examples'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:351:in `map'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:351:in `run_examples'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:337:in `run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `block in run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `map'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:338:in `run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `map'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:28:in `block in run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/reporter.rb:34:in `report'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:25:in `run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
# /Users/.../gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
I followed instructions on https://github.com/plataformatec/devise/wiki/How-To%3a-Controllers-and-Views-tests-with-Rails-3-%28and-rspec%29 and other similar Questions here, but I can't find a solution.
I'm using following gemset:
- capybara (1.1.2)
- devise (1.5.3)
- factory_girl_rails (1.6.0)
- rails (3.2.0, 3.1.1)
- rspec (2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- rspec-mocks (2.8.0)
- rspec-rails (2.8.1)
and some other gems.
Can anybody help me, getting my integration tests with a logged in user get running. In this case the news are only displayed, if a user is logged in.
Thanks.
Test::Unit
andRSpec
configurations? As of rspec-rails-2.0.0 and devise-1.1, the best way to put devise in your specs is simply to add the following into spec_helper: gist.github.com/1682113 – jibielRSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller end
. The files in the support-directory should be included byDir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
. Right? – big_geron:type => :controller
part. Just removed it and got same error. – jibiel:type => :controller
. – big_geron