Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method for Class in Rspec

The following RSpec 2 test..

describe "GET new" do
  describe "gets a report form" do
    xhr :get, :new, :post_id => @post
    response.should be_success
  end
end

gives this nice error:

undefined method xhr for #<Class:0xb5c72404> (NoMethodError)

Any idea what is wrong?

like image 545
0x4a6f4672 Avatar asked Aug 23 '11 08:08

0x4a6f4672


1 Answers

It turns out you have to use an it statement in the describe block. Then the error goes away. If you do not use the right amount of describe and it blocks, then RSpec produces all kinds of weird errors. This is the correct code:

describe "GET new" do
  it "gets a report form" do
    xhr :get, :new, :post_id => @post
    response.should be_success
  end
end
like image 139
0x4a6f4672 Avatar answered Sep 18 '22 14:09

0x4a6f4672