Rspec中Class的未定义方法

时间:2011-08-23 08:28:13

标签: ruby-on-rails rspec 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

给出了这个错误:

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

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:16)

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

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