Shoulda with TestUnit:使用Shoulda/Subject的条件验证
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shoulda with TestUnit:使用Shoulda/Subject的条件验证相关的知识,希望对你有一定的参考价值。
class Post < ActiveRecord::Base validates_presence_of :title validates_presence_of :publishing_date, :if => :published end class PostTest < ActiveSupport::TestCase context "Post that is NOT going to be published" do should validate_presence_of(:title) should_not validate_presence_of(:publishing_date) end context "Post that is going to be published" do subject do Post.new(:title => 'Valid Title', :published => true) end should validate_presence_of(:publishing_date) end end
以上是关于Shoulda with TestUnit:使用Shoulda/Subject的条件验证的主要内容,如果未能解决你的问题,请参考以下文章
ruby Rails Rspec模型使用rspec-rails,shoulda-matcher,shoulda-callbacks和factory_girl_rails测试骨架和备忘单。差不多
ruby Rails Rspec模型使用rspec-rails,shoulda-matcher,shoulda-callbacks和factory_girl_rails测试骨架和备忘单。差不多
ruby Rails Rspec模型使用rspec-rails,shoulda-matcher,shoulda-callbacks和factory_girl_rails测试骨架和备忘单。差不多
ruby Rails Rspec模型使用rspec-rails,shoulda-matcher,shoulda-callbacks和factory_girl_rails测试骨架和备忘单。差不多