rspec-composable_json_matchers 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +12 -0
- data/.yardopts +2 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +217 -0
- data/Rakefile +12 -0
- data/lib/rspec/composable_json_matchers.rb +95 -0
- data/lib/rspec/composable_json_matchers/be_json.rb +65 -0
- data/lib/rspec/composable_json_matchers/configuration.rb +39 -0
- data/lib/rspec/composable_json_matchers/setup.rb +2 -0
- data/lib/rspec/composable_json_matchers/version.rb +14 -0
- data/rspec-composable_json_matchers.gemspec +25 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac347d740dd20583329e5908285b186dd61aa27a
|
4
|
+
data.tar.gz: a9a956bdd23674f1c7af6ccede8717485709aeda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 256ba8db6ac26b919e719a429044cc2099766f48206a90868dd14f2de56c36aa4cd226b01c3a6daceb993eca4f69d6bf64981fabb704189561fa83266e8394c1
|
7
|
+
data.tar.gz: b7a583703a4004e7b92a1ea93c9bf85c2dbc501769875586a8d96f012c18b11d5db7e30d11e4e70bd2eaac528fbe45bc8b86386af3d0559ea8dcfd41fd510a93
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem 'coderay', '~> 1.1'
|
7
|
+
gem 'rake', '~> 10.0'
|
8
|
+
gem 'rubocop', '~> 0.37'
|
9
|
+
gem 'simplecov', '~> 0.11'
|
10
|
+
gem 'yard', '~> 0.8'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'coveralls', '~> 0.8'
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Yuji Nakayama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
[![Gem Version](http://img.shields.io/gem/v/rspec-composable_json_matchers.svg?style=flat)](http://badge.fury.io/rb/rspec-composable_json_matchers)
|
2
|
+
[![Dependency Status](http://img.shields.io/gemnasium/yujinakayama/rspec-composable_json_matchers.svg?style=flat)](https://gemnasium.com/yujinakayama/rspec-composable_json_matchers)
|
3
|
+
[![Build Status](https://travis-ci.org/yujinakayama/rspec-composable_json_matchers.svg?branch=master&style=flat)](https://travis-ci.org/yujinakayama/rspec-composable_json_matchers)
|
4
|
+
[![Coverage Status](http://img.shields.io/coveralls/yujinakayama/rspec-composable_json_matchers/master.svg?style=flat)](https://coveralls.io/r/yujinakayama/rspec-composable_json_matchers)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/yujinakayama/rspec-composable_json_matchers.svg?style=flat)](https://codeclimate.com/github/yujinakayama/rspec-composable_json_matchers)
|
6
|
+
|
7
|
+
# RSpec::ComposableJSONMatchers
|
8
|
+
|
9
|
+
**RSpec::ComposableJSONMatchers** provides `be_json` matcher,
|
10
|
+
which lets you express expected structures on JSON strings
|
11
|
+
with the power of RSpec's
|
12
|
+
[built-in matchers](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers)
|
13
|
+
and
|
14
|
+
[composable matchers](https://relishapp.com/rspec/rspec-expectations/docs/composing-matchers).
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
json = '{ "foo": 1, "bar": 2 }'
|
18
|
+
expect(json).to be_json a_kind_of(Hash)
|
19
|
+
expect(json).to be_json matching(foo: 1, bar: a_kind_of(Integer))
|
20
|
+
expect(json).to be_json including(foo: 1)
|
21
|
+
```
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
### Adding `rspec-composable_json_matchers` dependency
|
26
|
+
|
27
|
+
Add this line to your `Gemfile`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'rspec-composable_json_matchers'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then run:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
$ bundle install
|
37
|
+
```
|
38
|
+
|
39
|
+
### Enabling `be_json` matcher
|
40
|
+
|
41
|
+
To make the `be_json` matcher available in every example,
|
42
|
+
add the following line to your `spec/spec_helper.rb`:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# spec/spec_helper.rb
|
46
|
+
require 'rspec/composable_json_matchers/setup'
|
47
|
+
```
|
48
|
+
|
49
|
+
Or if you prefer more explicit way, add the following snippet:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# spec/spec_helper.rb
|
53
|
+
require 'rspec/composable_json_matchers'
|
54
|
+
|
55
|
+
RSpec.configure do |config|
|
56
|
+
include RSpec::ComposableJSONMatchers
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
If you want to enable the `be_json` matcher only specific examples rather than every example,
|
61
|
+
include the `RSpec::ComposableJSONMatchers` in the example groups:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# spec/something_spec.rb
|
65
|
+
require 'rspec/composable_json_matchers'
|
66
|
+
|
67
|
+
describe 'something' do
|
68
|
+
include RSpec::ComposableJSONMatchers
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Usage
|
73
|
+
|
74
|
+
The `be_json` matcher takes another matcher, a hash, or an array.
|
75
|
+
|
76
|
+
When a matcher is given,
|
77
|
+
it passes if actual string can be decoded as JSON and the decoded structure passes the given matcher:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json a_kind_of(Hash)
|
81
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json matching(foo: 1, bar: 2)
|
82
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: 1)
|
83
|
+
|
84
|
+
expect('["foo", "bar"]').to be_json a_kind_of(Array)
|
85
|
+
expect('["foo", "bar"]').to be_json matching(['foo', 'bar'])
|
86
|
+
expect('["foo", "bar"]').to be_json including('foo')
|
87
|
+
```
|
88
|
+
|
89
|
+
When a hash or an array is given,
|
90
|
+
it's handled as `be_json matching(hash_or_array)` (`matching` is an alias of the `match` matcher):
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# Equivalents
|
94
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json(foo: 1, bar: 2)
|
95
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json matching(foo: 1, bar: 2)
|
96
|
+
```
|
97
|
+
|
98
|
+
You can compose matchers via given matchers:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json matching(
|
102
|
+
foo: a_kind_of(Integer),
|
103
|
+
bar: a_kind_of(Integer)
|
104
|
+
)
|
105
|
+
|
106
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: a_kind_of(Integer))
|
107
|
+
```
|
108
|
+
|
109
|
+
For more practical example, see
|
110
|
+
[`spec/example_spec.rb`](https://github.com/yujinakayama/rspec-composable_json_matchers/blob/master/spec/example_spec.rb)
|
111
|
+
for the [GitHub Meta API](https://developer.github.com/v3/meta/).
|
112
|
+
|
113
|
+
## Combinations with built-in matchers
|
114
|
+
|
115
|
+
Since decoded JSON is always a hash or an array, you may want to use any of the following built-in matchers.
|
116
|
+
|
117
|
+
Note that you can always use the `matching` matcher (internally uses `#===`)
|
118
|
+
instead of the `eq_to` matcher (internally uses `#==`),
|
119
|
+
because there's no objects that are parsed from JSON and behave differently between `#==` and `#===`.
|
120
|
+
|
121
|
+
Of course, any other custom matchers supporting a hash or an array can also be used.
|
122
|
+
|
123
|
+
### `matching`
|
124
|
+
|
125
|
+
* Alias of [`match`](https://relishapp.com/rspec/rspec-expectations/docs/composing-matchers#composing-matchers-with-`match`:) matcher
|
126
|
+
* Supported structure: Hash and Array
|
127
|
+
* Accepts matchers as arguments: Yes
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json matching(foo: 1, bar: a_kind_of(Integer))
|
131
|
+
expect('["foo", "bar"]').to be_json matching(['foo', a_string_starting_with('b')])
|
132
|
+
```
|
133
|
+
|
134
|
+
### `including`
|
135
|
+
|
136
|
+
* Alias of [`include`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/include-matcher#hash-usage) matcher
|
137
|
+
* Supported structure: Hash and Array
|
138
|
+
* Accepts matchers as arguments: Yes
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: 1)
|
142
|
+
expect('["foo", "bar"]').to be_json including('foo')
|
143
|
+
```
|
144
|
+
|
145
|
+
### `all`
|
146
|
+
|
147
|
+
* [`all`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/all-matcher) matcher
|
148
|
+
* Supported structure: Array
|
149
|
+
* Accepts matchers as arguments: Yes
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
expect('["foo", "bar"]').to be_json all be_a(String)
|
153
|
+
```
|
154
|
+
|
155
|
+
### `containing_exactly`
|
156
|
+
|
157
|
+
* Alias of [`contain_exactly`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/contain-exactly-matcher) matcher
|
158
|
+
* Supported structure: Array
|
159
|
+
* Accepts matchers as arguments: Yes
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
expect('["foo", "bar"]').to be_json containing_exactly('bar', 'foo')
|
163
|
+
```
|
164
|
+
|
165
|
+
### `starting_with`
|
166
|
+
|
167
|
+
* Alias of [`start_with`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/start-with-matcher) matcher
|
168
|
+
* Supported structure: Array
|
169
|
+
* Accepts matchers as arguments: Yes
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
expect('["foo", "bar"]').to be_json starting_with('foo')
|
173
|
+
```
|
174
|
+
|
175
|
+
### `ending_with`
|
176
|
+
|
177
|
+
* Alias of [`end_with`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/end-with-matcher) matcher
|
178
|
+
* Supported structure: Array
|
179
|
+
* Accepts matchers as arguments: Yes
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
expect('["foo", "bar"]').to be_json ending_with('bar')
|
183
|
+
```
|
184
|
+
|
185
|
+
### `a_kind_of`
|
186
|
+
|
187
|
+
* Alias of [`be_a_kind_of`](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/type-matchers#be-(a-)kind-of-matcher) matcher
|
188
|
+
* Supported structure: Hash and Array
|
189
|
+
* Accepts matchers as arguments: No
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
expect('{}').to be_json a_kind_of(Hash)
|
193
|
+
expect('[]').to be_json a_kind_of(Array)
|
194
|
+
```
|
195
|
+
|
196
|
+
## Configuration
|
197
|
+
|
198
|
+
The `be_json` matcher internally uses
|
199
|
+
[`JSON.parse`](http://ruby-doc.org/stdlib-2.3.0/libdoc/json/rdoc/JSON.html#method-i-parse)
|
200
|
+
to decode JSON strings.
|
201
|
+
The default parser options used in the `be_json` matcher is `{ symbolize_names: true }`,
|
202
|
+
so you need to pass _a hash with symbol keys_ as an expected structure.
|
203
|
+
|
204
|
+
If you prefer string keys, add the following snippet to your `spec/spec_helper.rb`:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
# spec/spec_helper.rb
|
208
|
+
RSpec::ComposableJSONMatchers.configure do |config|
|
209
|
+
config.parser_options = { symbolize_names: false }
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
## License
|
214
|
+
|
215
|
+
Copyright (c) 2016 Yuji Nakayama
|
216
|
+
|
217
|
+
See the [LICENSE.txt](LICENSE.txt) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'rspec/composable_json_matchers/be_json'
|
2
|
+
require 'rspec/composable_json_matchers/configuration'
|
3
|
+
require 'rspec/composable_json_matchers/version'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
# Mix-in module for the `be_json` matcher.
|
7
|
+
#
|
8
|
+
# @example Make `be_json` matcher available everywhere
|
9
|
+
# # spec/spec_helper.rb
|
10
|
+
# require 'rspec/composable_json_matchers'
|
11
|
+
# RSpec.configure do |config|
|
12
|
+
# include RSpec::ComposableJSONMatchers
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# @example Make `be_json` matcher available only in specific example groups
|
16
|
+
# require 'rspec/composable_json_matchers'
|
17
|
+
# describe 'something' do
|
18
|
+
# include RSpec::ComposableJSONMatchers
|
19
|
+
# end
|
20
|
+
module ComposableJSONMatchers
|
21
|
+
class << self
|
22
|
+
# @api public
|
23
|
+
#
|
24
|
+
# Returns the current configuration.
|
25
|
+
#
|
26
|
+
# @return [RSpec::ComposableJSONMatchers::Configuration] the current configuration
|
27
|
+
#
|
28
|
+
# @see .configure
|
29
|
+
def configuration
|
30
|
+
@configuration ||= Configuration.new
|
31
|
+
end
|
32
|
+
|
33
|
+
# @api public
|
34
|
+
#
|
35
|
+
# Provides a block for configuring RSpec::ComposableJSONMatchers.
|
36
|
+
#
|
37
|
+
# @yieldparam config [RSpec::ComposableJSONMatchers::Configuration] the current configuration
|
38
|
+
#
|
39
|
+
# @return [void]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# # spec/spec_helper.rb
|
43
|
+
# RSpec::ComposableJSONMatchers.configure do |config|
|
44
|
+
# config.parser_options = { symbolize_names: false }
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# @see .configuration
|
48
|
+
def configure
|
49
|
+
yield configuration
|
50
|
+
end
|
51
|
+
|
52
|
+
# @api private
|
53
|
+
def reset!
|
54
|
+
@configuration = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# @api private
|
58
|
+
def matcher?(object)
|
59
|
+
begin
|
60
|
+
return false if object.respond_to?(:i_respond_to_everything_so_im_not_really_a_matcher)
|
61
|
+
rescue NoMethodError
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
|
65
|
+
object.respond_to?(:matches?)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @api public
|
70
|
+
#
|
71
|
+
# Passes if actual string can be decoded as JSON and the decoded structure passes the given
|
72
|
+
# matcher. When a hash is given, it's handled as `be_json matching(hash)` (`matching` is an
|
73
|
+
# alias of the [`match`](http://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/match-matcher)
|
74
|
+
# matcher).
|
75
|
+
#
|
76
|
+
# @param matcher_or_structure [#matches?, Hash, Array] a matcher object, a hash, or an array
|
77
|
+
#
|
78
|
+
# @example
|
79
|
+
# expect('{ "foo": 1, "bar": 2 }').to be_json(foo: 1, bar: 2)
|
80
|
+
# expect('{ "foo": 1, "bar": 2 }').to be_json(foo: 1, bar: a_kind_of(Integer))
|
81
|
+
# expect('{ "foo": 1, "bar": 2 }').to be_json matching(foo: 1, bar: 2)
|
82
|
+
# expect('{ "foo": 1, "bar": 2 }').to be_json including(foo: 1)
|
83
|
+
# expect('{ "foo": 1, "bar": 2 }').to be_json a_kind_of(Hash)
|
84
|
+
def be_json(matcher_or_structure)
|
85
|
+
if Hash === matcher_or_structure || Array === matcher_or_structure
|
86
|
+
matcher = matching(matcher_or_structure)
|
87
|
+
BeJSON.new(matcher, ComposableJSONMatchers.configuration)
|
88
|
+
elsif ComposableJSONMatchers.matcher?(matcher_or_structure)
|
89
|
+
BeJSON.new(matcher_or_structure, ComposableJSONMatchers.configuration)
|
90
|
+
else
|
91
|
+
raise ArgumentError, 'You must pass a matcher, a hash, or an array to `be_json` matcher.'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module RSpec
|
2
|
+
module ComposableJSONMatchers
|
3
|
+
# @api private
|
4
|
+
class BeJSON
|
5
|
+
include RSpec::Matchers::Composable
|
6
|
+
|
7
|
+
attr_reader :matcher, :configuration, :original_actual, :decoded_actual, :parser_error
|
8
|
+
|
9
|
+
def initialize(matcher, configuration)
|
10
|
+
@matcher = matcher
|
11
|
+
@configuration = configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def matches?(actual)
|
15
|
+
@original_actual = actual
|
16
|
+
@decoded_actual = parse(original_actual)
|
17
|
+
matcher.matches?(decoded_actual)
|
18
|
+
rescue JSON::ParserError => error
|
19
|
+
@parser_error = error
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def does_not_match?(actual)
|
24
|
+
matched = matches?(actual)
|
25
|
+
parser_error ? false : !matched
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
"be JSON #{matcher.description}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message
|
33
|
+
return parser_failure_message if parser_failure_message
|
34
|
+
"expected #{original_actual} to be JSON #{matcher.description}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure_message_when_negated
|
38
|
+
return parser_failure_message if parser_failure_message
|
39
|
+
"expected #{original_actual} not to be JSON #{matcher.description}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def diffable?
|
43
|
+
parser_error.nil? && matcher.diffable?
|
44
|
+
end
|
45
|
+
|
46
|
+
def expected
|
47
|
+
matcher.expected
|
48
|
+
end
|
49
|
+
|
50
|
+
alias actual decoded_actual
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def parse(json)
|
55
|
+
require 'json'
|
56
|
+
JSON.parse(json, configuration.parser_options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def parser_failure_message
|
60
|
+
return nil unless parser_error
|
61
|
+
"cannot parse #{original_actual.inspect} as JSON: #{parser_error.message}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RSpec
|
2
|
+
module ComposableJSONMatchers
|
3
|
+
class Configuration
|
4
|
+
# @api public
|
5
|
+
#
|
6
|
+
# The default value of .parser_options.
|
7
|
+
#
|
8
|
+
# @see #parser_options
|
9
|
+
DEFAULT_PARSER_OPTIONS = { symbolize_names: true }.freeze
|
10
|
+
|
11
|
+
# @api public
|
12
|
+
#
|
13
|
+
# Returns the current options for JSON.parse used in the `be_json` matcher.
|
14
|
+
#
|
15
|
+
# @return [Hash] the current options for JSON.parse.
|
16
|
+
#
|
17
|
+
# @see #parser_options=
|
18
|
+
# @see http://ruby-doc.org/stdlib-2.3.0/libdoc/json/rdoc/JSON.html#method-i-parse
|
19
|
+
def parser_options
|
20
|
+
@parser_options ||= DEFAULT_PARSER_OPTIONS
|
21
|
+
end
|
22
|
+
|
23
|
+
# @api public
|
24
|
+
#
|
25
|
+
# Set the given hash as the option for JSON.parse used in the `be_json` matcher.
|
26
|
+
#
|
27
|
+
# @param hash [Hash] an option for JSON.parse
|
28
|
+
#
|
29
|
+
# @return [void]
|
30
|
+
#
|
31
|
+
# @see #parser_options
|
32
|
+
# @see http://ruby-doc.org/stdlib-2.3.0/libdoc/json/rdoc/JSON.html#method-i-parse
|
33
|
+
def parser_options=(hash)
|
34
|
+
raise ArgumentError, 'You must pass a hash to `parser_options=`.' unless hash.is_a?(Hash)
|
35
|
+
@parser_options = hash
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/composable_json_matchers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-composable_json_matchers'
|
8
|
+
spec.version = RSpec::ComposableJSONMatchers::Version.to_s
|
9
|
+
spec.authors = ['Yuji Nakayama']
|
10
|
+
spec.email = ['nkymyj@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'RSpec matchers for JSON strings with the power of ' \
|
13
|
+
'built-in matchers and composable matchers'
|
14
|
+
spec.homepage = 'https://github.com/yujinakayama/rspec-composable_json_matchers'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'rspec', '~> 3.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-composable_json_matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuji Nakayama
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- nkymyj@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".travis.yml"
|
52
|
+
- ".yardopts"
|
53
|
+
- Gemfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/rspec/composable_json_matchers.rb
|
58
|
+
- lib/rspec/composable_json_matchers/be_json.rb
|
59
|
+
- lib/rspec/composable_json_matchers/configuration.rb
|
60
|
+
- lib/rspec/composable_json_matchers/setup.rb
|
61
|
+
- lib/rspec/composable_json_matchers/version.rb
|
62
|
+
- rspec-composable_json_matchers.gemspec
|
63
|
+
homepage: https://github.com/yujinakayama/rspec-composable_json_matchers
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: RSpec matchers for JSON strings with the power of built-in matchers and composable
|
87
|
+
matchers
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|