Sha256: c198093682eb2482fc0406d2383196db2222d4d754bed3307399244c74bb1fab

Contents?: true

Size: 581 Bytes

Versions: 6

Compression:

Stored size: 581 Bytes

Contents

require File.dirname(__FILE__)+'/../spec_helper'
require 'gorillib/object/try'

class Foo
  def i_am_a_method_hooray param='hooray'
    "i was called! #{param}!"
  end
end

describe Object do
  describe '#try' do
    it 'returns nil if item does not #respond_to? method' do
      Foo.new.try(:i_am_not_a_method).should be_nil
    end
    it 'calls the method (with args) if the item does #respond_to? it' do
      Foo.new.try(:i_am_a_method_hooray).should == "i was called! hooray!"
      Foo.new.try(:i_am_a_method_hooray, 'yay').should == "i was called! yay!"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gorillib-0.1.7 spec/object/try_spec.rb
gorillib-0.1.6 spec/object/try_spec.rb
gorillib-0.1.5 spec/object/try_spec.rb
gorillib-0.1.4 spec/object/try_spec.rb
gorillib-0.1.3 spec/object/try_spec.rb
gorillib-0.1.2 spec/object/try_spec.rb