Sha256: 4fca3d94822268984d12c4052842a2b54734a79c696333c96a92dfb1cd92e074

Contents?: true

Size: 1.02 KB

Versions: 83

Compression:

Stored size: 1.02 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "String.try_convert" do
  ruby_version_is "1.9" do
    it "returns self for strings" do
      x = "abc"
      String.try_convert(x).should equal(x)
    end
    
    it "converts using :to_str" do
      str = "hello"
      obj = mock('stringlike')
      obj.should_receive(:to_str).and_return(str)
      String.try_convert(obj).should equal(str)
    end
    
    it "returns nil when there is no :to_ary" do
      String.try_convert(-1).should be_nil
    end
    
    it "should not rescue errors" do
      lambda{
        String.try_convert(StringSpecs::StringNotReallyConvertable.new)
      }.should raise_error
    end
    
    it "checks the result of the conversion" do
      obj = mock('crazy to_str')
      obj.should_receive(:to_str).and_return(:confused)
      lambda{
        String.try_convert(obj)
      }.should raise_error(TypeError)
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/string/try_convert_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/string/try_convert_spec.rb