3

私は次の仕様でrspec(rails 3)の上に「shoulda」を試しています:

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

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を使用しているので、私の知る限り、shouldaは問題なくロードされます。

助言がありますか?

4

1 に答える 1

2

In RSpecshouldは、Matcher をトリガーするために使用される RSpec メソッドです。これは Shouldas コンテキスト ブロックではありません。そのためには、RSpecs own を使用しますdescribe

should "be true" do
  assert true
end

RSpecの例では動作しないはずのShouldaのTest::Unitベースの構文です(私は推測しますか?)。同じ効果と正しい構文を持つ2番目の例を使用してください。

于 2010-09-10T07:13:34.600 に答える