Rspec中Class的未定义方法

0x4*_*672 8 rspec ruby-on-rails rspec2

以下RSpec 2测试..

describe "GET new" do
  describe "gets a report form" do
    xhr :get, :new, :post_id => @post
    response.should be_success
  end
end
Run Code Online (Sandbox Code Playgroud)

给出了这个错误:

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

知道什么是错的吗?

0x4*_*672 16

事实证明你必须itdescribe块中使用一个语句.然后错误就消失了.如果你没有使用正确数量的describeit块,那么RSpec会产生各种奇怪的错误.这是正确的代码:

describe "GET new" do
  it "gets a report form" do
    xhr :get, :new, :post_id => @post
    response.should be_success
  end
end
Run Code Online (Sandbox Code Playgroud)