Sha256: 1fd549ef961d6bbc89acb2b705702110c5b8d9ebd344c9a19532921825f6f400

Contents?: true

Size: 1.13 KB

Versions: 52

Compression:

Stored size: 1.13 KB

Contents

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

describe "Struct#hash" do

  it "returns the same fixnum for structs with the same content" do
    [StructClasses::Ruby.new("1.8.6", "PPC"),
     StructClasses::Car.new("Hugo", "Foo", "1972")].each do |stc|
      stc.hash.should == stc.dup.hash
      stc.hash.should be_kind_of(Fixnum)
    end
  end

  it "returns the same value if structs are #eql?" do
    car = StructClasses::Car.new("Honda", "Accord", "1998")
    similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
    car.should eql(similar_car)
    car.hash.should == similar_car.hash
  end

  ruby_bug "redmine #1852", "1.9.1" do
    it "returns the same hash for recursive structs" do
      car = StructClasses::Car.new("Honda", "Accord", "1998")
      similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
      car[:make] = car
      similar_car[:make] = car
      car.hash.should == similar_car.hash
      # This is because car.eql?(similar_car).
      # Objects that are eql? must return the same hash.
      # See the Struct#eql? specs
    end
  end

end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/struct/hash_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/struct/hash_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/struct/hash_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/struct/hash_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/struct/hash_spec.rb