I have a before_validation :do_something, :on => :create
in one of my models.
I want to test that this happens, and doesn't happen on :save
.
Is there a succinct way to test this (using Rails 3, Mocha and Shoulda), without doing something like:
context 'A new User' do
# Setup, name test etc
@user.expects(:do_something)
@user.valid?
end
context 'An existing User' do
# Setup, name test etc
@user.expects(:do_something).never
@user.valid?
end
Can't find anything in the shoulda API, and this feels rather un-DRY...
Any ideas? Thanks :)