On Wed, Jul 9, 2014 at 2:15 PM, Sam Phippen <[email protected]>
wrote:

> Duck type means that it will respond to that method, instance of will
> check the class of the object.
>

Ah! Got it.

describe '#duck_type' do
  let(:dbl) { double() }
  before { allow(dbl).to receive(:random_method).with(duck_type(:size)) }

  context "when the argument is String" do
    it "should match duck type with one method" do
      dbl.random_method([])
    end
  end

  context "when the argument is Array" do
    it "should match duck type with one method" do
      dbl.random_method("")
    end
  end
end

Result :-

arup$ rspec test_spec.rb
..

Finished in 0.00094 seconds
2 examples, 0 failures

Good. But what's the use of to check of if any argument to respond to a
specific method or not. Is it indirect check to see if the argument object
belongs to a specific class or not ? I mean, I want my #foo method always
accept arguments as String object only, not any other. Is this the check
that duck_type helps us to perform ? Or Am I completely wrong, there is
some thing more interesting concept behind it ?


Regards,
A.R

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CAKxHnE0S6bJ7t11w-xCJLkX%3DosYGgpgdD1FF%2BL4MpfbyNsS%3D2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to