Sha256: 515f57b2ca3e4048d11c13d98463648f2e8f9a431daf388714b1ca3c2f9ef1e9

Contents?: true

Size: 738 Bytes

Versions: 31

Compression:

Stored size: 738 Bytes

Contents

describe "Hash#assoc" do
  before(:each) do
    @h = {:apple => :green, :orange => :orange, :grape => :green, :banana => :yellow}
  end

  it "returns an Array is the argument is == to a key of the Hash" do
    @h.assoc(:apple).should be_kind_of(Array)
  end

  it "returns a 2-element Array if the argument is == to a key of the Hash" do
    @h.assoc(:grape).size.should == 2
  end

  it "sets the first element of the Array to the located key" do
    @h.assoc(:banana).first.should == :banana
  end

  it "sets the last element of the Array to the value of the located key" do
    @h.assoc(:banana).last.should == :yellow
  end

  it "returns nil if the argument if not a key of the Hash" do
    @h.assoc(:green).should be_nil
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
opal-0.4.4 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.4.3 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.4.2 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.4.1 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.4.0 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.3.44 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.3.43 spec/rubyspec/core/hash/assoc_spec.rb
opal-0.3.42 spec/core/hash/assoc_spec.rb
opal-0.3.41 spec/core/hash/assoc_spec.rb
opal-0.3.40 spec/core/hash/assoc_spec.rb
opal-0.3.39 spec/core/hash/assoc_spec.rb
opal-0.3.38 spec/core/hash/assoc_spec.rb
opal-0.3.37 spec/core/hash/assoc_spec.rb
opal-0.3.36 spec/core/hash/assoc_spec.rb
opal-0.3.35 spec/core/hash/assoc_spec.rb
opal-0.3.34 spec/core/hash/assoc_spec.rb
opal-0.3.33 spec/core/hash/assoc_spec.rb
opal-0.3.32 spec/core/hash/assoc_spec.rb
opal-0.3.31 spec/core/hash/assoc_spec.rb
opal-0.3.30 spec/core/hash/assoc_spec.rb