3

我正在使用以下规范在 rspec (rails 3) 之上尝试“应该”:

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,所以据我所知,应该可以正常加载。

有什么建议么?

4

1 回答 1

2

在 RSpecshould中是一个用于触发匹配器的 RSpec 方法——它不是应该的上下文块。为此,您使用 RSpecs 自己的describe.

should "be true" do
  assert true
end

是应该的基于 Test::Unit 的语法,它不应该在 RSpec 示例中工作(我猜?)。只需使用您的第二个示例,它具有相同的效果和正确的语法。

于 2010-09-10T07:13:34.600 回答