Sha256: 32a8f6374431c635d6c83c3c84a04c0e67b2f6b80b7385fcdfa7a0b3d3b37d05

Contents?: true

Size: 1.88 KB

Versions: 83

Compression:

Stored size: 1.88 KB

Contents

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

describe "Hash#initialize" do
  it "is private" do
    hash_class.should have_private_instance_method("initialize")
  end

  it "can be used to reset default_proc" do
    h = new_hash("foo" => 1, "bar" => 2)
    h.default_proc.should == nil
    h.instance_eval { initialize { |h, k| k * 2 } }
    h.default_proc.should_not == nil
    h["a"].should == "aa"
  end

  it "should get passed whatever args were passed to Hash#new" do
    NewHash.new(:one, :two)[0].should == :one
    NewHash.new(:one, :two)[1].should == :two
  end

  ruby_version_is ""..."1.9" do
    it "raises a TypeError if called on a frozen instance" do
      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize() }}
      block.should raise_error(TypeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(nil) }  }
      block.should raise_error(TypeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(5) }    }
      block.should raise_error(TypeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } }
      block.should raise_error(TypeError)
    end
  end

  ruby_version_is "1.9" do
    it "raises a RuntimeError if called on a frozen instance" do
      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize() }}
      block.should raise_error(RuntimeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(nil) }  }
      block.should raise_error(RuntimeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(5) }    }
      block.should raise_error(RuntimeError)

      block = lambda { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } }
      block.should raise_error(RuntimeError)
    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/hash/initialize_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/hash/initialize_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/hash/initialize_spec.rb