Sha256: d3a31d7c55d3857e70787bc3490a3909bf9669d6c63edb64f7604a790014c316

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

require 'test/unit'
require 'jr/cli/core_ext/hash'

class HashTest < Test::Unit::TestCase
  sub_test_case 'read propertya' do
    test 'read the value' do
      assert do
        {foo: 'bar'}.foo == 'bar'
      end
    end

    test 'return nil if the key does not exist' do
      assert do
        {foo: 'bar'}.bar == nil
      end
    end
  end

  sub_test_case 'check key existence' do
    test 'return true if the key exists and truthy' do
      assert do
        {foo: 'bar'}.foo? == true
      end
    end

    test 'return false if the key exists but it is false' do
      assert do
        {foo: false}.foo? == false
      end
    end

    test 'return false if the key exists but it is nil' do
      assert do
        {foo: nil}.foo? == false
      end
    end

    test 'return false if the key does not exists' do
      assert do
        {foo: 'bar'}.bar? == false
      end
    end
  end

  sub_test_case 'write property' do
    test 'write value into the property' do
      assert do
        hash = {}
        hash.foo = 'bar'
        hash.foo == 'bar'
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jr-cli-0.6.0 test/unit/core_ext/hash_test.rb
jr-cli-0.5.1 test/unit/core_ext/hash_test.rb
jr-cli-0.5.0 test/unit/core_ext/hash_test.rb
jr-cli-0.4.0 test/unit/core_ext/hash_test.rb
jr-cli-0.3.1 test/unit/core_ext/hash_test.rb
jr-cli-0.3.0 test/unit/core_ext/hash_test.rb
jr-cli-0.2.0 test/unit/core_ext/hash_test.rb