rspec-composable_json_matchers 1.0.2 → 1.1.0

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
- SHA1:
3
- metadata.gz: 08d899242d84fd31e688747290d9540e8251bced
4
- data.tar.gz: 06de1d9e179efdd21cc1e11188517aed77d533ce
2
+ SHA256:
3
+ metadata.gz: 60aedac8bfa4be5a25ee02f5690bc668fa0877ac5694d25dcfd49e51b1f5959d
4
+ data.tar.gz: b75aa47517e390d769bf6bb85774fe16700572b3f481cf9f2f0b0d28477a08ba
5
5
  SHA512:
6
- metadata.gz: a34fa9de5b8b11ef7d585a2e033dcea41663949321a2d892f0853dea773bd5bd98bd6336e5d26284f60bcb55a931d5142f7d8d9e6e011e743a2f07998ea6b998
7
- data.tar.gz: a07c467c87f20fcf5c3e219d1a65e5c593cc24ef6a5fd8b34336b8725c1839fef31083387db714b9e5a6b6d343dd5b0a5b79f9605284d7d32d69e04bf69d7667
6
+ metadata.gz: 50c03bfe28eb3e07fc14340429a4d6d69d080373b857043d36df06ee548ce671e3ecb228e5c70e992491d417a4bbcc541078f76b4ae680478c2f5c0f5e286f3d
7
+ data.tar.gz: 567b30332befa7757725ca1940edfbc0cb4198b995204d27f8a080e22d7e4743aafa5dce19f760fdcc9ffdaa9cd14412ecaf42da41262d596514ba1672308fb2
data/.rubocop.yml CHANGED
@@ -2,6 +2,10 @@ Lint/HandleExceptions:
2
2
  Exclude:
3
3
  - 'spec/**/*'
4
4
 
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*'
8
+
5
9
  Metrics/LineLength:
6
10
  Max: 100
7
11
 
data/.travis.yml CHANGED
@@ -1,12 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.7
5
- - 2.2.4
6
- - 2.3.0
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', '~> 10.0'
8
- gem 'rubocop', '~> 0.37'
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rubocop', '~> 0.51'
9
9
  gem 'simplecov', '~> 0.11'
10
- gem 'yard', '~> 0.8'
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
- [![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)
1
+ [![Gem Version](https://badge.fury.io/rb/rspec-composable_json_matchers.svg)](http://badge.fury.io/rb/rspec-composable_json_matchers)
3
2
  [![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)
3
+ [![Coverage Status](https://coveralls.io/repos/yujinakayama/rspec-composable_json_matchers/badge.svg?branch=master&service=github)](https://coveralls.io/github/yujinakayama/rspec-composable_json_matchers?branch=master)
4
+ [![Code Climate](https://codeclimate.com/github/yujinakayama/rspec-composable_json_matchers/badges/gpa.svg)](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, a hash, or an array.
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 structure passes the given matcher:
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 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
+ 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 always a hash or an array, you may want to use any of the following built-in matchers.
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 `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
+ 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 supporting a hash or an array can also be used.
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
@@ -8,5 +8,5 @@ end
8
8
 
9
9
  RuboCop::RakeTask.new
10
10
 
11
- task default: [:spec, :rubocop]
12
- task ci: [:spec, :rubocop]
11
+ task default: %i[spec rubocop]
12
+ task ci: %i[spec rubocop]
@@ -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 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)
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 matcher_or_structure [#matches?, Hash, Array] a matcher object, a hash, or an array
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(matcher_or_structure)
85
- if Hash === matcher_or_structure || Array === matcher_or_structure
86
- matcher = matching(matcher_or_structure)
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, a hash, or an array to `be_json` 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
@@ -3,8 +3,8 @@ module RSpec
3
3
  # @api public
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 0
7
- PATCH = 2
6
+ MINOR = 1
7
+ PATCH = 0
8
8
 
9
9
  def self.to_s
10
10
  [MAJOR, MINOR, PATCH].join('.')
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'rspec/composable_json_matchers/version'
5
4
 
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.2
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: 2016-03-17 00:00:00.000000000 Z
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
- type: :runtime
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
- type: :development
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.5.1
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: