【发布时间】:2014-03-01 05:49:06
【问题描述】:
我要测试一个模型,像这样;
class Post < ActiveRecord::Base
validates_presence_of :title
# ...
end
我找到了两种主要的方法来测试验证:
1.使用thinkbot的should gem https://github.com/thoughtbot/shoulda
describe Post do
it { should validate_presence_of(:title) }
end
2.直接测试验证,就像书中的方法
describe Post do
it "must has title" do
post = Post.create
expect(post).not_to be_valid
end
所以我想知道哪种方法更好,为什么。提前致谢。
【问题讨论】:
标签: ruby-on-rails testing activerecord rspec