rspec_match_structure 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +46 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +77 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/rspec_match_structure/version.rb +5 -0
- data/lib/rspec_match_structure.rb +81 -0
- data/lib/structure.rb +152 -0
- data/rspec_match_structure.gemspec +36 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6709f65f70b8cca91150e482fb321aab0386d6ccd366278dfc6bbf0e285cc14a
|
4
|
+
data.tar.gz: 00afb99ea29475957b602d4b28dff18f447d6c766da981117b0961d7e29cf41b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1f7b19820592a1bda44f5ded02f3f1f9f7bf276954426510b6ce23b5886622c409f5e3eef76334597211430f68c359a373f4c173246004d00df2df5b7ca36d6
|
7
|
+
data.tar.gz: 99ee1bae15f18dc187919e79f87ac87b4cd65b4e8030f644c48e98dcf70a38311b5456524d8637fb72c54b6eb5efef43e3c39e1446fe79d87180066226abfa2e
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
environment: production
|
14
|
+
permissions:
|
15
|
+
contents: read
|
16
|
+
packages: write
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- name: Set up Ruby 2.6
|
21
|
+
uses: actions/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: 2.6.x
|
24
|
+
|
25
|
+
- name: Publish to GPR
|
26
|
+
run: |
|
27
|
+
mkdir -p $HOME/.gem
|
28
|
+
touch $HOME/.gem/credentials
|
29
|
+
chmod 0600 $HOME/.gem/credentials
|
30
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
31
|
+
gem build *.gemspec
|
32
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
33
|
+
env:
|
34
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
35
|
+
OWNER: ${{ github.repository_owner }}
|
36
|
+
|
37
|
+
- name: Publish to RubyGems
|
38
|
+
run: |
|
39
|
+
mkdir -p $HOME/.gem
|
40
|
+
touch $HOME/.gem/credentials
|
41
|
+
chmod 0600 $HOME/.gem/credentials
|
42
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
43
|
+
gem build *.gemspec
|
44
|
+
gem push *.gem
|
45
|
+
env:
|
46
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.3.2] - 2022-05-16
|
4
|
+
|
5
|
+
- Bumped version
|
6
|
+
- Fixed workflow
|
7
|
+
|
8
|
+
## [0.3.1] - 2022-05-16
|
9
|
+
|
10
|
+
- Renamed gem
|
11
|
+
|
12
|
+
## [0.3.0] - 2022-05-13
|
13
|
+
|
14
|
+
- Added more test cases
|
15
|
+
- Added readme
|
16
|
+
|
17
|
+
## [0.2.0] - 2022-03-23
|
18
|
+
|
19
|
+
- Added more thorough testing
|
20
|
+
- Added a_list_with matcher
|
21
|
+
|
22
|
+
|
23
|
+
## [0.1.0] - 2022-03-22
|
24
|
+
|
25
|
+
- Initial release
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in rspec_match_structure.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.7"
|
13
|
+
|
14
|
+
gem "simplecov"
|
15
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec_match_structure (0.3.2)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (6.1.4.4)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.1.9)
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
docile (1.4.0)
|
20
|
+
i18n (1.8.11)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
minitest (5.15.0)
|
23
|
+
parallel (1.21.0)
|
24
|
+
parser (3.0.2.0)
|
25
|
+
ast (~> 2.4.1)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (13.0.6)
|
28
|
+
regexp_parser (2.1.1)
|
29
|
+
rexml (3.2.5)
|
30
|
+
rspec (3.10.0)
|
31
|
+
rspec-core (~> 3.10.0)
|
32
|
+
rspec-expectations (~> 3.10.0)
|
33
|
+
rspec-mocks (~> 3.10.0)
|
34
|
+
rspec-core (3.10.1)
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-expectations (3.10.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.10.0)
|
39
|
+
rspec-mocks (3.10.2)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-support (3.10.2)
|
43
|
+
rubocop (1.22.1)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 3.0.0.0)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8, < 3.0)
|
48
|
+
rexml
|
49
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
52
|
+
rubocop-ast (1.12.0)
|
53
|
+
parser (>= 3.0.1.1)
|
54
|
+
ruby-progressbar (1.11.0)
|
55
|
+
simplecov (0.21.2)
|
56
|
+
docile (~> 1.1)
|
57
|
+
simplecov-html (~> 0.11)
|
58
|
+
simplecov_json_formatter (~> 0.1)
|
59
|
+
simplecov-html (0.12.3)
|
60
|
+
simplecov_json_formatter (0.1.3)
|
61
|
+
tzinfo (2.0.4)
|
62
|
+
concurrent-ruby (~> 1.0)
|
63
|
+
unicode-display_width (2.1.0)
|
64
|
+
zeitwerk (2.5.1)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
x86_64-darwin-20
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
rake (~> 13.0)
|
71
|
+
rspec (~> 3.0)
|
72
|
+
rspec_match_structure!
|
73
|
+
rubocop (~> 1.7)
|
74
|
+
simplecov
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.2.19
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Fabrizio Mele
|
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,91 @@
|
|
1
|
+
# RSpec match_structure
|
2
|
+
|
3
|
+
[![Ruby Gem](https://github.com/monade/rspec_match_structure/actions/workflows/gem-push.yml/badge.svg)](https://github.com/monade/rspec_match_structure/actions/workflows/gem-push.yml)
|
4
|
+
|
5
|
+
Raise your expectations! RSpec match_structure is a gem that allows to test the structure of your string, hashes and lists.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'rspec_match_structure'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install rspec_match_structure
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
`match_strucure` can match various types of data and structures against schemas. A dead simple example of what it can do is:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
expect(["a", "b", "c"]).to match_structure(a_list_of(String).with(2).elements_at_least)
|
30
|
+
```
|
31
|
+
|
32
|
+
Another example:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
expect([
|
36
|
+
{
|
37
|
+
id: '1',
|
38
|
+
type: 'users'
|
39
|
+
},
|
40
|
+
{
|
41
|
+
id: '2',
|
42
|
+
type: 'users'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
id: '1',
|
46
|
+
type: 'posts'
|
47
|
+
}
|
48
|
+
]).to match_structure(a_list_with({ type: 'users' }).exactly(2).times)
|
49
|
+
```
|
50
|
+
|
51
|
+
It can also match string agains regular expressions:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
expect("abc").to match_structure( /abc/ )
|
55
|
+
```
|
56
|
+
|
57
|
+
This is especially useful when you want to test a JSON:API response:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
|
61
|
+
expect(response.body).to match_structure(
|
62
|
+
{
|
63
|
+
data: {
|
64
|
+
id: String,
|
65
|
+
type: 'someType',
|
66
|
+
attributes: {
|
67
|
+
anAttribute: String
|
68
|
+
}
|
69
|
+
},
|
70
|
+
included: [
|
71
|
+
a_list_with({ type: 'relatedType' }).exactly(1).times
|
72
|
+
]
|
73
|
+
}
|
74
|
+
)
|
75
|
+
```
|
76
|
+
|
77
|
+
To see all the various features please refer to the [spec file](https://github.com/monade/rspec_match_structure/blob/master/spec/rspec_match_structure_spec.rb).
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/monade/rspec_match_structure.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rspec_match_structure"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rspec_match_structure/version"
|
4
|
+
require 'active_support/core_ext/hash'
|
5
|
+
|
6
|
+
require_relative "structure"
|
7
|
+
|
8
|
+
include Structure::Type::Methods
|
9
|
+
|
10
|
+
RSpec::Matchers.define :match_structure do |structure|
|
11
|
+
match do |json|
|
12
|
+
@key = 'root'
|
13
|
+
begin
|
14
|
+
explore_structure(structure, json)
|
15
|
+
rescue Structure::Type::SizeError => e
|
16
|
+
@message = e.message
|
17
|
+
false
|
18
|
+
rescue Structure::Type::MatchError => e
|
19
|
+
@message = e.message
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def size_fail(structure, json)
|
25
|
+
raise Structure::Type::SizeError,
|
26
|
+
"Wrong size at #{@key}: #{json.size} != #{structure.size}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def structure_fail(structure, json)
|
30
|
+
raise Structure::Type::MatchError,
|
31
|
+
"Structure:\n#{structure.pretty_inspect}\nGiven:\n#{json.pretty_inspect}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def explore_structure(struc, json)
|
35
|
+
# example: 1 ~= Integer
|
36
|
+
if struc.is_a? Class
|
37
|
+
structure_fail(struc, json) unless json.is_a?(struc)
|
38
|
+
# example: "foobar" ~= /f[o]+bar/
|
39
|
+
elsif struc.is_a?(Regexp) && json.is_a?(String)
|
40
|
+
structure_fail(struc, json) unless json.match?(struc)
|
41
|
+
# example: [1, 2, 3] ~= a_list_of(Integer)
|
42
|
+
elsif struc.is_a? Structure::Type::Array
|
43
|
+
struc.matches?(json) { |j, s| explore_structure(j, s) }
|
44
|
+
# example: 1 ~= one_of(Integer, String)
|
45
|
+
elsif struc.is_a? Structure::Type::Single
|
46
|
+
struc.matches?(json) { |j, s| explore_structure(j, s) }
|
47
|
+
elsif struc.is_a? Structure::Type::ArrayWithStruct
|
48
|
+
struc.matches?(json) { |j, s| explore_structure(j, s) }
|
49
|
+
# example: {a: b, c: d} ~= {a: Integer, b: String}
|
50
|
+
elsif json.is_a?(Hash)
|
51
|
+
structure_fail(struc, json) unless struc.is_a? Hash
|
52
|
+
struc = struc.with_indifferent_access
|
53
|
+
json = json.with_indifferent_access
|
54
|
+
struc.all? do |k, v|
|
55
|
+
@key = k
|
56
|
+
structure_fail(struc, json) unless json.key?(k)
|
57
|
+
explore_structure(v, json[k])
|
58
|
+
end
|
59
|
+
# example: [1, 2, 3] ~= [1, 2, 3]
|
60
|
+
elsif json.is_a?(Array)
|
61
|
+
structure_fail(struc, json) unless struc.is_a? Array
|
62
|
+
size_fail(struc, json) if struc.size != json.size
|
63
|
+
return struc.zip(json).all? do |s, j|
|
64
|
+
@key = s
|
65
|
+
explore_structure(s, j)
|
66
|
+
end
|
67
|
+
# example: 3 ~= 3
|
68
|
+
else
|
69
|
+
structure_fail(struc, json) unless json == struc
|
70
|
+
end
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
failure_message do |json|
|
75
|
+
"#{json.pretty_inspect}\ndoes not match structure\n#{structure.pretty_inspect}\n\n#{@message}"
|
76
|
+
end
|
77
|
+
|
78
|
+
failure_message_when_negated do |json|
|
79
|
+
"#{json.pretty_inspect}\nis matching structure\n#{structure.pretty_inspect}"
|
80
|
+
end
|
81
|
+
end
|
data/lib/structure.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pp"
|
4
|
+
|
5
|
+
module Structure
|
6
|
+
module Type
|
7
|
+
class Error < ::StandardError; end
|
8
|
+
|
9
|
+
class SizeError < Error; end
|
10
|
+
|
11
|
+
class MatchError < Error; end
|
12
|
+
|
13
|
+
class Single
|
14
|
+
attr_reader :classes
|
15
|
+
|
16
|
+
def initialize(classes)
|
17
|
+
@classes = classes
|
18
|
+
end
|
19
|
+
|
20
|
+
def class?
|
21
|
+
@classes.all? { |c| c.is_a?(Class) || c.is_a?(Module) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def matches?(json)
|
25
|
+
result = classes.any? do |s|
|
26
|
+
yield s, json
|
27
|
+
rescue Structure::Type::Error
|
28
|
+
false
|
29
|
+
end
|
30
|
+
raise MatchError, "#{json}\n is not one of #{inspect}" unless result
|
31
|
+
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
"one_of(#{@classes})"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Array < Single
|
41
|
+
def initialize(classes)
|
42
|
+
super(classes)
|
43
|
+
@max = 999_999
|
44
|
+
@min = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def between(min, max)
|
48
|
+
@min = min
|
49
|
+
@max = max
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def at_least(number)
|
54
|
+
between(number, Float::INFINITY)
|
55
|
+
end
|
56
|
+
|
57
|
+
def with(number)
|
58
|
+
@number = number
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def elements
|
63
|
+
@min = @number
|
64
|
+
@max = @number
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
def items
|
69
|
+
elements
|
70
|
+
end
|
71
|
+
|
72
|
+
def elements_at_most
|
73
|
+
raise "Wrong use of at_most" unless @number
|
74
|
+
|
75
|
+
@max = @number
|
76
|
+
@number = nil
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def elements_at_least
|
81
|
+
raise "Wrong use of at_least" unless @number
|
82
|
+
|
83
|
+
@min = @number
|
84
|
+
@number = nil
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def matches?(json)
|
89
|
+
unless json.size.between?(
|
90
|
+
@min, @max
|
91
|
+
)
|
92
|
+
raise SizeError,
|
93
|
+
"Size Error: #{inspect} size (#{json.size}) is not between #{@min} and #{@max}."
|
94
|
+
end
|
95
|
+
|
96
|
+
json.all? { |j| classes.any? { |s| yield s, j } }
|
97
|
+
end
|
98
|
+
|
99
|
+
def inspect
|
100
|
+
if class?
|
101
|
+
"a_list_of(#{@classes.inspect})"
|
102
|
+
else
|
103
|
+
"a_list_of(\n#{@classes.pretty_inspect})"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class ArrayWithStruct < Array
|
109
|
+
attr_reader :min, :max, :struct
|
110
|
+
|
111
|
+
def initialize(struct)
|
112
|
+
super([])
|
113
|
+
@struct = struct
|
114
|
+
@max = 999_999
|
115
|
+
@min = 1
|
116
|
+
end
|
117
|
+
|
118
|
+
def exactly(number)
|
119
|
+
with(number)
|
120
|
+
end
|
121
|
+
|
122
|
+
def times
|
123
|
+
elements
|
124
|
+
end
|
125
|
+
|
126
|
+
def matches?(json)
|
127
|
+
result = json.count do |j|
|
128
|
+
yield @struct, j
|
129
|
+
rescue Structure::Type::Error
|
130
|
+
false
|
131
|
+
end
|
132
|
+
raise MatchError, "#{json}\n has no #{@struct}" unless result && result.between?(@min, @max)
|
133
|
+
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
module Methods
|
139
|
+
def a_list_of(*class_list)
|
140
|
+
Structure::Type::Array.new(class_list)
|
141
|
+
end
|
142
|
+
|
143
|
+
def one_of(*class_list)
|
144
|
+
Structure::Type::Single.new(class_list)
|
145
|
+
end
|
146
|
+
|
147
|
+
def a_list_with(struct)
|
148
|
+
Structure::Type::ArrayWithStruct.new(struct)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rspec_match_structure/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rspec_match_structure"
|
7
|
+
spec.version = RspecMatchStructure::VERSION
|
8
|
+
spec.authors = ["Mònade"]
|
9
|
+
spec.email = ["hello@monade.io"]
|
10
|
+
|
11
|
+
spec.summary = "An RSpec matcher to match json:api structures and lists"
|
12
|
+
spec.description = "An RSpec matcher to match json:api structures and lists."
|
13
|
+
spec.homepage = "https://github.com/monade/rspec_match_structure"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.5"
|
16
|
+
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/monade/rspec_match_structure/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_dependency "activesupport"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, checkout our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_match_structure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mònade
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: An RSpec matcher to match json:api structures and lists.
|
28
|
+
email:
|
29
|
+
- hello@monade.io
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/workflows/gem-push.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/rspec_match_structure.rb
|
47
|
+
- lib/rspec_match_structure/version.rb
|
48
|
+
- lib/structure.rb
|
49
|
+
- rspec_match_structure.gemspec
|
50
|
+
homepage: https://github.com/monade/rspec_match_structure
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/monade/rspec_match_structure
|
55
|
+
source_code_uri: https://github.com/monade/rspec_match_structure
|
56
|
+
changelog_uri: https://github.com/monade/rspec_match_structure/CHANGELOG.md
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.5'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.0.3.1
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: An RSpec matcher to match json:api structures and lists
|
76
|
+
test_files: []
|