Fernando P. wrote:
In a Rails app, I often find myself having to write
expects(:whatever).at_least_once.returns(“some_value”), so it clutters
my test and I simply ditch expects() in favor of stubs() which won’t
yell at me because some method was called more than once.
What do you usually use?
It varies from test to test depending on whether a failure actually
matters from the point of view of that test. If I am checking, in the
current test, that a method actually gets called, such that it’s a
failure if it doesn’t, then I use #expects. If I just need to fake a
response to get down a certain code path to test something later, I use
#stubs. Errors masked by using #stubs should get caught by other tests
where those calls are mocked with #expects.
I find I don’t use #at_least_once very much. Either the method gets
called once, or it gets called in a sequence that I control and should
be checking for explicitly with #in_sequence.