Sha256: 46bbcf5f16168f1857e4cdf4cc6f6ef296303059801a0b7a08128ae6a628fb44

Contents?: true

Size: 1.03 KB

Versions: 62

Compression:

Stored size: 1.03 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.8.8" do
  describe "Hash.try_convert" do
    it "returns the argument if passed a Hash" do
      h = {:foo => :glark}
      Hash.try_convert(h).should == h
    end

    it "returns nil if the argument can't be coerced into a Hash" do
      Hash.try_convert(Object.new).should be_nil
    end

    it "does not rescue exceptions raised by #to_hash" do
      obj = mock("to_hash raises")
      obj.should_receive(:to_hash).and_raise(RuntimeError)
      lambda { Hash.try_convert obj }.should raise_error(RuntimeError)
    end

    it "coerces the argument with #to_hash" do
      obj = mock('to_hash')
      obj.should_receive(:to_hash).and_return({:foo => :bar})
      Hash.try_convert(obj).should == {:foo => :bar}
    end

    it "raises a TypeError if #to_hash does not return a Hash" do
      obj = mock("to_hash invalid")
      obj.should_receive(:to_hash).and_return(:invalid_to_hash)
      lambda { Hash.try_convert obj }.should raise_error(TypeError)
    end
  end
end

Version data entries

62 entries across 62 versions & 3 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/hash/try_convert_spec.rb
jactive_support-2.1.2 spec/java_ext/map/try_convert_spec.rb
jactive_support-3.0.0 spec/java_ext/map/try_convert_spec.rb
jactive_support-3.0.0.pre2 spec/java_ext/map/try_convert_spec.rb