Conditional validation testing

210 views
Skip to first unread message

Ricardo Panaggio

unread,
May 31, 2011, 4:26:52 PM5/31/11
to sho...@googlegroups.com
Hello,

It seems there's no "shoulda way" to test conditional validations. Am I missing something?

Ricardo Panaggio

Ryan McGeary

unread,
May 31, 2011, 8:49:51 PM5/31/11
to sho...@googlegroups.com
Ricardo, After specifying the subject explicitly, you can test validations that are based on a particular state of the object.

Test::Unit:

context "An object with validation enforced" do
  subject { Object.new(:enforce_validation => true) }
  should validate_presence_of :title
end

RSpec:

describe "An object with validation enforced" do
  subject { Object.new(:enforce_validation => true) }
  it { should validate_presence_of :title }
end

-Ryan


--
Individuals over processes. Interactions over tools.
 
Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training
 
The Shoulda group:
http://groups.google.com/group/shoulda
 
To post to this group, send email to
sho...@googlegroups.com
 
To unsubscribe from this group, send email to
shoulda+u...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages