Shoulda with TestUnit:使用Shoulda/Subject的条件验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shoulda with TestUnit:使用Shoulda/Subject的条件验证相关的知识,希望对你有一定的参考价值。

  1. class Post < ActiveRecord::Base
  2. validates_presence_of :title
  3. validates_presence_of :publishing_date, :if => :published
  4. end
  5.  
  6. class PostTest < ActiveSupport::TestCase
  7.  
  8. context "Post that is NOT going to be published" do
  9. should validate_presence_of(:title)
  10. should_not validate_presence_of(:publishing_date)
  11. end
  12.  
  13. context "Post that is going to be published" do
  14. subject do
  15. Post.new(:title => 'Valid Title', :published => true)
  16. end
  17. should validate_presence_of(:publishing_date)
  18. end
  19.  
  20. 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测试骨架和备忘单。差不多

无法使用 shoulda 匹配器获得唯一性验证测试通过

shoulda-callback-matchers after_save 条件问题