Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequencing failure messages are unclear #60

Closed
dchelimsky opened this issue Jan 31, 2012 · 3 comments · Fixed by #633
Closed

Sequencing failure messages are unclear #60

dchelimsky opened this issue Jan 31, 2012 · 3 comments · Fixed by #633

Comments

@dchelimsky
Copy link

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
@floehopper
Copy link
Member

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 added a commit that referenced this issue Nov 18, 2023
TODO:
* [ ] Add tests
* [ ] Maybe improve method names?
* [ ] Maybe extract more methods?
* [ ] Avoid very long lines

Closes #60
floehopper added a commit that referenced this issue Nov 18, 2023
I think there's more we could do in this area, but this implements
@dchelimsky's suggestion which is definitely an improvement.

If an invocation was unexpected because, although there is an
expectation that expectation does not match due to an ordering
constraint, then append "invoked out of order" to the failure message.

e.g.

    unexpected invocation: #<Mock:mock>.foo() invoked out of order

Closes #60 (only 11 years late!😅)
floehopper added a commit that referenced this issue Nov 18, 2023
I think there's more we could do in this area, but this implements
@dchelimsky's suggestion which is definitely an improvement.

If an invocation was unexpected because, although there is an
expectation that expectation does not match due to an ordering
constraint, then append "invoked out of order" to the failure message.

e.g.

    unexpected invocation: #<Mock:mock>.foo() invoked out of order

Closes #60 (only 11 years late!😅)
@floehopper
Copy link
Member

Released in v2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants