rspec-composable_json_matchers 1.0.2 → 1.1.0
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 +5 -5
- data/.rubocop.yml +4 -0
- data/.travis.yml +6 -8
- data/Gemfile +5 -3
- data/README.md +28 -14
- data/Rakefile +2 -2
- data/lib/rspec/composable_json_matchers.rb +27 -10
- data/lib/rspec/composable_json_matchers/version.rb +2 -2
- data/rspec-composable_json_matchers.gemspec +1 -2
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 60aedac8bfa4be5a25ee02f5690bc668fa0877ac5694d25dcfd49e51b1f5959d
|
4
|
+
data.tar.gz: b75aa47517e390d769bf6bb85774fe16700572b3f481cf9f2f0b0d28477a08ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50c03bfe28eb3e07fc14340429a4d6d69d080373b857043d36df06ee548ce671e3ecb228e5c70e992491d417a4bbcc541078f76b4ae680478c2f5c0f5e286f3d
|
7
|
+
data.tar.gz: 567b30332befa7757725ca1940edfbc0cb4198b995204d27f8a080e22d7e4743aafa5dce19f760fdcc9ffdaa9cd14412ecaf42da41262d596514ba1672308fb2
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- jruby-19mode
|
8
|
-
- jruby-9.0.0.0
|
9
|
-
before_install: gem update bundler
|
10
|
-
script: bundle exec rake ci
|
3
|
+
- 2.2.9
|
4
|
+
- 2.3.6
|
5
|
+
- 2.4.3
|
6
|
+
- 2.5.0
|
11
7
|
sudo: false
|
12
8
|
cache: bundler
|
9
|
+
before_install: gem update --system
|
10
|
+
script: bundle exec rake ci
|
data/Gemfile
CHANGED
@@ -4,10 +4,12 @@ gemspec
|
|
4
4
|
|
5
5
|
group :development, :test do
|
6
6
|
gem 'coderay', '~> 1.1'
|
7
|
-
gem 'rake', '~>
|
8
|
-
gem 'rubocop', '~> 0.
|
7
|
+
gem 'rake', '~> 12.0'
|
8
|
+
gem 'rubocop', '~> 0.51'
|
9
9
|
gem 'simplecov', '~> 0.11'
|
10
|
-
gem '
|
10
|
+
gem 'vcr', '~> 4.0'
|
11
|
+
gem 'webmock', '~> 3.0'
|
12
|
+
gem 'yard', '>= 0.9.11', '< 1.0'
|
11
13
|
end
|
12
14
|
|
13
15
|
group :test do
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
[](https://gemnasium.com/yujinakayama/rspec-composable_json_matchers)
|
1
|
+
[](http://badge.fury.io/rb/rspec-composable_json_matchers)
|
3
2
|
[](https://travis-ci.org/yujinakayama/rspec-composable_json_matchers)
|
4
|
-
[](https://coveralls.io/github/yujinakayama/rspec-composable_json_matchers?branch=master)
|
4
|
+
[](https://codeclimate.com/github/yujinakayama/rspec-composable_json_matchers)
|
6
5
|
|
7
6
|
# RSpec::ComposableJSONMatchers
|
8
7
|
|
@@ -53,7 +52,7 @@ Or if you prefer more explicit way, add the following snippet:
|
|
53
52
|
require 'rspec/composable_json_matchers'
|
54
53
|
|
55
54
|
RSpec.configure do |config|
|
56
|
-
include RSpec::ComposableJSONMatchers
|
55
|
+
config.include RSpec::ComposableJSONMatchers
|
57
56
|
end
|
58
57
|
```
|
59
58
|
|
@@ -71,10 +70,11 @@ end
|
|
71
70
|
|
72
71
|
## Usage
|
73
72
|
|
74
|
-
The `be_json` matcher takes another matcher
|
73
|
+
The `be_json` matcher takes another matcher
|
74
|
+
or a JSON value (hash, array, numeric, string, true, false, or nil).
|
75
75
|
|
76
76
|
When a matcher is given,
|
77
|
-
it passes if actual string can be decoded as JSON and the decoded
|
77
|
+
it passes if actual string can be decoded as JSON and the decoded value passes the given matcher:
|
78
78
|
|
79
79
|
```ruby
|
80
80
|
expect('{ "foo": 1, "bar": 2 }').to be_json a_kind_of(Hash)
|
@@ -84,10 +84,12 @@ expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: 1)
|
|
84
84
|
expect('["foo", "bar"]').to be_json a_kind_of(Array)
|
85
85
|
expect('["foo", "bar"]').to be_json matching(['foo', 'bar'])
|
86
86
|
expect('["foo", "bar"]').to be_json including('foo')
|
87
|
+
|
88
|
+
expect('null').to be_json(nil)
|
87
89
|
```
|
88
90
|
|
89
|
-
When a
|
90
|
-
it's handled as `be_json matching(
|
91
|
+
When a JSON value is given,
|
92
|
+
it's handled as `be_json matching(value)` (`matching` is an alias of the `match` matcher):
|
91
93
|
|
92
94
|
```ruby
|
93
95
|
# Equivalents
|
@@ -112,13 +114,14 @@ for the [GitHub Meta API](https://developer.github.com/v3/meta/).
|
|
112
114
|
|
113
115
|
## Combinations with built-in matchers
|
114
116
|
|
115
|
-
Since decoded JSON is
|
117
|
+
Since decoded JSON is a hash or an array in most cases,
|
118
|
+
you may want to use any of the following built-in matchers.
|
116
119
|
|
117
|
-
Note that you can always use the `
|
118
|
-
instead of the `
|
119
|
-
because there's no
|
120
|
+
Note that you can always use the `match` matcher (internally uses `#===`)
|
121
|
+
instead of the `eq` matcher (internally uses `#==`),
|
122
|
+
because there's no object that is parsed from JSON and behaves differently between `#==` and `#===`.
|
120
123
|
|
121
|
-
Of course, any other custom matchers
|
124
|
+
Of course, any other custom matchers can also be used.
|
122
125
|
|
123
126
|
### `matching`
|
124
127
|
|
@@ -182,6 +185,17 @@ expect('["foo", "bar"]').to be_json starting_with('foo')
|
|
182
185
|
expect('["foo", "bar"]').to be_json ending_with('bar')
|
183
186
|
```
|
184
187
|
|
188
|
+
### `having_attributes`
|
189
|
+
|
190
|
+
* Alias of [`have_attributes`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/have-attributes-matcher) matcher
|
191
|
+
* Supported structure: Hash and Array
|
192
|
+
* Accepts matchers as arguments: Yes
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json having_attributes(keys: [:foo, :bar])
|
196
|
+
expect('["foo", "bar"]').to be_json having_attributes(size: 2)
|
197
|
+
```
|
198
|
+
|
185
199
|
### `a_kind_of`
|
186
200
|
|
187
201
|
* Alias of [`be_a_kind_of`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/type-matchers#be-(a-)kind-of-matcher) matcher
|
data/Rakefile
CHANGED
@@ -64,16 +64,31 @@ module RSpec
|
|
64
64
|
|
65
65
|
object.respond_to?(:matches?)
|
66
66
|
end
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
def json_value?(object)
|
70
|
+
# value = false / null / true / object / array / number / string
|
71
|
+
# https://www.rfc-editor.org/rfc/rfc8259.txt
|
72
|
+
case object
|
73
|
+
when Hash, Array, Numeric, String, TrueClass, FalseClass, NilClass
|
74
|
+
true
|
75
|
+
else
|
76
|
+
false
|
77
|
+
end
|
78
|
+
end
|
67
79
|
end
|
68
80
|
|
69
81
|
# @api public
|
70
82
|
#
|
71
|
-
# Passes if actual string can be decoded as JSON and the decoded
|
72
|
-
# matcher. When a
|
73
|
-
# alias of the [`match`](http://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/match-matcher)
|
83
|
+
# Passes if actual string can be decoded as JSON and the decoded value passes the given
|
84
|
+
# matcher. When a JSON value is given, it's handled as `be_json matching(value)`
|
85
|
+
# (`matching` is an alias of the [`match`](http://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/match-matcher)
|
74
86
|
# matcher).
|
75
87
|
#
|
76
|
-
# @param
|
88
|
+
# @param
|
89
|
+
# matcher_or_json_value
|
90
|
+
# [#matches?, Hash, Array, Numeric, String, TrueClass, FalseClass, NilClass]
|
91
|
+
# a matcher object or a JSON value
|
77
92
|
#
|
78
93
|
# @example
|
79
94
|
# expect('{ "foo": 1, "bar": 2 }').to be_json(foo: 1, bar: 2)
|
@@ -81,14 +96,16 @@ module RSpec
|
|
81
96
|
# expect('{ "foo": 1, "bar": 2 }').to be_json matching(foo: 1, bar: 2)
|
82
97
|
# expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: 1)
|
83
98
|
# expect('{ "foo": 1, "bar": 2 }').to be_json a_kind_of(Hash)
|
84
|
-
def be_json(
|
85
|
-
if
|
86
|
-
|
99
|
+
def be_json(matcher_or_json_value)
|
100
|
+
if ComposableJSONMatchers.matcher?(matcher_or_json_value)
|
101
|
+
BeJSON.new(matcher_or_json_value, ComposableJSONMatchers.configuration)
|
102
|
+
elsif ComposableJSONMatchers.json_value?(matcher_or_json_value)
|
103
|
+
matcher = matching(matcher_or_json_value)
|
87
104
|
BeJSON.new(matcher, ComposableJSONMatchers.configuration)
|
88
|
-
elsif ComposableJSONMatchers.matcher?(matcher_or_structure)
|
89
|
-
BeJSON.new(matcher_or_structure, ComposableJSONMatchers.configuration)
|
90
105
|
else
|
91
|
-
raise ArgumentError, 'You must pass a matcher
|
106
|
+
raise ArgumentError, 'You must pass a matcher or a JSON value ' \
|
107
|
+
'(hash, array, numeric, string, true, false, or nil) ' \
|
108
|
+
'to `be_json` matcher.'
|
92
109
|
end
|
93
110
|
end
|
94
111
|
end
|
metadata
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-composable_json_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '3.0'
|
20
|
-
|
19
|
+
name: rspec
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '1.11'
|
34
|
-
|
33
|
+
name: bundler
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.11'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email:
|
43
43
|
- nkymyj@gmail.com
|
44
44
|
executables: []
|
@@ -64,7 +64,7 @@ homepage: https://github.com/yujinakayama/rspec-composable_json_matchers
|
|
64
64
|
licenses:
|
65
65
|
- MIT
|
66
66
|
metadata: {}
|
67
|
-
post_install_message:
|
67
|
+
post_install_message:
|
68
68
|
rdoc_options: []
|
69
69
|
require_paths:
|
70
70
|
- lib
|
@@ -79,11 +79,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
84
|
-
signing_key:
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.6.13
|
84
|
+
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: RSpec matchers for JSON strings with the power of built-in matchers and composable
|
87
87
|
matchers
|
88
88
|
test_files: []
|
89
|
-
has_rdoc:
|