rspec-paramz 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 +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +223 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspec/paramz.rb +70 -0
- data/lib/rspec/paramz/named_proc.rb +16 -0
- data/lib/rspec/paramz/pretty_print.rb +52 -0
- data/lib/rspec/paramz/syntax.rb +12 -0
- data/lib/rspec/paramz/version.rb +5 -0
- data/rspec-paramz.gemspec +35 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 974cf77b3ed42146c25af78805d1e2e87fc8b666ef743830b0d5de4d792f35fb
|
4
|
+
data.tar.gz: cc1ffbcb73711c259e537c7466c55a66561f92cc66201bf4d7134e609f8817b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a66d490cd774db29223ca2dd1121e2e76522807333b6847e55f7fa3f7629aa54926cb484dddada7bd8dd629c97b8e1638247c9e212ba368e8bf4e35719f3e47
|
7
|
+
data.tar.gz: 27471467415c6cd6d21aa1418721e31089c7a9ccf15ae514f71873ccf947798e3e9dcd6b26816fed9d5635cb34f0b3a2d4c6646f98f2bba1b23a1889d76de3ea
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at fukayatsu@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-paramz (0.1.0)
|
5
|
+
rspec (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
jaro_winkler (1.5.3)
|
14
|
+
method_source (0.9.2)
|
15
|
+
onkcop (0.53.0.3)
|
16
|
+
rubocop (>= 0.53.0)
|
17
|
+
rubocop-rspec (>= 1.24.0)
|
18
|
+
parallel (1.17.0)
|
19
|
+
parser (2.6.3.0)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
pry (0.12.2)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.9.0)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
rspec (3.8.0)
|
27
|
+
rspec-core (~> 3.8.0)
|
28
|
+
rspec-expectations (~> 3.8.0)
|
29
|
+
rspec-mocks (~> 3.8.0)
|
30
|
+
rspec-core (3.8.2)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-expectations (3.8.4)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-mocks (3.8.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-support (3.8.2)
|
39
|
+
rubocop (0.72.0)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.6)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
46
|
+
rubocop-rspec (1.33.0)
|
47
|
+
rubocop (>= 0.60.0)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
unicode-display_width (1.6.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
bundler (~> 2.0)
|
56
|
+
onkcop
|
57
|
+
pry
|
58
|
+
rake (~> 10.0)
|
59
|
+
rspec-paramz!
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Atsuo Fukaya
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 fukayatsu
|
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,223 @@
|
|
1
|
+
# RSpec::Paramz [![Build Status](https://travis-ci.org/fukayatsu/rspec-paramz.svg?branch=master)](https://travis-ci.org/fukayatsu/rspec-paramz)
|
2
|
+
|
3
|
+
Simple Parameterized Test for RSpec.
|
4
|
+
|
5
|
+
Inspired by [tomykaira/rspec-parameterized](https://github.com/tomykaira/rspec-parameterized).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-paramz'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-paramz
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
See [paramz_spec.rb](https://github.com/fukayatsu/rspec-paramz/blob/master/spec/rspec/paramz_spec.rb) for example.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
RSpec.describe RSpec::Paramz do
|
29
|
+
describe '#paramz' do
|
30
|
+
context 'format 1' do
|
31
|
+
paramz(
|
32
|
+
[:a, :b, :answer],
|
33
|
+
1, 2, 3,
|
34
|
+
3, 8, 11,
|
35
|
+
5, -8, -3,
|
36
|
+
) do
|
37
|
+
it 'should do additions' do
|
38
|
+
expect(a + b).to eq answer
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#=>
|
43
|
+
# [a = 1 | b = 2 | answer = 3]
|
44
|
+
# should do additions
|
45
|
+
# [a = 3 | b = 8 | answer = 11]
|
46
|
+
# should do additions
|
47
|
+
# [a = 5 | b = -8 | answer = -3]
|
48
|
+
# should do additions
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'format 2' do
|
52
|
+
paramz(
|
53
|
+
[:a, :b, subject: -> { a + b }],
|
54
|
+
1, 2, 3,
|
55
|
+
3, 8, 11,
|
56
|
+
5, -8, -3,
|
57
|
+
)
|
58
|
+
|
59
|
+
#=>
|
60
|
+
# [a = 1 | b = 2 | subject { a + b } = 3]
|
61
|
+
# should == 3
|
62
|
+
# [a = 3 | b = 8 | subject { a + b } = 11]
|
63
|
+
# should == 11
|
64
|
+
# [a = 5 | b = -8 | subject { a + b } = -3]
|
65
|
+
# should == -3
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'format 2-a' do
|
69
|
+
paramz(
|
70
|
+
[:a, :b, subject: -> { a + b }],
|
71
|
+
1, 2, 3,
|
72
|
+
3, 8, 11,
|
73
|
+
5, -8, -3,
|
74
|
+
) do
|
75
|
+
it 'should do additions' do
|
76
|
+
expect(subject).to eq(a + b)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
#=>
|
81
|
+
# [a = 1 | b = 2 | subject { a + b } = 3]
|
82
|
+
# should do additions
|
83
|
+
# [a = 3 | b = 8 | subject { a + b } = 11]
|
84
|
+
# should do additions
|
85
|
+
# [a = 5 | b = -8 | subject { a + b } = -3]
|
86
|
+
# should do additions
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'format 3' do
|
90
|
+
paramz(
|
91
|
+
[:a, :b, subject: { answer: -> { a + b } }],
|
92
|
+
1, 2, 3,
|
93
|
+
3, 8, 11,
|
94
|
+
5, -8, -3,
|
95
|
+
)
|
96
|
+
|
97
|
+
#=>
|
98
|
+
# [a = 1 | b = 2 | subject(:answer) { a + b } = 3]
|
99
|
+
# should == 3
|
100
|
+
# [a = 3 | b = 8 | subject(:answer) { a + b } = 11]
|
101
|
+
# should == 11
|
102
|
+
# [a = 5 | b = -8 | subject(:answer) { a + b } = -3]
|
103
|
+
# should == -3
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'format 3-b' do
|
107
|
+
paramz(
|
108
|
+
[:a, :b, subject: { answer: -> { a + b } }],
|
109
|
+
1, 2, 3,
|
110
|
+
3, 8, 11,
|
111
|
+
5, -8, -3,
|
112
|
+
) do
|
113
|
+
it 'should do additions' do
|
114
|
+
expect(subject).to eq(a + b)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should do additions' do
|
118
|
+
expect(answer).to eq(a + b)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
#=>
|
123
|
+
# [a = 1 | b = 2 | subject(:answer) { a + b } = 3]
|
124
|
+
# should do additions
|
125
|
+
# should do additions
|
126
|
+
# [a = 3 | b = 8 | subject(:answer) { a + b } = 11]
|
127
|
+
# should do additions
|
128
|
+
# should do additions
|
129
|
+
# [a = 5 | b = -8 | subject(:answer) { a + b } = -3]
|
130
|
+
# should do additions
|
131
|
+
# should do additions
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'rspec-let' do
|
135
|
+
let(:one) { 1 }
|
136
|
+
let(:two) { one * 2 }
|
137
|
+
let(:three) { one * 3 }
|
138
|
+
|
139
|
+
context 'default' do
|
140
|
+
paramz(
|
141
|
+
[:a, :b, :answer],
|
142
|
+
-> { one }, 0, 1,
|
143
|
+
-> { one }, -> { one }, -> { 2 },
|
144
|
+
-> { one }, -> { two }, -> { three },
|
145
|
+
) do
|
146
|
+
it 'should do additions' do
|
147
|
+
expect(a + b).to eq answer
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
#=>
|
152
|
+
# [a = { one } | b = 0 | answer = 1]
|
153
|
+
# should do additions
|
154
|
+
# [a = { one } | b = { one } | answer = { 2 }]
|
155
|
+
# should do additions
|
156
|
+
# [a = { one } | b = { two } | answer = { three }]
|
157
|
+
# should do additions
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'using RSpec::Paramz::Syntax' do
|
161
|
+
using RSpec::Paramz::Syntax
|
162
|
+
paramz(
|
163
|
+
[:a, :b, :answer],
|
164
|
+
:one.&, 0, 1,
|
165
|
+
:one.&, :one.&, -> { 2 },
|
166
|
+
:one.&, :two.&, :three.&,
|
167
|
+
) do
|
168
|
+
it 'should do additions' do
|
169
|
+
expect(a + b).to eq answer
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
#=>
|
174
|
+
# [a = { one } | b = 0 | answer = 1]
|
175
|
+
# should do additions
|
176
|
+
# [a = { one } | b = { one } | answer = { 2 }]
|
177
|
+
# should do additions
|
178
|
+
# [a = { one } | b = { two } | answer = { three }]
|
179
|
+
# should do additions
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'nil or empty' do
|
184
|
+
paramz(
|
185
|
+
[:a, :b, :answer],
|
186
|
+
"foo", nil, "foo",
|
187
|
+
"", nil, "",
|
188
|
+
nil, "bar", nil
|
189
|
+
) do
|
190
|
+
it 'should do additions' do
|
191
|
+
expect(a&.to_s).to eq answer
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
#=>
|
196
|
+
# [a = "foo" | b = nil | answer = "foo"]
|
197
|
+
# should do additions
|
198
|
+
# [a = "" | b = nil | answer = ""]
|
199
|
+
# should do additions
|
200
|
+
# [a = nil | b = "bar" | answer = nil]
|
201
|
+
# should do additions
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
```
|
206
|
+
|
207
|
+
## Development
|
208
|
+
|
209
|
+
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.
|
210
|
+
|
211
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
212
|
+
|
213
|
+
## Contributing
|
214
|
+
|
215
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fukayatsu/rspec-paramz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
216
|
+
|
217
|
+
## License
|
218
|
+
|
219
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
220
|
+
|
221
|
+
## Code of Conduct
|
222
|
+
|
223
|
+
Everyone interacting in the RSpec::Paramz project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fukayatsu/rspec-paramz/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/paramz"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/rspec/paramz.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "rspec/paramz/version"
|
2
|
+
require "rspec/paramz/syntax"
|
3
|
+
require "rspec/paramz/named_proc"
|
4
|
+
require "rspec/paramz/pretty_print"
|
5
|
+
|
6
|
+
module RSpec
|
7
|
+
module Paramz
|
8
|
+
module ExampleGroupMethods
|
9
|
+
def paramz(*args, &block)
|
10
|
+
labels = args.first
|
11
|
+
|
12
|
+
if !block_given? && !labels.any? { |label| subject_label?(label) }
|
13
|
+
raise ArgumentError, "No block or subject given to paramz."
|
14
|
+
end
|
15
|
+
|
16
|
+
args[1..-1].each_slice(labels.length).with_index do |arg, index|
|
17
|
+
pairs = [labels, arg].transpose.to_h
|
18
|
+
|
19
|
+
context_name = '[' + pairs.map { |k, v| "#{RSpec::Paramz::PrettyPrint.inspect(k)} = #{RSpec::Paramz::PrettyPrint.inspect(v, false)}" }.join(' | ') + ']'
|
20
|
+
|
21
|
+
context context_name do
|
22
|
+
pairs.each do |label, val|
|
23
|
+
if subject_label?(label)
|
24
|
+
_subject, _subject_name = parse_subject(label)
|
25
|
+
|
26
|
+
module_exec { _subject.is_a?(Proc) ? subject(_subject_name, &_subject) : subject(_subject_name) { _subject } }
|
27
|
+
it { should == val } unless block_given?
|
28
|
+
else
|
29
|
+
module_exec { val.is_a?(Proc) ? let(label, &val) : let(label) { val } }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module_eval(&block) if block_given?
|
34
|
+
|
35
|
+
after(:each) do |example|
|
36
|
+
if example.exception
|
37
|
+
index_info = arg.map { |v| RSpec::Paramz::PrettyPrint.inspect(v, false) }.join(', ')
|
38
|
+
example.exception.backtrace.push("failed paramz index is:#{index + 1}:[#{index_info}]")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def subject_label?(label)
|
48
|
+
label.is_a?(Hash) && label.keys == [:subject]
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_subject(label)
|
52
|
+
_subject = label[:subject]
|
53
|
+
|
54
|
+
_subject_name = nil
|
55
|
+
if _subject.is_a?(Hash)
|
56
|
+
_subject_name = _subject.keys.first
|
57
|
+
_subject = _subject.values.first
|
58
|
+
end
|
59
|
+
|
60
|
+
[_subject, _subject_name]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module Core
|
66
|
+
class ExampleGroup
|
67
|
+
extend ::RSpec::Paramz::ExampleGroupMethods
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Paramz
|
3
|
+
module PrettyPrint
|
4
|
+
def self.inspect(value, raw_value = true)
|
5
|
+
case value
|
6
|
+
when Hash
|
7
|
+
subject(value)
|
8
|
+
when Proc
|
9
|
+
to_source(value)
|
10
|
+
else
|
11
|
+
raw_value ? value : value.inspect
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.subject(value)
|
16
|
+
return value if value.keys != [:subject]
|
17
|
+
|
18
|
+
_subject = value.values.first
|
19
|
+
case _subject
|
20
|
+
when Proc
|
21
|
+
"subject #{to_source(_subject)}"
|
22
|
+
when Hash
|
23
|
+
subject_name = _subject.keys.first
|
24
|
+
subject_value = _subject.values.first
|
25
|
+
|
26
|
+
case subject_value
|
27
|
+
when Proc
|
28
|
+
"subject(:#{subject_name}) #{to_source(subject_value)}"
|
29
|
+
else
|
30
|
+
"subject { #{subject_value} }"
|
31
|
+
end
|
32
|
+
else
|
33
|
+
value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.to_source(value)
|
38
|
+
return value if value.is_a?(NamedProc) || !value.is_a?(Proc)
|
39
|
+
|
40
|
+
node = RubyVM::AbstractSyntaxTree.of(value)
|
41
|
+
return value if node.nil?
|
42
|
+
|
43
|
+
path = value.source_location.first
|
44
|
+
lines = File.readlines(path)
|
45
|
+
source_lines = lines[(node.first_lineno - 1)..(node.last_lineno - 1)]
|
46
|
+
source_lines[-1] = source_lines[-1][0..(node.last_column - 1)]
|
47
|
+
source_lines[0] = source_lines[0][node.first_column..]
|
48
|
+
source_lines.map(&:strip).join("\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rspec/paramz/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rspec-paramz"
|
7
|
+
spec.version = RSpec::Paramz::VERSION
|
8
|
+
spec.authors = ["fukayatsu"]
|
9
|
+
spec.email = ["fukayatsu@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Simple Parameterized Test for RSpec.}
|
12
|
+
spec.description = %q{Simple Parameterized Test for RSpec}
|
13
|
+
spec.homepage = "https://github.com/fukayatsu/rspec-paramz"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/fukayatsu/rspec-paramz"
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_runtime_dependency "rspec", "~> 3.0"
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "onkcop"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-paramz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fukayatsu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-07 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: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: onkcop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Simple Parameterized Test for RSpec
|
84
|
+
email:
|
85
|
+
- fukayatsu@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- lib/rspec/paramz.rb
|
104
|
+
- lib/rspec/paramz/named_proc.rb
|
105
|
+
- lib/rspec/paramz/pretty_print.rb
|
106
|
+
- lib/rspec/paramz/syntax.rb
|
107
|
+
- lib/rspec/paramz/version.rb
|
108
|
+
- rspec-paramz.gemspec
|
109
|
+
homepage: https://github.com/fukayatsu/rspec-paramz
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata:
|
113
|
+
homepage_uri: https://github.com/fukayatsu/rspec-paramz
|
114
|
+
source_code_uri: https://github.com/fukayatsu/rspec-paramz
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubygems_version: 3.0.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Simple Parameterized Test for RSpec.
|
134
|
+
test_files: []
|