hash_dealer 1.4.9 → 1.4.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.9
1
+ 1.4.10
data/hash_dealer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "hash_dealer"
8
- s.version = "1.4.9"
8
+ s.version = "1.4.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Langevin"]
12
- s.date = "2012-08-02"
12
+ s.date = "2012-12-03"
13
13
  s.description = "Like Factory Girl but for Hashes only"
14
14
  s.email = "dan.langevin@lifebooker.com"
15
15
  s.extra_rdoc_files = [
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.homepage = "http://github.com/LifebookerInc/hash_dealer"
42
42
  s.licenses = ["MIT"]
43
43
  s.require_paths = ["lib"]
44
- s.rubygems_version = "1.8.11"
44
+ s.rubygems_version = "1.8.24"
45
45
  s.summary = "Hash Factory - like Factory Girl but for Hashes only"
46
46
 
47
47
  if s.respond_to? :specification_version then
data/lib/comparator.rb CHANGED
@@ -5,6 +5,8 @@ class Comparator
5
5
  def self.formatted_value(val)
6
6
  if val.nil?
7
7
  return "NilClass::nil"
8
+ elsif val.is_a?(PathString)
9
+ return val.gsub(":","")
8
10
  elsif val == ""
9
11
  return "''"
10
12
  else
@@ -22,8 +24,11 @@ class Comparator
22
24
 
23
25
  def self.diff(obj1, obj2)
24
26
  return {} if obj1 == obj2
25
- return self.array_diff(obj1, obj2) if obj1.is_a?(Array) && obj2.is_a?(Array)
26
- return self.hash_diff(obj1, obj2) if obj1.is_a?(Hash) && obj2.is_a?(Hash)
27
+ if obj1.is_a?(Array) && obj2.is_a?(Array)
28
+ return self.array_diff(obj1, obj2)
29
+ elsif obj1.is_a?(Hash) && obj2.is_a?(Hash)
30
+ return self.hash_diff(obj1, obj2)
31
+ end
27
32
  return [formatted_value(obj1), "KEY MISSING"] if obj2.nil?
28
33
  return ["KEY MISSING", formatted_value(obj2)] if obj1.nil?
29
34
  return [formatted_value(obj1), formatted_value(obj2)]
@@ -31,6 +36,12 @@ class Comparator
31
36
 
32
37
  def self.array_diff(obj1, obj2)
33
38
  {}.tap do |ret|
39
+ # handle VariableArray by extracting the first element
40
+ # of non-VariableArrays and the 2nd element of VariableArrays
41
+ if obj1.is_a?(VariableArray) || obj2.is_a?(VariableArray)
42
+ obj1 = obj1.is_a?(VariableArray) ? [obj1[1]] : [obj1[0]]
43
+ obj2 = obj2.is_a?(VariableArray) ? [obj2[1]] : [obj2[0]]
44
+ end
34
45
  bigger_arr = obj1.size >= obj2.size ? obj1 : obj2
35
46
  bigger_arr.each_index do |k|
36
47
  ret[k] = self.diff(obj1[k], obj2[k]) unless obj1[k] == obj2[k]
@@ -30,19 +30,50 @@ describe "match_response Matcher" do
30
30
  {:a => {:b => "c"}}.should match_response({"a" => {"b" => "c"}})
31
31
  end
32
32
 
33
- it "should provide meaningful diffs" do
34
- diff = Comparator.diff({:a => {:b => "c", :d => "e"}}, {:a => {:b => "d", :d => "e"}, :b => "test"})
35
- diff.should eql({"a" => {"b" => ["c", "d"]}, "b" => ["KEY MISSING", "test"]})
33
+ context ".diff" do
34
+
35
+ it "should provide meaningful diffs" do
36
+ h1 = {:a => {:b => "c", :d => "e"}}
37
+ h2 = {:a => {:b => "d", :d => "e"}, :b => "test"}
38
+ diff = Comparator.diff(h1, h2)
39
+ diff.should eql({
40
+ "a" => {"b" => ["c", "d"]},
41
+ "b" => ["KEY MISSING", "test"]
42
+ })
43
+ end
44
+
45
+ it "should match hashes regardless of the order of the keys" do
46
+ Comparator.diff({"a" => {"b" => "c", "d" => "e"}, "b" => "c"}, {:b => "c", :a => {"d" => "e", :b => "c"}}).should eql({})
47
+ end
48
+
49
+ it "should use the matcher comparison inside of Comparator" do
50
+ Comparator.diff({"a" => "dkddk"}.matcher, {"a" => "test"}).should eql({})
51
+ Comparator.diff({"a" => "dkddk"}, {"a" => "test"}.matcher).should eql({})
52
+ end
53
+
54
+ it "should provide meaningful diffs for arrays" do
55
+ h1 = {
56
+ :a => [{"1" => "3"}]
57
+ }
58
+ h2 = {
59
+ :a => [{"2" => "4"}]
60
+ }
61
+ diff = Comparator.diff(h1.matcher, h2)
62
+ diff.should eql({
63
+ "a" => {
64
+ 0 => {
65
+ "1" => ["3", "KEY MISSING"],
66
+ "2" => ["KEY MISSING", "4"]
67
+ }
68
+ }
69
+ })
70
+ true
71
+ end
72
+
73
+
36
74
  end
37
75
 
38
- it "should match hashes regardless of the order of the keys" do
39
- Comparator.diff({"a" => {"b" => "c", "d" => "e"}, "b" => "c"}, {:b => "c", :a => {"d" => "e", :b => "c"}}).should eql({})
40
- end
41
76
 
42
- it "should use the matcher comparison inside of Comparator" do
43
- Comparator.diff({"a" => "dkddk"}.matcher, {"a" => "test"}).should eql({})
44
- Comparator.diff({"a" => "dkddk"}, {"a" => "test"}.matcher).should eql({})
45
- end
46
77
 
47
78
  it "should recursively set hash keys to strings" do
48
79
  Comparator.normalize_value({:x => [[{:y => "z"}]]})["x"].first.first["y"].should eql "z"
data/spec/spec_helper.rb CHANGED
@@ -20,3 +20,8 @@ Debugger.start
20
20
 
21
21
  Dir[File.join(File.dirname(__FILE__), '..', 'spec/support/**/*.rb')].each {|f| require f}
22
22
 
23
+ RSpec.configure do |config|
24
+ config.treat_symbols_as_metadata_keys_with_true_values = true
25
+ config.filter_run :focus => true
26
+ config.run_all_when_everything_filtered = true
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_dealer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.4.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2156289180 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156289180
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: i18n
27
- requirement: &2156288400 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2156288400
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: colorize
38
- requirement: &2156287840 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *2156287840
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: bundler
49
- requirement: &2156287160 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2156287160
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: jeweler
60
- requirement: &2156286200 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *2156286200
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rspec
71
- requirement: &2156285720 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *2156285720
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: rcov
82
- requirement: &2156285080 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,21 +117,31 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *2156285080
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: guard-rspec
93
- requirement: &2156284420 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
- - - =
131
+ - - '='
97
132
  - !ruby/object:Gem::Version
98
133
  version: 0.4.0
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *2156284420
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - '='
140
+ - !ruby/object:Gem::Version
141
+ version: 0.4.0
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: ruby-debug19
104
- requirement: &2156283700 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *2156283700
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: simplecov
115
- requirement: &2156282880 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,7 +165,12 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *2156282880
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  description: Like Factory Girl but for Hashes only
125
175
  email: dan.langevin@lifebooker.com
126
176
  executables: []
@@ -164,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
214
  version: '0'
165
215
  segments:
166
216
  - 0
167
- hash: 2453696594862586054
217
+ hash: 4440880840768368962
168
218
  required_rubygems_version: !ruby/object:Gem::Requirement
169
219
  none: false
170
220
  requirements:
@@ -173,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
223
  version: '0'
174
224
  requirements: []
175
225
  rubyforge_project:
176
- rubygems_version: 1.8.11
226
+ rubygems_version: 1.8.24
177
227
  signing_key:
178
228
  specification_version: 3
179
229
  summary: Hash Factory - like Factory Girl but for Hashes only