I am using Mocha::Hooks#mocha_verify
in the after_scenario
spinach hook which works fine for some cases. However, there are many times when I want to verify an expectation after a value has been updated on a piece of data. For example,
class MyModel < ActiveRecord::Base
after_commit :checked, if: -> (record) { record.previous_changes.key?('checked_at') && record.checked_at? }
def checked
Bus.publish_at(checked_at + 1.day, 'checked', id: id)
end
end
Right now I'm having to set the expectation before the "act" part of the test runs so I have to do something like:
Bus.expects(:publish_at).with(
instance_of(ActiveSupport::TimeWithZone),
'checked',
has_entries(id: @my_model.id)
).once
The test data in @my_model
still has nil
checked_at
because the "act" part of the test hasn't run yet, but I would like to verify that the first parameter is correct. I don't see a way to do this but it would be nice to be able to verify an invocation after the "act" part of the test like:
Bus.verify(:publish_at).with(
@my_model.checked_at + 1.day,
'checked',
has_entries(id: @my_model.id)
).once