whiny_hash 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/test/whiny_hash.rb +88 -0
- data/whiny_hash.gemspec +2 -3
- metadata +6 -5
data/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
whiny_hash*.gem
|
data/test/whiny_hash.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'whiny_hash'
|
3
|
+
|
4
|
+
class TestWhinyHash < Test::Unit::TestCase
|
5
|
+
def test_create
|
6
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
7
|
+
assert_equal( wh.count, 3)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_read_normal
|
11
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
12
|
+
assert_equal(wh[:a], 1)
|
13
|
+
assert_equal(wh[:b], 2)
|
14
|
+
assert_equal(wh[:c], 3)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_read_string_keys
|
18
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
19
|
+
assert_equal(wh["a"], 1)
|
20
|
+
assert_equal(wh["b"], 2)
|
21
|
+
assert_equal(wh["c"], 3)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_override_normal
|
25
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
26
|
+
wh[:a] = 9
|
27
|
+
wh[:b] = 8
|
28
|
+
wh[:c] = 7
|
29
|
+
assert_equal(wh[:a], 9)
|
30
|
+
assert_equal(wh[:b], 8)
|
31
|
+
assert_equal(wh[:c], 7)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_override_string_keys
|
35
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
36
|
+
wh["a"] = 9
|
37
|
+
wh["b"] = 8
|
38
|
+
wh["c"] = 7
|
39
|
+
assert_equal(wh[:a], 9)
|
40
|
+
assert_equal(wh[:b], 8)
|
41
|
+
assert_equal(wh[:c], 7)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_spit_read_unset
|
45
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
46
|
+
assert_raise(RuntimeError) { wh[:d] }
|
47
|
+
assert_raise(RuntimeError) { wh["d"] }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_spit_set_unset
|
51
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
52
|
+
assert_raise(RuntimeError) { wh[:d] = 4 }
|
53
|
+
assert_raise(RuntimeError) { wh["d"] = 4 }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_merge_normal
|
57
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
58
|
+
ww = wh.merge :a => 9, :b => 8, :c => 7
|
59
|
+
assert_equal(ww[:a], 9)
|
60
|
+
assert_equal(ww[:b], 8)
|
61
|
+
assert_equal(ww[:c], 7)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_merge_string_keys
|
65
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
66
|
+
ww = wh.merge "a" => 9, "b" => 8, "c" => 7
|
67
|
+
assert_equal(ww[:a], 9)
|
68
|
+
assert_equal(ww[:b], 8)
|
69
|
+
assert_equal(ww[:c], 7)
|
70
|
+
assert_equal(ww["a"], 9)
|
71
|
+
assert_equal(ww["b"], 8)
|
72
|
+
assert_equal(ww["c"], 7)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_spit_merge_unset
|
76
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
77
|
+
assert_raise(RuntimeError) { wh.merge :d => 1, :a => 2 }
|
78
|
+
assert_raise(RuntimeError) { wh.merge "d" => 1 }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_class
|
82
|
+
wh = WhinyHash.new :a => 1, :b => 2, :c => 3
|
83
|
+
ww = wh.merge :a => 9, :b => 8, :c => 7
|
84
|
+
assert(ww.is_a?(Hash))
|
85
|
+
assert(ww.is_a?(ActiveSupport::HashWithIndifferentAccess))
|
86
|
+
assert(ww.is_a?(WhinyHash))
|
87
|
+
end
|
88
|
+
end
|
data/whiny_hash.gemspec
CHANGED
@@ -3,17 +3,16 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "whiny_hash"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.2"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = "A Hash that complains a lot -- used to simplify optional parameters"
|
9
9
|
s.email = "info@provideal.net"
|
10
|
-
s.homepage = "http://github.com/
|
10
|
+
s.homepage = "http://github.com/provideal/whiny_hash"
|
11
11
|
s.description = "A Hash that complains a lot -- used to simplify optional parameters. WhinyHash instances raise errors if unset keys are accessed either directly or by merge."
|
12
12
|
s.authors = ['Peter Horn']
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
-
s.test_files -= Dir["test/support/country_select/**/*"]
|
17
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
17
|
s.require_paths = ["lib"]
|
19
18
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Peter Horn
|
@@ -31,9 +31,10 @@ files:
|
|
31
31
|
- Gemfile
|
32
32
|
- README.textile
|
33
33
|
- lib/whiny_hash.rb
|
34
|
+
- test/whiny_hash.rb
|
34
35
|
- whiny_hash.gemspec
|
35
36
|
has_rdoc: true
|
36
|
-
homepage: http://github.com/
|
37
|
+
homepage: http://github.com/provideal/whiny_hash
|
37
38
|
licenses: []
|
38
39
|
|
39
40
|
post_install_message:
|
@@ -64,5 +65,5 @@ rubygems_version: 1.3.7
|
|
64
65
|
signing_key:
|
65
66
|
specification_version: 3
|
66
67
|
summary: A Hash that complains a lot -- used to simplify optional parameters
|
67
|
-
test_files:
|
68
|
-
|
68
|
+
test_files:
|
69
|
+
- test/whiny_hash.rb
|