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

Exception when using custom rspec matcher #140

Open
jk779 opened this issue Oct 13, 2021 · 2 comments
Open

Exception when using custom rspec matcher #140

jk779 opened this issue Oct 13, 2021 · 2 comments
Labels

Comments

@jk779
Copy link

jk779 commented Oct 13, 2021

Hi! This is a great gem! 🎊

I'm experiencing a problem tho. When using a custom rspec matcher like this:

RSpec::Matchers.define :include_or_eq do |expected|
  match do |actual|
    if actual.is_a?(Hash)
      return actual[:any].include? expected if actual.key? :any
      return actual[:all].sort == expected.sort if actual.key? :all

      raise 'Neither :all nor :any key defined :('
    else
      actual == expected
    end
  end
end

and expecting with it like this:

allow(Client).to receive(:check).with(
  anything,
  include_or_eq(subject),
  action,
  { return_user: return_user }
).and_return ret_value

i'll get the following error when the matcher doesn't match:

ArgumentError:
       wrong number of arguments (0 for 1) for SuperDiff::ObjectInspection::InspectionTreeBuilders::Main initializer
     Shared Example Group: "update endpoints" called from ./spec/shared_examples/a_custom_endpoint.rb:8
     Shared Example Group: "a custom endpoint" called from ./spec/grape/api/v1/admin/badwords_spec.rb:31
     # /Users/michael/.asdf/installs/ruby/2.7.0/lib/ruby/gems/2.7.0/gems/attr_extras-6.2.4/lib/attr_extras/attr_initialize.rb:53:in `validate_arity'

(full stacktrace here)

When using the same code with a non-custom matcher, e.g.:

allow(Client).to receive(:check).with(
  anything,
  a_string_including(subject),
  action,
  { return_user: return_user }
).and_return ret_value

everything works great and an expected super_diff is displayed.

Am I missing something here?

@mcmire
Copy link
Collaborator

mcmire commented Oct 13, 2021

This looks like a bug to me! Is it possible for you to obtain a larger backtrace by chance? I can see an indicator to what the issue might be but not where it's originating from inside the gem.

@jk779
Copy link
Author

jk779 commented Apr 12, 2022

Hi @mcmire, thanks fot your reply and sorry for the long silence from my part :(
I'm currently running into this issue again in the same project.

In another project where i'm using your gem and the gem the custom matcher is coming from as well, the issue does not occur. So i suspect there is something really strange going on in my application that is causing this (maybe another gem thats interfering?)

I'd love to share more backtraces, i've already dug deep into it with ruby-debug-ide, but it's not that easy to understand whats going on when SuperDiff.inspect_object is recusively called and interacting with attr_extras leading into this exception eventually.
Can you point me which kind of trace/debug info you'd need?
(I've already attached a "full" backtrace in the original post, which i guess you have seen?)

Since it's not a public project this issue arises in I'm sadly not able to share the whole source code here :(

Because it's probably a project/app specific problem, I strongly think the problem is on my part, but i would greatly appreciate your help anyways if you've a minute to spare :)! Otherwise I think this issue can be closed. 🙈

Thanks!

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

2 participants