json_matcher 0.0.4 → 0.0.5
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 +2 -0
- data/lib/json_matcher.rb +11 -4
- data/lib/json_matcher/version.rb +1 -1
- data/spec/json_matcher_spec.rb +2 -2
- metadata +8 -9
data/lib/json_matcher.rb
CHANGED
@@ -21,8 +21,7 @@ module JsonMatcher
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def similar?
|
24
|
-
|
25
|
-
return @options[:exact] ? equal : equal_without_order
|
24
|
+
@options[:exact] ? equal : equal_without_order
|
26
25
|
end
|
27
26
|
|
28
27
|
def to_s
|
@@ -36,8 +35,8 @@ module JsonMatcher
|
|
36
35
|
|
37
36
|
def equal_without_order
|
38
37
|
return true if @actual_hash == @expected_hash
|
39
|
-
@failure_msg[:extra] = @actual_hash
|
40
|
-
@failure_msg[:less] = @expected_hash
|
38
|
+
@failure_msg[:extra] = get_failuer_if_extra_keys(@actual_hash, @expected_hash)
|
39
|
+
@failure_msg[:less] = get_failuer_if_extra_keys(@expected_hash, @actual_hash)
|
41
40
|
hash_matcher @actual_hash, @expected_hash
|
42
41
|
@failure_msg[:extra].length == 0 and @failure_msg[:less].length == 0
|
43
42
|
end
|
@@ -63,5 +62,13 @@ module JsonMatcher
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
65
|
+
def get_failuer_if_extra_keys first, second
|
66
|
+
first.inject({}) do |hash, key_value|
|
67
|
+
key, value = key_value
|
68
|
+
hash[key] = value unless second.keys.include?(key)
|
69
|
+
hash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
66
73
|
end
|
67
74
|
end
|
data/lib/json_matcher/version.rb
CHANGED
data/spec/json_matcher_spec.rb
CHANGED
@@ -59,8 +59,8 @@ describe JsonMatcher do
|
|
59
59
|
describe "options" do
|
60
60
|
describe "exact match" do
|
61
61
|
it "should just do exact match if option exact set to true" do
|
62
|
-
actual = {
|
63
|
-
expected = {
|
62
|
+
actual = "{\"key\":\"value\",\"extra_key\":\"value2\",\"another_key\":\"value3\"}"
|
63
|
+
expected = "{\"extra_key\":\"value2\",\"another_key\":\"value3\",\"key\":\"value\"}"
|
64
64
|
JsonMatcher.similar(actual, expected, {:exact => true}).should_not be_nil
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
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: 2011-11-
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157570900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157570900
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: term-ansicolor
|
27
|
-
requirement: &
|
27
|
+
requirement: &2157570480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2157570480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2157570060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2157570060
|
47
47
|
description: A gem that matches similar json and ignores order
|
48
48
|
email:
|
49
49
|
- garima.slideshare@gmail.com
|
@@ -52,7 +52,6 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
|
-
- .rvmrc
|
56
55
|
- Gemfile
|
57
56
|
- README.md
|
58
57
|
- Rakefile
|