【发布时间】:2012-09-14 14:49:44
【问题描述】:
我是一个 RSpec 新手,但我真的很喜欢编写测试是多么容易,并且随着我学习 RSpec 的新功能,我会不断地重构它们以使其更简洁。所以,最初,我有以下内容:
describe Account do
context "when new" do
let(:account) { Account.new }
subject { account }
it "should have account attributes" do
subject.account_attributes.should_not be_nil
end
end
end
然后我了解了its方法,所以我尝试将其重写为:
describe Account do
context "when new" do
let(:account) { Account.new }
subject { account }
its(:account_attributes, "should not be nil") do
should_not be_nil
end
end
end
由于its 不接受 2 个参数而失败,但删除消息工作正常。问题是,如果测试失败,失败示例部分下的消息只会显示
rspec ./spec/models/account_spec.rb:23 # Account when new account_attributes
这并不过分帮助。
那么,有没有办法将消息传递给its,或者更好的是,让它自动输出一条正常的消息?
【问题讨论】:
-
附带问题,因为它伴随着这个问题:测试 Account has_many AccountAttributes 的最佳 RSpec 方法是什么?
标签: ruby-on-rails testing rspec