3

I want to do something like this:

@vehicle.should_receive(:park)
@vehicle.stub!(:park)
Vehicle.any_instance.stub(:park)
# etc.

so that I can validate interaction or use a state_machine in other specs without the overhead of actually changing states...

How could I accomplish this?

4

1 回答 1

0

使用您所写的上述任何方法。请注意,我认为在 Rspec 的某些版本中,直接存根或使用#should_receive 将替换所述存根方法的主体。如果您稍后测试副作用,它们将不存在。

通常我会解决这个问题。

@vehicle.should_receive(:park) do
   @vehicle.state = :parked
end

expect do
  @person.exit_vehicle
end.should change(@vehicle.state).from(:driving).to(:parked)
于 2012-08-16T22:41:36.543 回答