bogus
bogus copied to clipboard
Duck types are sensitive to argument names
For example:
class Foo
def call(env)
end
end
class Bar
def call(_)
end
end
fake(:xxx) { [Foo, Bar]}.respond_to?(:call) == false
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.
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.
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.