mocha icon indicating copy to clipboard operation
mocha copied to clipboard

Sequencing failure messages are unclear

Open dchelimsky opened this issue 13 years ago • 1 comments

Given this example:

require "test/unit"
require "mocha"

class FooTest < Test::Unit::TestCase
  def test_foo
    sequence = sequence(:task_order)
    task_one = mock("task_one")
    task_two = mock("task_two")

    task_one.expects(:execute).in_sequence(sequence)
    task_two.expects(:execute).in_sequence(sequence)

    task_two.execute
    task_one.execute
  end
end

The failure message is unclear:

  1) Failure:
test_foo(FooTest) [example_spec.rb:13]:
unexpected invocation: #<Mock:task_two>.execute()
unsatisfied expectations:
- expected exactly once, not yet invoked: #<Mock:task_one>.execute(any_parameters); in sequence :task_order
- expected exactly once, not yet invoked: #<Mock:task_two>.execute(any_parameters); in sequence :task_order

I'd propose something like this:

  1) Failure:
test_foo(FooTest) [example_spec.rb:13]:
invocation: #<Mock:task_two>.execute() received out of order

dchelimsky avatar Jan 31 '12 11:01 dchelimsky

I think that given there can be many sequences and many objects and methods involved in each, it may be quite hard to come up with a more meaningful error message, but I agree it is desirable. I'll look into it. Thanks for the feedback.

floehopper avatar Feb 01 '12 11:02 floehopper

See also:

  • https://gist.github.com/lukeredpath/1704783
  • https://github.com/rspec/rspec-mocks/blob/main/features/setting_constraints/message_order.feature

floehopper avatar Nov 18 '23 11:11 floehopper