test/hashr_test.rb in hashr-0.0.22 vs test/hashr_test.rb in hashr-1.0.0
- old
+ new
@@ -1,16 +1,20 @@
require 'test_helper'
-class HashrTest < Test::Unit::TestCase
+class HashrTest < Minitest::Test
def teardown
Hashr.raise_missing_keys = false
end
test 'initialize takes nil' do
- assert_nothing_raised { Hashr.new(nil) }
+ Hashr.new(nil)
end
+ test 'initialize raises an ArgumentError when given a string' do
+ assert_raises(ArgumentError) { Hashr.new("foo") }
+ end
+
test 'method access on an existing key returns the value' do
assert_equal 'foo', Hashr.new(:foo => 'foo').foo
end
test 'method access on a non-existing key returns nil when raise_missing_keys is false' do
@@ -87,10 +91,29 @@
hashr = Hashr.new
hashr[:foo] = 'foo'
assert_equal 'foo', hashr.foo
end
+ test 'respond_to? returns true if raise_missing_keys is off' do
+ Hashr.raise_missing_keys = false
+ hashr = Hashr.new
+ assert hashr.respond_to?(:foo)
+ end
+
+ test 'respond_to? returns false for missing keys if raise_missing_keys is on' do
+ Hashr.raise_missing_keys = true
+ hashr = Hashr.new
+ assert_equal false, hashr.respond_to?(:foo)
+ end
+
+ test 'respond_to? returns true for extant keys if raise_missing_keys is on' do
+ Hashr.raise_missing_keys = true
+ hashr = Hashr.new
+ hashr[:foo] = 'bar'
+ assert hashr.respond_to?(:foo)
+ end
+
test 'defining defaults' do
klass = Class.new(Hashr) do
define :foo => 'foo', :bar => { :baz => 'baz' }
end
assert_equal 'foo', klass.new.foo
@@ -203,6 +226,5 @@
hashr = Hashr.new(:foo => { :bar => 'bar' })
hashr.set('foo.baz', 'baz')
assert_equal 'baz', hashr.foo.baz
end
end
-