rspec-json_api 1.2.2 → 1.3.1
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -1
- data/lib/rspec/json_api/matchers/have_no_content.rb +22 -2
- data/lib/rspec/json_api/matchers/match_json_schema.rb +31 -10
- data/lib/rspec/json_api/version.rb +1 -1
- data/lib/rspec/json_api.rb +1 -0
- data/rspec-json_api.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4b978bb71054b9d75d61a47c0213eb26888876c72a132bd77da8e2a8aea15b
|
4
|
+
data.tar.gz: 69896916d64f74eb3c63708f6a84e412c9a0b8e5d2b9283fad40133f7f80a143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69138827c7e5241305a32bac25ba0247e60bc7836bd31a22dd5fa3160a8c8247872359e716ded38e2876a299343cc516d643d2d0c8263a85928a11e4dc69b6d
|
7
|
+
data.tar.gz: a3ab6e463a51bb29c9a12fae052fff6f0f9a8e3732642b5a1a4a195078761e8a216235a655987a767c5b2f737ccb5a9dcb303d6ef66ff032a8ff811c113ba00c
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-json_api (1.
|
4
|
+
rspec-json_api (1.3.1)
|
5
5
|
activesupport (>= 6.1.4.1)
|
6
|
+
diffy (>= 3.4.2)
|
6
7
|
rails (>= 6.1.4.1)
|
7
8
|
rspec-rails (>= 5.0.2)
|
8
9
|
|
@@ -75,6 +76,7 @@ GEM
|
|
75
76
|
crass (1.0.6)
|
76
77
|
date (3.3.4)
|
77
78
|
diff-lcs (1.5.0)
|
79
|
+
diffy (3.4.2)
|
78
80
|
erubi (1.10.0)
|
79
81
|
globalid (1.2.1)
|
80
82
|
activesupport (>= 6.1)
|
@@ -201,6 +203,7 @@ PLATFORMS
|
|
201
203
|
|
202
204
|
DEPENDENCIES
|
203
205
|
activesupport (~> 6.1, >= 6.1.4.1)
|
206
|
+
diffy
|
204
207
|
rake (~> 13.0, >= 13.0.6)
|
205
208
|
rspec-json_api!
|
206
209
|
rspec-rails (~> 5.0, >= 5.0.2)
|
@@ -3,17 +3,37 @@
|
|
3
3
|
module RSpec
|
4
4
|
module JsonApi
|
5
5
|
module Matchers
|
6
|
+
# The HaveNoContent class is designed to verify that a given string is empty.
|
7
|
+
#
|
8
|
+
# This matcher is primarily used within RSpec tests to assert that a given
|
9
|
+
# string lacks content, effectively ensuring that expected content is absent,
|
10
|
+
# which can be particularly useful in testing API responses or other outputs
|
11
|
+
# where the absence of content signifies a specific state or outcome.
|
6
12
|
class HaveNoContent
|
13
|
+
# Determines whether the actual string is empty, signifying no content.
|
14
|
+
#
|
15
|
+
# @param actual [String] The string to be evaluated.
|
16
|
+
# @return [Boolean] Returns true if the string is empty, indicating no content; false otherwise.
|
7
17
|
def matches?(actual)
|
8
18
|
actual == ""
|
9
19
|
end
|
10
20
|
|
21
|
+
# Provides a failure message for when the actual string contains content,
|
22
|
+
# contrary to the expectation of being empty.
|
23
|
+
#
|
24
|
+
# @return [String] A descriptive message indicating the expectation was for
|
25
|
+
# the string to have no content, yet content was found.
|
11
26
|
def failure_message
|
12
|
-
|
27
|
+
"expected the string to be empty but it contained content"
|
13
28
|
end
|
14
29
|
|
30
|
+
# Provides a failure message for when the expectation is negated (i.e.,
|
31
|
+
# expecting content) and the actual string is unexpectedly empty.
|
32
|
+
#
|
33
|
+
# @return [String] A descriptive message indicating that content was expected
|
34
|
+
# in the string, but it was found to be empty.
|
15
35
|
def failure_message_when_negated
|
16
|
-
|
36
|
+
"expected the string not to be empty, yet it was devoid of content"
|
17
37
|
end
|
18
38
|
end
|
19
39
|
end
|
@@ -3,36 +3,57 @@
|
|
3
3
|
module RSpec
|
4
4
|
module JsonApi
|
5
5
|
module Matchers
|
6
|
+
# MatchJsonSchema class is designed to match a given JSON against a predefined JSON schema.
|
7
|
+
#
|
8
|
+
# This matcher is useful for validating JSON structures in API responses or other JSON data
|
9
|
+
# against a schema defined either as a Hash, an Array, or another JSON structure.
|
6
10
|
class MatchJsonSchema
|
11
|
+
# @return [Object] the expected JSON schema to match against
|
7
12
|
attr_reader :expected
|
13
|
+
# @return [Object] the actual JSON data being tested
|
14
|
+
attr_reader :actual
|
8
15
|
|
16
|
+
# Initializes the matcher with the expected JSON schema.
|
17
|
+
# @param expected [Object] The expected JSON schema as a Hash, Array, or other JSON-compatible structure.
|
9
18
|
def initialize(expected)
|
10
19
|
@expected = expected
|
11
20
|
end
|
12
21
|
|
22
|
+
# Matches the actual JSON data against the expected schema.
|
23
|
+
# @param actual [String] The JSON string to test against the expected schema.
|
24
|
+
# @return [Boolean] true if the actual JSON matches the expected schema, false otherwise.
|
13
25
|
def matches?(actual)
|
14
|
-
|
15
|
-
|
26
|
+
@actual = JSON.parse(actual, symbolize_names: true)
|
27
|
+
@diff = Diffy::Diff.new(expected, @actual, context: 5)
|
16
28
|
|
17
|
-
|
18
|
-
return false unless actual.instance_of?(expected.class)
|
29
|
+
return false unless @actual.instance_of?(expected.class)
|
19
30
|
|
20
31
|
if expected.instance_of?(Array)
|
21
|
-
RSpec::JsonApi::CompareArray.compare(actual, expected)
|
32
|
+
RSpec::JsonApi::CompareArray.compare(@actual, expected)
|
22
33
|
else
|
23
|
-
|
24
|
-
return false unless actual.deep_keys.deep_sort == expected.deep_keys.deep_sort
|
34
|
+
return false unless @actual.deep_keys.deep_sort == expected.deep_keys.deep_sort
|
25
35
|
|
26
|
-
RSpec::JsonApi::CompareHash.compare(actual, expected)
|
36
|
+
RSpec::JsonApi::CompareHash.compare(@actual, expected)
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
40
|
+
# Provides a failure message for when the JSON data does not match the expected schema.
|
41
|
+
# @return [String] A descriptive message detailing the mismatch between expected and actual JSON.
|
30
42
|
def failure_message
|
31
|
-
|
43
|
+
<<~MSG
|
44
|
+
expected: #{expected}
|
45
|
+
got: #{actual}
|
46
|
+
|
47
|
+
Diff:
|
48
|
+
#{@diff}
|
49
|
+
MSG
|
32
50
|
end
|
33
51
|
|
52
|
+
# Provides a failure message for when the JSON data matches the expected schema, but it was expected not to.
|
53
|
+
# This is used in negative matchers.
|
54
|
+
# @return [self] Returns itself, but typically this method should be implemented to return a descriptive message
|
34
55
|
def failure_message_when_negated
|
35
|
-
|
56
|
+
"expected the JSON data not to match the provided schema, but it did."
|
36
57
|
end
|
37
58
|
end
|
38
59
|
end
|
data/lib/rspec/json_api.rb
CHANGED
data/rspec-json_api.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
# Uncomment to register a new dependency of your gem
|
30
30
|
spec.add_dependency "activesupport", ">= 6.1.4.1"
|
31
|
+
spec.add_dependency "diffy", ">= 3.4.2"
|
31
32
|
spec.add_dependency "rails", ">= 6.1.4.1"
|
32
33
|
spec.add_dependency "rspec-rails", ">= 5.0.2"
|
33
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-json_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Gajowiak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.1.4.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: diffy
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.4.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.4.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|