Sha256: 86615a0e47f18c5cf30995c7dc9467be2da2598202915742d728f7254c3337f3

Contents?: true

Size: 1.24 KB

Versions: 83

Compression:

Stored size: 1.24 KB

Contents

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

describe "Hash#keys" do

  ruby_version_is ""..."1.9" do
    it "returns an array populated with keys" do
      new_hash.keys.should == []
      new_hash.keys.class.should == Array
      new_hash(5).keys.should == []
      new_hash { 5 }.keys.should == []
      new_hash(1 => 2, 2 => 4, 4 => 8).keys.sort.should == [1, 2, 4]
      new_hash(1 => 2, 2 => 4, 4 => 8).keys.should be_kind_of(Array)
      new_hash(nil => nil).keys.should == [nil]
    end
  end

  ruby_version_is "1.9" do
    it "returns an array with the keys in the order they were inserted" do
      new_hash.keys.should == []
      new_hash.keys.class.should == Array
      new_hash(5).keys.should == []
      new_hash { 5 }.keys.should == []
      new_hash(1 => 2, 4 => 8, 2 => 4).keys.should == [1, 4, 2]
      new_hash(1 => 2, 2 => 4, 4 => 8).keys.should be_kind_of(Array)
      new_hash(nil => nil).keys.should == [nil]
    end
  end


  it "it uses the same order as #values" do
    h = new_hash(1 => "1", 2 => "2", 3 => "3", 4 => "4")

    h.size.times do |i|
      h[h.keys[i]].should == h.values[i]
    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/keys_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/hash/keys_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/hash/keys_spec.rb