Let's say I have a service class as such:
class FooService
  def self.execute(foo_id)
    Foo.find(foo_id).tap do |foo|
      foo.update_attribute :status, :working
      do_work(foo)
      foo.update_attribute :status, :done
    end
  end
end
A simple test for this method in Minitest with Mocha:
test 'executing the service' do
  @foo = Foo.first
  FooService.expects(:do_work).with(@foo)
  FooService.execute(@foo.id)
  assert_equal :done, @foo.reload.status
end
What would be the best way to test that the status attribute was set to :working?
I've tried using Foo.any_instance.expects(:update_attribute).with(:status, :working) but since there is no way to call the original implementation in Mocha this has bad side effects.
 
                        
One solution would be to get
do_workto raise an error. That should stop the process before the end of the routine and leavefooin statusworking