1

It should be straight forward, but it doesn't work for me.

I'm stubbing a function call, and I want to make sure it is called once, so I did:

MyClass.stubs(:record).returns(true).expect(:record).once
MyClass.run

but I keep getting:

expected exactly once, not yet invoked: allowed any number of times, invoked once: MyClass.record(any_parameters).record(any_parameters)

What am I doing wrong?

Vega
  • 27,856
  • 27
  • 95
  • 103
Yossale
  • 14,165
  • 22
  • 82
  • 109

1 Answers1

1

Are you trying to set expectations for 2 separate invocations on record?

stubs is just a syntactic sugar for expects, specifying that you expect an invocation zero or more times.

You could probably rewrite your example as such:

MyClass.expects(:record).returns(true)

Keep in mind that expects is by default implying the once part although you could add it if you think that it adds to your code's clarity.

Kostas Rousis
  • 5,918
  • 1
  • 33
  • 38