json-deep-compare 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,6 +111,10 @@ module JsonDeepCompare
111
111
  )
112
112
  end
113
113
 
114
+ def has_substitution?
115
+ @options[:substitutions] && @options[:substitutions].has_key?(selector)
116
+ end
117
+
114
118
  def leaf?
115
119
  @children.empty?
116
120
  end
@@ -121,7 +125,7 @@ module JsonDeepCompare
121
125
 
122
126
  def lval_for_equality
123
127
  @_lval_for_equality ||= begin
124
- if left_to_right? && substitution
128
+ if left_to_right? && has_substitution?
125
129
  substitution
126
130
  else
127
131
  lval
@@ -135,7 +139,7 @@ module JsonDeepCompare
135
139
 
136
140
  def rval_for_equality
137
141
  @_rval_for_equality ||= begin
138
- if right_to_left? && substitution
142
+ if right_to_left? && has_substitution?
139
143
  substitution
140
144
  else
141
145
  rval
@@ -154,7 +158,7 @@ module JsonDeepCompare
154
158
  end
155
159
 
156
160
  def substitution
157
- @options[:substitutions] && @options[:substitutions][selector]
161
+ @options[:substitutions][selector]
158
162
  end
159
163
 
160
164
  def value_inspect(value)
@@ -1,3 +1,3 @@
1
1
  module JsonDeepCompare
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -207,4 +207,19 @@ class DocumentComparisonTestCase < Test::Unit::TestCase
207
207
  )
208
208
  assert comparison.equal?
209
209
  end
210
+
211
+ def test_substitions_with_falsy_values
212
+ lval = {'one' => 'false'}
213
+ rval = {'one' => false}
214
+ comparison = JsonDeepCompare::DocumentComparison.new(
215
+ lval, rval, substitutions: {":root > .one" => false}
216
+ )
217
+ assert comparison.equal?
218
+ lval = {'one' => 'null'}
219
+ rval = {'one' => nil}
220
+ comparison = JsonDeepCompare::DocumentComparison.new(
221
+ lval, rval, substitutions: {":root > .one" => nil}
222
+ )
223
+ assert comparison.equal?
224
+ end
210
225
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-deep-compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: -2030263147861406758
80
+ hash: -2669003529915222280
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: -2030263147861406758
89
+ hash: -2669003529915222280
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.23