Devise: NameError when including Devise::Test::ControllerHelpers

Created on 30 May 2016  路  3Comments  路  Source: heartcombo/devise

After setting up a new app using Rails 4.2.5 with Devise 4.1.1 and Warden 1.2.6, I created a User model authenticating with email and password. I'm trying to setup the spec helpers as per the README. In spec/support/devise.rb, if I include

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
end

as the README describes, I get uninitialized constant Devise::Test (NameError) (full stack trace at the bottom) when I run bundle exec rspec. However, if I include

RSpec.configure do |config|
  config.include Devise::TestHelpers, type: :controller
  config.include Devise::TestHelpers, type: :view
end

as per the first example application, it works. Looking at the Devise code, though, suggests that the latter is depracated. Namely, in lib/devise/test_helpers.rb, lines 7 and 8 say For controller tests, please include Devise::Test::ControllerHelpers instead. DEPRECATION.

Example application: https://github.com/jroggeman/spikes

Full stack trace:

/Users/joel/Code/spikes/spec/support/devise.rb:2:in `block in <top (required)>': uninitialized constant Devise::Test (NameError)
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core.rb:97:in `configure'
    from /Users/joel/Code/spikes/spec/support/devise.rb:1:in `<top (required)>'
    from /Users/joel/Code/spikes/spec/rails_helper.rb:23:in `block in <top (required)>'
    from /Users/joel/Code/spikes/spec/rails_helper.rb:23:in `each'
    from /Users/joel/Code/spikes/spec/rails_helper.rb:23:in `<top (required)>'
    from /Users/joel/Code/spikes/spec/models/user_spec.rb:1:in `require'
    from /Users/joel/Code/spikes/spec/models/user_spec.rb:1:in `<top (required)>'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/joel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
    from ./bin/rspec:16:in `load'
    from ./bin/rspec:16:in `<main>'

Most helpful comment

Devise::Test::ControllerHelpers is not in Devise 4.1.1, it's only in the current master branch. If you browse the code for 4.1.1 you'll find that it still uses Devise::TestHelpers, and the documentation in the README is correct.

All 3 comments

Similarly, include Devise::TestHelpers in the controller test superclass gets around the same problem when not using Rspec.

Devise::Test::ControllerHelpers is not in Devise 4.1.1, it's only in the current master branch. If you browse the code for 4.1.1 you'll find that it still uses Devise::TestHelpers, and the documentation in the README is correct.

Ahh, I see. Sorry about that. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yovasx2 picture yovasx2  路  4Comments

Gorchel picture Gorchel  路  3Comments

HerbertKoelman picture HerbertKoelman  路  3Comments

Pedroknoll picture Pedroknoll  路  3Comments

BimaPanduW picture BimaPanduW  路  3Comments