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

Duck types are sensitive to argument names #71

Open
psyho opened this issue Sep 1, 2015 · 3 comments
Open

Duck types are sensitive to argument names #71

psyho opened this issue Sep 1, 2015 · 3 comments

Comments

@psyho
Copy link
Owner

psyho commented Sep 1, 2015

For example:

class Foo
  def call(env)
  end
end

class Bar
  def call(_)
  end
end

fake(:xxx) { [Foo, Bar]}.respond_to?(:call) == false
@ravicious
Copy link

ravicious commented Nov 14, 2016

Is there any workaround for this issue? I have a bunch of classes and some define foo through delegate and other classes define foo through attr_reader – Bogus seems to have a problem with this as well.

Edit: For now I can "manually" define the delegated methods, though I'm more interested in a Bogus-specific workaround for this problem.

@psyho
Copy link
Owner Author

psyho commented Nov 14, 2016

There is no workaround for this, although the fix would be fairly simple - you can just strip argument names from the parameters list when comparing here: https://github.com/psyho/bogus/blob/master/lib/bogus/fakes/makes_ducks.rb#L33

However, this might not work in your particular case. If I remember correctly, delegate defines a method that accepts an arbitrary number of arguments, so the method signature is actually different.

@ravicious
Copy link

However, this might not work in your particular case. If I remember correctly, delegate defines a method that accepts an arbitrary number of arguments, so the method signature is actually different.

You're right, I didn't know about it, thanks! I think it's time to rethink the usage of the RuboCop Rails/Delegate cop in our project.

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