Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

undefined method `controller' for RSpec::ExampleGroups #1540

Closed
ankit8898 opened this issue May 20, 2014 · 3 comments
Closed

undefined method `controller' for RSpec::ExampleGroups #1540

ankit8898 opened this issue May 20, 2014 · 3 comments

Comments

@ankit8898
Copy link

Updated from rspec-rails (3.0.0.beta2) to rspec-rails (3.0.0.rc1)

spec

require 'spec_helper'
describe ApplicationController do
  controller do
    def index
      render :text => 'Ok'
    end

    def show
      raise TypeError, 'Any fake value!'
    end
  end

  it "redirects to new_sessions_path" do
    get :index
    expect(response).to redirect_to(new_session_path)
  end
end

Error

spec/controllers/application_controller_spec.rb:5:in `block (2 levels) in <top (required)>': undefined method `controller' for #<Class:0x007fed8fe69180> (NoMethodError)
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `module_exec'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `subclass'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:227:in `block in define_example_group_method'
    from /Users/ankitgupta/Documents/projects/work/my-development/spec/controllers/application_controller_spec.rb:4:in `block in <top (required)>'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `module_exec'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:331:in `subclass'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/example_group.rb:227:in `block in define_example_group_method'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:41:in `block in expose_example_group_alias'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/dsl.rb:79:in `block (2 levels) in expose_example_group_alias_globally'
    from /Users/ankitgupta/Documents/projects/work/my-development/spec/controllers/application_controller_spec.rb:3:in `<top (required)>'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `block in load_spec_files'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `each'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/configuration.rb:1051:in `load_spec_files'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:97:in `setup'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:85:in `run'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:70:in `run'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.0.rc1/exe/rspec:4:in `<top (required)>'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `load'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `<main>'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    from /Users/ankitgupta/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
@myronmarston
Copy link
Member

rspec-rails 2.x had some very implicit ("magical", to some) behavior where it would infer the spec type based on the file location. In RSpec 3 (starting with RC1) you need to opt-in if you want this, or set the spec type yourself:

describe ApplicationController, :type => :controller do
end

# or

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

See rspec/rspec-rails#970 for more info.

For folks doing the 2.14 -> 2.99 -> 3.0 upgrade path, there are clear deprecation warnings about this, but unfortunately, that's not triggered for 3.0 beta2 -> 3.0 RC1. Sorry about that!

@ankit8898
Copy link
Author

@myronmarston Thanks much! 👍

@AWaselnuk
Copy link

@myronmarston exactly what was wrong. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants