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 method `get'' 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:in `subclass'' 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:in `block 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:in `subclass'' 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:in `describe'' 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:in `load'' 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:in `map'' 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:in `run'' 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:in `run'' 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 <diogo.borges.almeida at gmail.com> wrote:> 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 > endNot 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:> 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 > endThe `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 Chelimsky was kind enough to repair my noob mistake via twitter. What was happening was exactly what he described in his reply. More info at: https://gist.github.com/858446 Thanks, DBA
Hi, On Mar 13, 2011 10:11 PM, "David Chelimsky" <dchelimsky at gmail.com> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110314/2b0b718a/attachment.html>