"expects" in a mock block doesn't return an expectation, if the parameter is a hash
-
James Mead
- Assigned user set to James Mead
-
James Mead
Sorry - I only just saw this - I didn't have Lighthouse notifications set up correctly. I'm going to have a look at it now.
-
James Mead
- Tag set to bug-report
- State changed from new to open
The second form was never intended to work, because with the Hash argument version you are potentially defining expectations for multiple methods. So it's not obvious to which expectation the at_least_once clause would apply :-
mock('Something') do expects(:method_1 => 1, :method_2 => 2).at_least_once endHowever, I do think the error message should be clearer.
I suppose it would be possible for the at_least_once to apply to all expectations, but I need to think about this a bit more.
Cheers, James.
-
tomm
-1 on allowing at_least_once to apply to >1 expectation. The point of expectation IMO is clarity even to the level of non-developers, and I think the ambiguity will cause confusion.
-
James Mead
I think one way to improve this is for Mock#expects to return an instance of an ExpectationList when it is passed a Hash (instead of returning the Hash which is what it currently does). This seems roughly equivalent to returning an instance of an Expectation when it is passed a single method name (which is what it currently does).
Having made this change it would then be possible to add methods like Expectation#at_least_once to ExpectationList and have them either report a sensible error message or apply to all expectations in the list.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.