2010-09-09 57 views
2

我用下面的規範試行「早該」上的RSpec的頂部(軌道3):早該應該「有效」做失敗,「‘handle_matcher’:未定義的方法‘能匹配?’」

require 'spec_helper' 
describe Article do 
    should "be true" do 
    assert true 
    end 
end 

,也未能與

/Users/jeppe/.rvm/gems/ruby-1.8.7-p302/gems/rspec-expectations-2.0.0.beta.20/lib/rspec/expectations/handler.rb:11:in `handle_matcher': undefined method `matches?' for "be true":String (NoMethodError) 

現在,當我做到既

require 'spec_helper' 
describe Article do 
    it "should be true" do 
    assert true 
    end 
end 

0123我的測試將運行得很好
require 'spec_helper' 
describe Article do 
    it { should belong_to :issue } 
    it { should have_and_belong_to_many :pages } 
    it { should have_many :tasks } 
end 

最後使用的地方Shoulda :: ActiveRecord :: Matchers,所以據我所知應該是加載好的。

有什麼建議嗎?

回答

1

在RSpec should是用來觸發匹配器的RSpec方法 - 它不是Shouldas上下文塊。爲此,您使用RSpec自己的describe

should "be true" do 
    assert true 
end 

是Shoulda的Test :: Unit基本語法,它不應該在RSpec示例中工作(我猜?)。只需使用第二個示例,它具有相同的效果和正確的語法。

+0

好吧,所以我'只是'與Test :: Unit vs Rspec語法混淆 - 感謝指出:-) – 2010-09-10 08:33:03

相關問題