应该“有效” do 失败,并显示““handle_matcher”:未定义的方法“匹配?”
我正在使用以下规范在 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,所以据我所知应该加载好了。
有什么建议吗?
I'm trying out 'shoulda' on top of rspec (rails 3) with the following spec:
require 'spec_helper'
describe Article do
should "be true" do
assert true
end
end
and it fails with
/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)
Now my tests will run just fine when I do both
require 'spec_helper'
describe Article do
it "should be true" do
assert true
end
end
and
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
where the last uses Shoulda::ActiveRecord::Matchers, so to my knowledge shoulda is loaded allright.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 RSpec 中
should
是一个用于触发匹配器的 RSpec 方法 - 它不是 Shouldas 上下文块。为此,您可以使用 RSpecs 自己的describe
。是 Shoulda 的 Test::Unit 基于语法,它不应该在 RSpec 示例中工作(我猜?)。只需使用您的第二个示例,它具有相同的效果和正确的语法。
In RSpec
should
is an RSpec method used to trigger a matcher - it is not Shouldas context block. For that, you use RSpecs owndescribe
.is Shoulda's Test::Unit based syntax, which shouldn't work in RSpec examples (I guess?). Just use your second example, which has the same effect and the right syntax.