Closed aaronchi closed 10 years ago
This is already supported, but got left out in the readme, thanks for letting me know!
Basically, you just use if
and unless
as chained methods, like so:
it { should callback(:assign_something).before(:create).if(:this_is_true) }
Ok, so I have a model MyModel
with an attribute my_attr
and a callback:
after_update :do_whatever, if: :my_attr
How do I test that? This doesn't work:
should callback(:do_whatever).after(:update).if(self.subject.my_attr) #Test::Unit
#result of running this test
=> ... class:MyModelTest>': undefined method `my_attr' for nil:NilClass (NoMethodError)
Should matchers don't currently take into account if/unless conditions on callbacks. Is there any way to include conditions in the tests or do these have to be tested separately?