dot_hash 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,6 +4,6 @@ require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs.push "lib"
7
- t.test_files = FileList['test/*_test.rb']
7
+ t.test_files = FileList['test/**/*_test.rb']
8
8
  t.verbose = true
9
9
  end
@@ -11,6 +11,11 @@ module DotHash
11
11
  has_key?(key) ? get_value(key) : super
12
12
  end
13
13
 
14
+ def respond_to?(key, *args)
15
+ symbolize_key key
16
+ has_key?(key) or super(key, *args)
17
+ end
18
+
14
19
  private
15
20
 
16
21
  def has_key?(key)
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require File.expand_path("../../test_helper", __FILE__)
2
2
 
3
3
  describe Hash do
4
4
  attr_reader :properties
@@ -0,0 +1,69 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ module DotHash
4
+ describe Properties do
5
+ attr_reader :settings
6
+
7
+ describe "#method_missing" do
8
+ describe "with a simple hash" do
9
+ before do
10
+ @settings = Properties.new speed: "15", "power" => 100
11
+ end
12
+
13
+ it "gets a hash property using the dot notation" do
14
+ settings.speed.must_equal "15"
15
+ end
16
+
17
+ it "raises an error if the method is not on the hash" do
18
+ -> {settings.name}.must_raise NoMethodError
19
+ end
20
+
21
+ it "gets a property from a stringed key" do
22
+ settings.power.must_equal 100
23
+ end
24
+ end
25
+
26
+ describe "with a nested hash" do
27
+ before do
28
+ @settings = Properties.new user: {
29
+ "info" => {name: "dude", is_admin: false}
30
+ }
31
+ end
32
+
33
+ it "returns a DotHash instence for property with a nested hash" do
34
+ settings.user.must_be_instance_of DotHash::Properties
35
+ end
36
+
37
+ it "gets chained properties" do
38
+ settings.user.info.name.must_equal "dude"
39
+ settings.user.info.is_admin.must_equal false
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#respond_to?" do
45
+ before do
46
+ @settings = Properties.new speed: "15",
47
+ info: {name: "Eden"},
48
+ "color" => "#00FFBB"
49
+ end
50
+
51
+ it "responds to a simple property" do
52
+ settings.must_respond_to :speed
53
+ end
54
+
55
+ it "responds to a nested property" do
56
+ settings.info.must_respond_to :name
57
+ end
58
+
59
+ it "respond to a string property" do
60
+ settings.must_respond_to :color
61
+ end
62
+
63
+ it "doesn't respond to a missing property" do
64
+ settings.wont_respond_to :size
65
+ end
66
+ end
67
+
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -44,8 +44,8 @@ files:
44
44
  - lib/dot_hash/hash_to_properties.rb
45
45
  - lib/dot_hash/properties.rb
46
46
  - lib/dot_hash/version.rb
47
- - test/dot_hash_test.rb
48
- - test/hash_to_properties_test.rb
47
+ - test/dot_hash/hash_to_properties_test.rb
48
+ - test/dot_hash/properties_test.rb
49
49
  - test/test_helper.rb
50
50
  homepage: https://github.com/3den/dot_hash
51
51
  licenses: []
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: -4110770147551490378
64
+ hash: -2717258685003126638
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: -4110770147551490378
73
+ hash: -2717258685003126638
74
74
  requirements: []
75
75
  rubyforge_project:
76
76
  rubygems_version: 1.8.24
@@ -78,6 +78,6 @@ signing_key:
78
78
  specification_version: 3
79
79
  summary: Converts hash.to_properties so you can access values using properties.some_key
80
80
  test_files:
81
- - test/dot_hash_test.rb
82
- - test/hash_to_properties_test.rb
81
+ - test/dot_hash/hash_to_properties_test.rb
82
+ - test/dot_hash/properties_test.rb
83
83
  - test/test_helper.rb
@@ -1,44 +0,0 @@
1
- require File.expand_path("../test_helper", __FILE__)
2
-
3
- module DotHash
4
- describe Properties do
5
- attr_reader :settings
6
-
7
- describe "with a simple hash" do
8
- before do
9
- @settings = Properties.new speed: "15", "power" => 100
10
- end
11
-
12
- it "gets a hash property using the dot notation" do
13
- settings.speed.must_equal "15"
14
- end
15
-
16
- it "raises an error if the method is not on the hash" do
17
- -> {settings.name}.must_raise NoMethodError
18
- end
19
-
20
- it "gets a property from a stringed key" do
21
- settings.power.must_equal 100
22
- end
23
- end
24
-
25
- describe "with a nested hash" do
26
- before do
27
- @settings = Properties.new user: {
28
- "info" => {name: "dude", is_admin: false}
29
- }
30
- end
31
-
32
- it "returns a DotHash instence for property with a nested hash" do
33
- settings.user.must_be_instance_of DotHash::Properties
34
- end
35
-
36
- it "gets chained properties" do
37
- settings.user.info.name.must_equal "dude"
38
- settings.user.info.is_admin.must_equal false
39
- end
40
-
41
- end
42
-
43
- end
44
- end