Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5/RSpec/Device - method_missing: undefined method setup #4189

Closed
Blazy7 opened this issue Jul 12, 2016 · 13 comments
Closed

Rails 5/RSpec/Device - method_missing: undefined method setup #4189

Blazy7 opened this issue Jul 12, 2016 · 13 comments

Comments

@Blazy7
Copy link

Blazy7 commented Jul 12, 2016

Hello, after upgrade from Rails 5.0.0rc1 to Rails 5.0.0 and try to bundle exec rspec spec/ i get error method_missing': undefined methodsetup'

/Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:732:in `method_missing': undefined method `setup' for RSpec::ExampleGroups::AdminOrdersController:Class (NoMethodError)
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/devise-4.2.0/lib/devise/test/controller_helpers.rb:28:in `block in <module:ControllerHelpers>'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/concern.rb:120:in `class_eval'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/concern.rb:120:in `append_features'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/devise-4.2.0/lib/devise/test_helpers.rb:9:in `include'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/devise-4.2.0/lib/devise/test_helpers.rb:9:in `block in included'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/devise-4.2.0/lib/devise/test_helpers.rb:4:in `class_eval'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/devise-4.2.0/lib/devise/test_helpers.rb:4:in `included'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:2063:in `include'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:2063:in `safe_include'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:2025:in `block in configure_group_with'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:2024:in `each'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:2024:in `configure_group_with'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/configuration.rb:1365:in `configure_group'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:429:in `set_it_up'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:384:in `subclass'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/example_group.rb:258:in `block in define_example_group_method'
    from /Users/Hristo/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.1/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
    from /Users/Hristo/Work/thc-store/spec/controllers/admin/orders_controller_spec.rb:3:in `<top (required)>'

Gemfile:

source 'https://rubygems.org'

ruby '2.2.4'
gem 'rails', '>= 5.0.0.rc1'
...
group :test do
  gem 'rspec-rails', '~> 3.0'
  gem 'factory_girl_rails', '~> 4.5'
  gem 'shoulda-matchers'
  gem "vcr"
  gem "webmock"
  gem 'timecop'
  gem 'rails-controller-testing'
end

Any help will be appreciated. Thanks.

@Blazy7 Blazy7 changed the title Rails 5 Rails 5/RSpec/Device - method_missing': undefined methodsetup' Jul 12, 2016
@Blazy7 Blazy7 changed the title Rails 5/RSpec/Device - method_missing': undefined methodsetup' Rails 5/RSpec/Device - method_missing': undefined method /setup' Jul 12, 2016
@Blazy7 Blazy7 changed the title Rails 5/RSpec/Device - method_missing': undefined method /setup' Rails 5/RSpec/Device - 'method_missing': undefined method 'setup' Jul 12, 2016
@Blazy7 Blazy7 changed the title Rails 5/RSpec/Device - 'method_missing': undefined method 'setup' Rails 5/RSpec/Device - method_missing: undefined method setup Jul 12, 2016
@jasnow
Copy link

jasnow commented Jul 12, 2016

See if you have the "setup" script in your repo's "bin" directory.

@Blazy7
Copy link
Author

Blazy7 commented Jul 12, 2016

I have setup script with content:

#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
  system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
  # This script is a starting point to setup your application.
  # Add necessary setup steps to this file.

  puts '== Installing dependencies =='
  system! 'gem install bundler --conservative'
  system('bundle check') or system!('bundle install')

  # puts "\n== Copying sample files =="
  # unless File.exist?('config/database.yml')
  #   cp 'config/database.yml.sample', 'config/database.yml'
  # end

  puts "\n== Preparing database =="
  system! 'bin/rails db:setup'

  puts "\n== Removing old logs and tempfiles =="
  system! 'bin/rails log:clear tmp:clear'

  puts "\n== Restarting application server =="
  system! 'bin/rails restart'
end

@lucasmazza
Copy link
Contributor

@Blazy7 can you please provide a sample app that reproduces the error? This sound like a possible issue with the controller test setup.

@viamin
Copy link

viamin commented Jul 19, 2016

I've also hit this with devise 4.2.0, rails 5.0.0 and rspec-rails 3.5.1. This occurs when trying to run my controller specs.

Rolling back to devise 4.1.0 and changing
config.include Devise::Test::ControllerHelpers, type: :controller
to
config.include Devise::TestHelpers, type: :controller
fixes the issue for me.

This could be an issue with the additional module nesting. setup is defined in the Devise module (line 291), and doesn't seem to be available in the Devise::Test::ControllerHelpers namespace.

zephiransas added a commit to zephiransas/devise that referenced this issue Jul 22, 2016
@zephiransas
Copy link

devise 4.2.0
Rails 4.2.6
rspec-rails 3.4.2

I write some controller helper for controller test.
in spec/support/controller_helpers.rb like this...

module ControllerHelpers
  include Devise::Test::ControllerHelpers
  (snip)

in rails_helper.rb,

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

when call this line, this issue occured.

@Blaked84
Copy link

Same issue as @zephiransas.

In my mycontroller_controller_spec.rb :
include Devise::TestHelpers

devise 4.2.0
Rails 4.2.3
rspec-rails 3.5.1

If I rollback to devise 4.1.1, this issue disappears.

@lucasmazza
Copy link
Contributor

@zephiransas @Blaked84 in those cases you shouldn't include the module inside another directly, but use your ControllerHelpers included hook to include the Devise test helper inside the host test/spec class:

module ControllerHelpers
  extend ActiveSupport::Concern

  included do
    include Devise::Test::ControllerHelpers
  end
end

But it could be something else on your test setup that's breaking with the controller helpers, in that case, please provide a sample app with quick steps to reproduce the error otherwise we will be spitballing here forever. I'm closing this issue as we might have different problems going around here, so if you got a sample app of the issue you are facing please open a new issue with the app's URL.

@zephiransas
Copy link

@lucasmazza That works well for me. Thx!

@albertnetymk
Copy link

albertnetymk commented Sep 20, 2016

Was bitten by this on upgrading devise from 4.1.1 to 4.2.0. Resolved it by merging rspec config from spec_helper.rb to rspec config in rails_helper.rb, for I don't have non-rails tests anyway.

Because it's specified in https://github.com/plataformatec/devise#controller-tests, "Just be sure that this inclusion is made after the require 'rspec/rails' directive."

@sgoldens
Copy link

@lucasmazza I made a quick sample app as you suggested, exhibiting the undefined method 'setup' for RSpec::ExampleGroups:: errors on running rspec after a quick rake db:create && rake db:migrate --> https://github.com/sgoldens/setup-devise-bug

Hope that helps! Would love to get this solved.

@lucasmazza
Copy link
Contributor

@sgoldens your sample app does not require rspec/rails on spec_helper/rails_helper, so it does not load the integrations between rspec and the lifecycle test callbacks that Devise uses (that come from Active Support). Please re-check your test suite setup to ensure that rspec and rails are integrated properly.

@jessethebuilder
Copy link

This also happens if config.include Devise::Test::ControllerHelpers, type: :controller comes BEFORE `require 'rspec/rails' in your setup.

@jhirbour
Copy link

jhirbour commented Mar 18, 2019

I've had this issue as well and ended up on this page from Google.

For my application there were 2 locations where config.include Devise::Test::ControllerHelpers, type: :controller was being set, 1 spec/support/devise_config.rb and another in spec/rails_helper.rb . Removing it from spec/support fixed the issue and allowed me to upgrade to 4.2 (and later).

It's unclear to me if it's the duplication causing the issue, or the ordering as @jessethebuilder suggested above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

10 participants