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

NoMethodError: undefined method `map' #443

Closed
floehopper opened this issue Dec 16, 2019 · 3 comments
Closed

NoMethodError: undefined method `map' #443

floehopper opened this issue Dec 16, 2019 · 3 comments
Assignees

Comments

@floehopper
Copy link
Member

I noticed this PR in which they tried to use v1.10.2 to fix the issue in #436, but ran into another problem.

NoMethodError: undefined method `map' for #<String:0x000055f157c8de00>
    lib/mocha/parameters_matcher.rb:31:in `matchers'
    lib/mocha/parameters_matcher.rb:24:in `mocha_inspect'
    lib/mocha/invocation.rb:29:in `block in call'
    lib/mocha/multiple_yields.rb:11:in `block in each'
    lib/mocha/multiple_yields.rb:10:in `each'
    lib/mocha/multiple_yields.rb:10:in `each'
    lib/mocha/invocation.rb:23:in `call'
    lib/mocha/expectation.rb:571:in `invoke'
    lib/mocha/mock.rb:315:in `method_missing'
@floehopper floehopper self-assigned this Dec 16, 2019
@floehopper
Copy link
Member Author

I'm currently investigating.

floehopper added a commit 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
Member Author

See possible fix in #444

@floehopper
Copy link
Member Author

Fixed in #444.

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

No branches or pull requests

1 participant