rspec-json_matcher 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/rspec/json_matcher/version.rb +1 -1
- data/lib/rspec/json_matcher.rb +13 -14
- data/spec/rspec/json_matcher_spec.rb +11 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b5b194d82e6f879060a40c9cee4ecdd96cd38ab
|
4
|
+
data.tar.gz: d7e4b9e053a6a0312542f451a9d6be0183cf469f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 419d26029dab6cf9868443c61fe14ddfedbd35cc6a1403b2760b03c0a04771ab202ef868c237311a2edeee08030d78c60a7bc1e5d569f10ccf6ef10ec6f22f3a
|
7
|
+
data.tar.gz: 8434fa25f560b14afc212606c994969fefb18368695c9fc5844b96cc18f93faa91e12a547c8a97622ef059dc1f3e18b575ca6a0a54f94f46e0f2e3f33bff87f4
|
data/CHANGELOG.md
ADDED
data/lib/rspec/json_matcher.rb
CHANGED
@@ -69,6 +69,14 @@ module RSpec
|
|
69
69
|
new(*args).compare
|
70
70
|
end
|
71
71
|
|
72
|
+
def self.extract_keys(array_or_hash)
|
73
|
+
if array_or_hash.is_a?(Array)
|
74
|
+
array_or_hash.each_index.to_a
|
75
|
+
else
|
76
|
+
array_or_hash.keys
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
72
80
|
def initialize(actual, expected)
|
73
81
|
@actual = actual
|
74
82
|
@expected = expected
|
@@ -84,8 +92,8 @@ module RSpec
|
|
84
92
|
actual.class == expected.class
|
85
93
|
end
|
86
94
|
|
87
|
-
def
|
88
|
-
actual.size ==
|
95
|
+
def has_same_keys?
|
96
|
+
(self.class.extract_keys(actual) - self.class.extract_keys(expected)).size == 0
|
89
97
|
end
|
90
98
|
|
91
99
|
def has_same_value?
|
@@ -97,25 +105,16 @@ module RSpec
|
|
97
105
|
end
|
98
106
|
|
99
107
|
def has_same_collection?
|
100
|
-
collection? && has_same_class? &&
|
108
|
+
collection? && has_same_class? && has_same_keys? && has_same_values?
|
101
109
|
end
|
102
110
|
|
103
|
-
def
|
104
|
-
|
111
|
+
def has_same_values?
|
112
|
+
self.class.extract_keys(actual).all? {|key| self.class.compare(actual[key], expected[key]) }
|
105
113
|
end
|
106
114
|
|
107
115
|
def collection?
|
108
116
|
actual.is_a?(Array) || actual.is_a?(Hash)
|
109
117
|
end
|
110
|
-
|
111
|
-
def keys
|
112
|
-
case actual
|
113
|
-
when Array
|
114
|
-
actual.each_index
|
115
|
-
when Hash
|
116
|
-
actual.keys
|
117
|
-
end
|
118
|
-
end
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -2,11 +2,21 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe RSpec::JsonMatcher do
|
4
4
|
context "with invalid JSON" do
|
5
|
-
it "does match" do
|
5
|
+
it "does not match" do
|
6
6
|
"".should_not be_json
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
context "with invalid keys JSON" do
|
11
|
+
it "does not match" do
|
12
|
+
{
|
13
|
+
"a" => nil
|
14
|
+
}.to_json.should_not be_json(
|
15
|
+
"b" => nil
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
context "with valid JSON" do
|
11
21
|
it "matches with handy patterns" do
|
12
22
|
[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-json_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
|
+
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.
|
122
|
+
rubygems_version: 2.0.3
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: RSpec matcher for testing JSON string
|