rspec-json_expectations 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7be8f6d84a11ad85c20dfdb8a792db48587ed6e
|
4
|
+
data.tar.gz: fce85bc76ad20f75eeb897eae740841e2ffd9fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e06b381b60dc36b9153f80bc8840c8d60d332cc4d03025155b2966408475719d9ebbdfea1b59207f662730a5bf36adb7df9f6a00ff82997df544900ad298cb42
|
7
|
+
data.tar.gz: 14f572322abeeb992f142360504a659984d351d1837f4e94b033546b2119a2a294e69976ad33952f38e196f6617f4769c8a5f7d02376dd4f041bbaa04e21b449
|
@@ -8,6 +8,7 @@ Feature: include_json matcher with hash
|
|
8
8
|
"""ruby
|
9
9
|
require "rspec/json_expectations"
|
10
10
|
"""
|
11
|
+
|
11
12
|
And a local "SIMPLE_HASH" with:
|
12
13
|
"""ruby
|
13
14
|
{
|
@@ -16,6 +17,7 @@ Feature: include_json matcher with hash
|
|
16
17
|
name: "John"
|
17
18
|
}
|
18
19
|
"""
|
20
|
+
|
19
21
|
And a local "BIG_HASH" with:
|
20
22
|
"""ruby
|
21
23
|
{
|
@@ -28,6 +30,16 @@ Feature: include_json matcher with hash
|
|
28
30
|
}
|
29
31
|
"""
|
30
32
|
|
33
|
+
And a local "HASH_WITH_SIMPLE_TYPES" with:
|
34
|
+
"""ruby
|
35
|
+
{
|
36
|
+
phone: nil,
|
37
|
+
name: "A guy without phone",
|
38
|
+
without_phone: true,
|
39
|
+
communicative: false
|
40
|
+
}
|
41
|
+
"""
|
42
|
+
|
31
43
|
Scenario: Expecting json string to include simple json
|
32
44
|
Given a file "spec/simple_example_spec.rb" with:
|
33
45
|
"""ruby
|
@@ -112,4 +124,27 @@ Feature: include_json matcher with hash
|
|
112
124
|
1 example, 0 failures
|
113
125
|
"""
|
114
126
|
|
127
|
+
Scenario: Expecting json response to contain null(s), booleans, etc
|
128
|
+
Given a file "spec/nil_values_spec.rb" with:
|
129
|
+
"""ruby
|
130
|
+
require "spec_helper"
|
131
|
+
|
132
|
+
RSpec.describe "A json response" do
|
133
|
+
subject { %{HASH_WITH_SIMPLE_TYPES} }
|
134
|
+
|
135
|
+
it "has no phone" do
|
136
|
+
expect(subject).to include_json(
|
137
|
+
name: "A guy without phone",
|
138
|
+
phone: nil,
|
139
|
+
communicative: false,
|
140
|
+
without_phone: true
|
141
|
+
)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
"""
|
145
|
+
When I run "rspec spec/nil_values_spec.rb"
|
146
|
+
Then I see:
|
147
|
+
"""
|
148
|
+
1 example, 0 failures
|
149
|
+
"""
|
115
150
|
|
@@ -7,7 +7,8 @@ module RSpec
|
|
7
7
|
# match. Errors are accumulated in errors hash for each
|
8
8
|
# json atom paths.
|
9
9
|
class JsonTraverser
|
10
|
-
|
10
|
+
HANDLED_BY_SIMPLE_VALUE_HANDLER = [String, Numeric, FalseClass, TrueClass, NilClass]
|
11
|
+
SUPPORTED_VALUES = [Hash, Regexp, Array] + HANDLED_BY_SIMPLE_VALUE_HANDLER
|
11
12
|
|
12
13
|
class << self
|
13
14
|
def traverse(errors, expected, actual, negate=false, prefix=[])
|
@@ -48,7 +49,7 @@ module RSpec
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def handle_value(errors, expected, actual, negate=false, prefix=[])
|
51
|
-
return nil unless
|
52
|
+
return nil unless handled_by_simple_value?(expected)
|
52
53
|
|
53
54
|
if conditionally_negate(actual == expected, negate)
|
54
55
|
true
|
@@ -61,6 +62,10 @@ module RSpec
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
65
|
+
def handled_by_simple_value?(expected)
|
66
|
+
HANDLED_BY_SIMPLE_VALUE_HANDLER.any? { |type| type === expected }
|
67
|
+
end
|
68
|
+
|
64
69
|
def handle_regex(errors, expected, actual, negate=false, prefix=[])
|
65
70
|
return nil unless expected.is_a?(Regexp)
|
66
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-json_expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Fedorov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,4 +107,3 @@ test_files:
|
|
107
107
|
- features/rspec/json_expectations/simple_hash_match.feature
|
108
108
|
- features/step_definitions/steps.rb
|
109
109
|
- features/support/env.rb
|
110
|
-
has_rdoc:
|