【问题标题】:shoulda should "be valid" do fails with "'handle_matcher': undefined method 'matches?'"应该“有效”失败并出现“'handle_matcher': undefined method 'matches?'”
【发布时间】:2010-09-09 14:17:06
【问题描述】:

我正在使用以下规范在 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 的地方,所以据我所知应该可以正常加载。

有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 rspec shoulda


    【解决方案1】:

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

    should "be true" do
      assert true
    end
    

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

    【讨论】:

    • 好的,所以我“只是”对 Test::Unit vs Rspec 语法感到困惑 - 感谢您指出这一点:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-19
    • 2021-10-11
    相关资源
    最近更新 更多