rspec-json_matcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/rspec/json_matcher.rb +4 -8
- data/lib/rspec/json_matcher/version.rb +1 -1
- data/spec/rspec/json_matcher_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e45eac67dbe3e29c027ac71c53f7729303270e19
|
4
|
+
data.tar.gz: bf794ed34f279494b7908e55050c3dda5099b6be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed23cc7165475a0e11a4bfb26a1eebeb185c1029711bb7067d86411fe22a77cf0289646ab2dc75d9139654b66361626fdd2ccc5932cf1e6b85209180b6e37b14
|
7
|
+
data.tar.gz: 4541d20701817b6e58ee6ba3aee7efee59b57fe204292fd1651f66d19f41320e392c54510ca9c3983bb8fc357c99def3fe98e72ad8df6a59d1e55a38c810a55d
|
data/README.md
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# RSpec::JsonMatcher
|
2
2
|
This library provides RSpec matcher for testing JSON string.
|
3
3
|
|
4
|
+
* parsing a given value as JSON string
|
5
|
+
* handy pattern matching with `#===` method like case-when statement
|
6
|
+
* supporting nested pattern matching
|
7
|
+
|
4
8
|
## Usage
|
9
|
+
### Configuration
|
5
10
|
```ruby
|
6
11
|
# spec/spec_helper.rb
|
12
|
+
require "rspec/json_matcher"
|
7
13
|
RSpec.configuration.include RSpec::JsonMatcher
|
8
14
|
```
|
9
15
|
|
10
|
-
### Features
|
11
|
-
* parsing a given value as JSON string
|
12
|
-
* handy pattern matching with `#===` method like case-when statement
|
13
|
-
* supporting nested pattern matching
|
14
|
-
|
15
16
|
### Example
|
16
17
|
```ruby
|
17
18
|
[
|
data/lib/rspec/json_matcher.rb
CHANGED
@@ -9,7 +9,7 @@ module RSpec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class Matcher
|
12
|
-
attr_reader :expected
|
12
|
+
attr_reader :expected, :parsed
|
13
13
|
|
14
14
|
def initialize(expected = nil)
|
15
15
|
@expected = expected
|
@@ -18,7 +18,7 @@ module RSpec
|
|
18
18
|
def matches?(json)
|
19
19
|
@parsed = JSON.parse(json)
|
20
20
|
if has_expectation?
|
21
|
-
Comparer.compare(
|
21
|
+
Comparer.compare(parsed, expected)
|
22
22
|
else
|
23
23
|
true
|
24
24
|
end
|
@@ -58,7 +58,7 @@ module RSpec
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def inspection(prefix = nil)
|
61
|
-
["expected #{prefix}to match:",
|
61
|
+
["expected #{prefix}to match:", expected.ai, "", "actual:", parsed.ai].join("\n")
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -75,7 +75,7 @@ module RSpec
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def compare
|
78
|
-
|
78
|
+
has_equal_value? || has_same_collection?
|
79
79
|
end
|
80
80
|
|
81
81
|
private
|
@@ -88,10 +88,6 @@ module RSpec
|
|
88
88
|
actual.size == expected.size
|
89
89
|
end
|
90
90
|
|
91
|
-
def has_same_value?
|
92
|
-
has_equal_value? || has_same_collection?
|
93
|
-
end
|
94
|
-
|
95
91
|
def has_equal_value?
|
96
92
|
if expected.respond_to?(:call)
|
97
93
|
expected.call(actual)
|