Sha256: 24c193502107f895e71e5df921e0f7c5fbf3e90609c868d014ab3ec8cab9b0c9

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

require_relative "spec_helper"

module Nyara
  describe ParamHash do
    it "symbol/string keys in ParamHash are the same" do
      h = ParamHash.new
      h[:a] = 3
      assert_equal 3, h['a']
      assert_equal true, h.key?(:a)
      assert_equal true, h.key?('a')
      assert_equal 1, h.size
    end
  end

  describe HeaderHash do
    it "ignores case in key" do
      h = HeaderHash.new
      h['a-bc'] = 'good'
    end

    it "headerlizes key and stringify value" do
      h = HeaderHash.new
      h['Content-type'] = 'text/html'
      h[:'content-tYpe'] = :'text/plain'
      assert_equal 1, h.size
      assert_equal ['Content-Type', 'text/plain'], h.to_a.first
    end

    class HaHash < HeaderHash
    end

    it "#reverse_merge! raises error if other is not HeaderHash" do
      h = HeaderHash.new
      h.reverse_merge! HaHash.new # :)
      assert_raise ArgumentError do
        h.reverse_merge!({})
      end
    end

    it "#reverse_merge!" do
      h = HeaderHash.new
      g = HeaderHash.new
      h['a'] = 'h'
      g['a'] = 'g'
      g['b'] = 'b'
      h.reverse_merge! g
      assert_equal 2, h.size
      assert_equal 'h', h['a']
      assert_equal 'b', h['b']
    end
  end

  describe ConfigHash do
    it "deep key assignment" do
      h = ConfigHash.new
      h['a', 'deep', 'key1'] = 'value1'
      h['a', 'deep', :key2] = 'value2'
      assert_equal 'value1', h['a', 'deep', :key1]
      assert_equal 'value2', h['a']['deep']['key2']
    end

    it "works when last available key exists as other hash type" do
      h = ConfigHash.new
      other_h = {}
      h['a'] = other_h
      h['a', 'b'] = 3
      assert_equal 3, h['a', 'b']
      assert_equal other_h.object_id, h['a'].object_id
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyara-0.0.1.pre.5 spec/hashes_spec.rb
nyara-0.0.1.pre.4 spec/hashes_spec.rb
nyara-0.0.1.pre.3 spec/hashes_spec.rb
nyara-0.0.1.pre.2 spec/hashes_spec.rb
nyara-0.0.1.pre.1 spec/hashes_spec.rb
nyara-0.0.1.pre spec/hashes_spec.rb