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

array_including does not support composing matchers #801

Closed
myronmarston opened this issue Oct 20, 2014 · 1 comment
Closed

array_including does not support composing matchers #801

myronmarston opened this issue Oct 20, 2014 · 1 comment
Labels

Comments

@myronmarston
Copy link
Member

As reported in a tweet:

https://twitter.com/fuzzmonkey/status/524271331349921792

Given this spec:

class Foo; end

RSpec.describe "Using `array_including(instance_of(Foo))`" do
  it "passes when the args match" do
    dbl = double
    expect(dbl).to receive(:a_message).with(3, array_including(instance_of(Foo)))
    dbl.a_message(3, [1, Foo.new, 4])
  end
end

It fails:

  1) Using `array_including(instance_of(Foo))` passes when the args match
     Failure/Error: dbl.a_message(3, [1, Foo.new, 4])
       Double received :a_message with unexpected arguments
         expected: (3, array_including(#<RSpec::Mocks::ArgumentMatchers::InstanceOf:0x007f8eaaaa8710>))
              got: (3, [1, #<Foo:0x007f8eaaa50e48>, 4])
     # ./lib/rspec/mocks/error_generator.rb:213:in `__raise'
     # ./lib/rspec/mocks/error_generator.rb:43:in `raise_unexpected_message_args_error'
     # ./lib/rspec/mocks/proxy.rb:193:in `raise_unexpected_message_args_error'
     # ./lib/rspec/mocks/proxy.rb:174:in `message_received'
     # ./lib/rspec/mocks/method_double.rb:73:in `proxy_method_invoked'
     # ./lib/rspec/mocks/method_double.rb:60:in `block (2 levels) in define_proxy_method'
     # ./spec/array_including_example_spec.rb:7:in `block (2 levels) in <top (required)>'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example.rb:166:in `instance_exec'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example.rb:166:in `block in run'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example.rb:344:in `with_around_example_hooks'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example.rb:163:in `run'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example_group.rb:494:in `block in run_examples'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example_group.rb:490:in `map'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example_group.rb:490:in `run_examples'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/example_group.rb:456:in `run'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:112:in `map'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:112:in `block in run_specs'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/reporter.rb:62:in `report'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:108:in `run_specs'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:86:in `run'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:70:in `run'
     # /Users/myron/code/rspec-dev/repos/rspec-core/lib/rspec/core/runner.rb:38:in `invoke'
     # /Users/myron/code/rspec-dev/repos/rspec-core/exe/rspec:4:in `<top (required)>'
     # ./bin/rspec:16:in `load'
     # ./bin/rspec:16:in `<main>'

Finished in 0.00813 seconds (files took 0.13108 seconds to load)
1 example, 1 failure

The problem is that array_including doesn't delegate to RSpec::Support::FuzzyMatcher.values_match? to match individual array elements. This is a bug. Also, the description doesn't look right -- it should use the description of the composed matchers. Actually, looking at argument_matchers.rb, this looks like a problem with the hash matchers, too.

One potential fix is the solution to #513 being discussed there, as the rspec-expectations versions of these matchers already work properly for these cases.

@myronmarston
Copy link
Member Author

Closing in favor of #819.

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

No branches or pull requests

1 participant