You would do something like this:
describe MyModel
context "when mobile phone is present" do
subject { MyModel.new(:mobile_phone => true) }
it { should validate_presence_of :mobile_carrier }
end
context "when mobile phone is not present" do
subject { MyModel.new(:mobile_phone => false) }
it { should_not validate_presence_of :mobile_carrier }
end
end
I haven't tried this and I don't remember if the should_not works on
the validates_* properly.
I've always been partial to the way Datamapper handles things with
contextual validations.
You can get more sophisticated if you use the let() feature in Rspec.
Hope this helps.
Ho-Sheng Hsiao