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

Mocha-related test failures #121

Open
apiology opened this issue Dec 7, 2019 · 7 comments
Open

Mocha-related test failures #121

apiology opened this issue Dec 7, 2019 · 7 comments

Comments

@apiology
Copy link
Owner

apiology commented Dec 7, 2019

With Mocha 1.10.0 and 1.10.1 (upgraded from 1.9.0), I get the following errors on the existing tests:

-*- mode: compilation; default-directory: "~/src/quality/" -*-
Compilation started at Sat Dec  7 09:28:04

cd /Users/broz/src/quality/ && make
bundle exec rake localtest
2019-12-07 09:28:11 -0500
/Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/charlock_holmes-0.7.7/lib/charlock_holmes/encoding_detector.rb:66: warning: instance variable encoding_list not initialized
Mocha deprecation warning at /Users/broz/src/quality/test/unit/test_helper.rb:16:in `require': Require 'mocha/test_unit', 'mocha/minitest' or 'mocha/api' instead of 'mocha/setup'.
Run options: --seed 31019

# Running:

..............cane not installed
EE....Processing file1
Processing file2
...........

Finished in 0.120743s, 256.7437 runs/s, 1548.7440 assertions/s.

  1) Error:
TestTask#test_quality_task_some_not_installed:
LocalJumpError: no block given (yield)
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `block in invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:22:in `block in call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:11:in `block in each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:20:in `call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/mock.rb:315:in `method_missing'
    /Users/broz/src/quality/lib/quality/runner.rb:109:in `ratchet_quality_cmd'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/2.6.0/forwardable.rb:230:in `ratchet_quality_cmd'
    /Users/broz/src/quality/lib/quality/tools/shellcheck.rb:12:in `quality_shellcheck'
    /Users/broz/src/quality/lib/quality/runner.rb:49:in `call'
    /Users/broz/src/quality/lib/quality/runner.rb:49:in `run_quality_with_tool'
    /Users/broz/src/quality/lib/quality/runner.rb:39:in `block in run_quality'
    /Users/broz/src/quality/lib/quality/runner.rb:38:in `each'
    /Users/broz/src/quality/lib/quality/runner.rb:38:in `run_quality'
    /Users/broz/src/quality/lib/quality/rake/task.rb:85:in `block in define'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `block in invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:22:in `block in call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/single_yield.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:20:in `call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/mock.rb:315:in `method_missing'
    /Users/broz/src/quality/lib/quality/rake/task.rb:85:in `define'
    /Users/broz/src/quality/lib/quality/rake/task.rb:65:in `initialize'
    /Users/broz/src/quality/test/unit/base_test_task.rb:17:in `new'
    /Users/broz/src/quality/test/unit/base_test_task.rb:17:in `get_test_object'
    /Users/broz/src/quality/test/unit/test_task.rb:20:in `test_quality_task_some_not_installed'

  2) Error:
TestTask#test_quality_task_some_suppressed:
LocalJumpError: no block given (yield)
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `block in invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:22:in `block in call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:11:in `block in each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/multiple_yields.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:20:in `call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/mock.rb:315:in `method_missing'
    /Users/broz/src/quality/lib/quality/runner.rb:109:in `ratchet_quality_cmd'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/2.6.0/forwardable.rb:230:in `ratchet_quality_cmd'
    /Users/broz/src/quality/lib/quality/tools/shellcheck.rb:12:in `quality_shellcheck'
    /Users/broz/src/quality/lib/quality/runner.rb:49:in `call'
    /Users/broz/src/quality/lib/quality/runner.rb:49:in `run_quality_with_tool'
    /Users/broz/src/quality/lib/quality/runner.rb:39:in `block in run_quality'
    /Users/broz/src/quality/lib/quality/runner.rb:38:in `each'
    /Users/broz/src/quality/lib/quality/runner.rb:38:in `run_quality'
    /Users/broz/src/quality/lib/quality/rake/task.rb:85:in `block in define'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `block in invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:22:in `block in call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/single_yield.rb:10:in `each'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/invocation.rb:20:in `call'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/expectation.rb:571:in `invoke'
    /Users/broz/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mocha-1.10.1/lib/mocha/mock.rb:315:in `method_missing'
    /Users/broz/src/quality/lib/quality/rake/task.rb:85:in `define'
    /Users/broz/src/quality/lib/quality/rake/task.rb:65:in `initialize'
    /Users/broz/src/quality/test/unit/base_test_task.rb:17:in `new'
    /Users/broz/src/quality/test/unit/base_test_task.rb:17:in `get_test_object'
    /Users/broz/src/quality/test/unit/test_task.rb:10:in `test_quality_task_some_suppressed'

31 runs, 187 assertions, 0 failures, 2 errors, 0 skips
Coverage report generated for Unit Tests to /Users/broz/src/quality/coverage. 1136 / 1164 LOC (97.59%) covered.
[Coveralls] Outside the Travis environment, not sending data.
SimpleCov failed with exit 1rake aborted!
Command failed with status (1)
/Users/broz/.rbenv/versions/2.6.5/bin/bundle:23:in `load'
/Users/broz/.rbenv/versions/2.6.5/bin/bundle:23:in `<main>'
Tasks: TOP => localtest => test
(See full trace by running task with --trace)
make: *** [localtest] Error 1

Compilation exited abnormally with code 2 at Sat Dec  7 09:28:22

@apiology
Copy link
Owner Author

This appears to be related to freerange/mocha#436

@apiology
Copy link
Owner Author

Worked around in ec9b4ce

Not sure how long term of a fix that's going to be; there's still a DeprecationWarning.

@apiology
Copy link
Owner Author

Well, I guess not really - I just got another error when I tried the workaround - see the commit comment in ea899c6

@floehopper
Copy link

Well, I guess not really - I just got another error when I tried the workaround - see the commit comment in ea899c6

@apiology Sorry to hear this. I've opened a new issue and am investigating.

floehopper added a commit to freerange/mocha that referenced this issue Dec 16, 2019
This was highlighted when investigating this issue [1]. It turned out
that this project was calling Expectation#multiple_yields with non-Array
arguments, mostly/all Strings. See #443 for details.

While the documentation said that each argument should be an Array, it
turned out that in most cases the functionality still worked with
non-Array arguments, but I suspect this was by accident rather than
design. One exception to this was if an argument was a Hash, then it
ended up being passed to the block as an Array of two-element Arrays.

This code [2] which is used to optionally displays invocations was
assuming that `yield_args` was always an Array, but this was not true.
Similarly this code [3] which is used to display a deprecation warning
was also assuming that `yield_args` was always an Array. And it was the
latter which was causing the NoMethodError [4] in the apiology/quality
project.

I've hopefully fixed the underlying problem by wrapping any non-Array
argument in an Array. Note that using Kernel#Array was not an option,
because this didn't give the correct behaviour for Hash arguments.

There is an argument to say that this was undocumented behaviour, but I
think that seems unnecessarily strict in this case.

[1]: apiology/quality#121
[2]: https://github.com/freerange/mocha/blob/1070fc02015a8ea36ad50782f80b557813595c02/lib/mocha/invocation.rb#L24
[3]: https://github.com/freerange/mocha/blob/1070fc02015a8ea36ad50782f80b557813595c02/lib/mocha/invocation.rb#L29
[4]: https://circleci.com/gh/apiology/quality/351
@floehopper
Copy link

@apiology:

It turns out that you were relying on some undocumented behaviour of Expectation#multiple_yields which was assuming all its arguments were Arrays. Unfortunately some recently introduced code in Mocha assumed that this was always the case and raised a NoMethodError when it was not.

FWIW I believe you could fix the problem by changing this line from:

quality_checker.expects(:execute).multiple_yields(*lines)

to:

quality_checker.expects(:execute).multiple_yields(*lines.map { |line| [line] })

However, since the undocumented behaviour of Expectation#multiple_yields seems reasonable, I've just opened a pull request to implement it & document it properly. So you could wait until that is released instead.

I have verified that this PR ☝️ does indeed fix the build on your branch. Hopefully when this other pull request gets merged you'll have a solution which avoids the deprecation warnings too.

Let me know if you have any questions.

@floehopper
Copy link

There's now a new release of mocha (v1.11.0) which contains both freerange/mocha#441 & freerange/mocha#444.

@floehopper
Copy link

I've opened #125 to demonstrate how you might solve this problem. Let me know if you have any questions.

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

No branches or pull requests

2 participants