Undefined method 'get'

Hello guys,

I was just starting a rails 3.0.5 application with rspec-rails 2.5.0
and ruby 1.9.2-p180 and when I went to describe my controller I ran
into this undefined method ‘get’ error.

Here’s the spec that is causing the problem (which lives in the folder
spec/controllers)

require ‘spec_helper’

describe ArticlesController, :type => :controller do
describe “GET index” do
get :index
response.should be_successful
end
end

And here’s the error it throws:

spec/controllers/articles_controller_spec.rb:13:in block (2 levels) in <top (required)>': undefined methodget’ for #<Class:
0x00000104799aa0> (NoMethodError)
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/example_group.rb:132:in module_eval' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:insubclass’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/example_group.rb:119:in describe' from /spec/controllers/articles_controller_spec.rb:12:inblock in
<top (required)>’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/example_group.rb:132:in module_eval' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/example_group.rb:132:insubclass’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/example_group.rb:119:in describe' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/extensions/object.rb:6:indescribe’
from /spec/controllers/articles_controller_spec.rb:3:in <top (required)>' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:inload’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/configuration.rb:386:in block in load_spec_files' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/configuration.rb:386:inmap’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/configuration.rb:386:in load_spec_files' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/command_line.rb:18:inrun’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/runner.rb:55:in run_in_process' from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/ rspec/core/runner.rb:46:inrun’
from /Users/DBA/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/
rspec/core/runner.rb:10:in `block in autorun’

What could be causing rspec not to find controller example group
methods?

Best regards,
DBA

Hi,

On Mon, Mar 7, 2011 at 15:30, DBA [email protected]
wrote:

describe “GET index” do
get :index
response.should be_successful
end
end

Not sure what the problem could be. Does ArticlesController inherit
from ActionController::Base (maybe via ApplicationController)? You
shouldn’t need to specify :type => :controller on the top-level
describe like you do. Also, your expectation should be
‘response.should be_success’.

Mike

On Mar 7, 2011, at 1:30 AM, DBA wrote:

describe ArticlesController, :type => :controller do
describe “GET index” do
get :index
response.should be_successful
end
end

The get method is available in examples (the block passed to it or
specify), but here it’s being called in a group (the block passed to
describe or context`). Try this instead:

describe ArticlesController, :type => :controller do
describe “GET index” do
it “returns a 200” do
get :index
response.should be_successful
end
end
end

HTH,
David

Indeed. David C. was kind enough to repair my noob mistake via
twitter. What was happening was exactly what he described in his
reply.

More info at: gist:858446 · GitHub

Thanks,
DBA

Hi,

On Mar 13, 2011 10:11 PM, “David C.” [email protected]
wrote:

The get method is available in examples (the block passed to it or
specify), but here it’s being called in a group (the block passed to
describe or context`).

Yeah, don’t know how I missed that!

Mike