rspec-parameterized 0.4.2 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +26 -0
- data/CHANGELOG.md +28 -2
- data/README.md +32 -3
- data/lib/rspec/parameterized/arg.rb +7 -0
- data/lib/rspec/parameterized/example_helper_methods.rb +19 -0
- data/lib/rspec/parameterized/helper_methods.rb +20 -0
- data/lib/rspec/parameterized/lazy_arg.rb +19 -0
- data/lib/rspec/parameterized/ref_arg.rb +19 -0
- data/lib/rspec/parameterized/version.rb +1 -1
- data/lib/rspec/parameterized.rb +6 -1
- data/rspec-parameterized.gemspec +2 -0
- data/spec/parametarized_spec.rb +96 -0
- metadata +14 -8
- data/.travis.yml +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b23f093e2fa9b8dbf2b3c4c3b04ce052ae73aa3dbe0d21cbb7a5e2e87f33a71d
|
4
|
+
data.tar.gz: c5ebbcad0dc320e6142b23e4b1a5f259e58be61aabb968a1cf573e512c147647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bdbe0fde4048954d88af8668938b7da13c58367282deeb7b1f0d096003abfb0ea8d4cc16880b972c962e2abb9962091ea33732665ab01a67dab3b53c97ce91e
|
7
|
+
data.tar.gz: f2dce9cd68b028acb2912875160213f633324874c139bc1652e3bd43c4899515635f84429f765e4293c09e5f4ed917aa02740c85ce7eb865f0be9de7047281e2
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: RSpec
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ $default-branch ]
|
6
|
+
pull_request:
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
20
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
|
-
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.
|
3
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.2...master)
|
4
|
+
|
5
|
+
## [v0.5.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.2) (2022-06-24)
|
6
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.1...v0.5.2)
|
7
|
+
|
8
|
+
- Made MFA mandatory for gem releases
|
9
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/79
|
10
|
+
|
11
|
+
## [v0.5.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.1) (2022-01-04)
|
12
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.0...v0.5.1)
|
13
|
+
|
14
|
+
- Changes to apply method calls recursively when parameter is Array or Hash.
|
15
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/75
|
16
|
+
|
17
|
+
## [v0.5.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.0) (2021-06-29)
|
18
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.2...v0.5.0)
|
19
|
+
|
20
|
+
- Support new parameter type: ref and lazy
|
21
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/62
|
22
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/65
|
23
|
+
|
24
|
+
## [v0.4.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.2) (2019-04-26)
|
25
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.1...v0.4.2)
|
26
|
+
|
27
|
+
- Support jruby
|
28
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/54
|
29
|
+
- https://github.com/tomykaira/rspec-parameterized/issues/49
|
4
30
|
|
5
31
|
## [v0.4.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.1) (2018-12-06)
|
6
32
|
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.0...v0.4.1)
|
@@ -156,4 +182,4 @@
|
|
156
182
|
## [v0.0.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.1) (2012-05-20)
|
157
183
|
|
158
184
|
|
159
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
185
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec::Parameterized [![Gem Version](https://badge.fury.io/rb/rspec-parameterized.svg)](https://badge.fury.io/rb/rspec-parameterized)
|
1
|
+
# RSpec::Parameterized [![Gem Version](https://badge.fury.io/rb/rspec-parameterized.svg)](https://badge.fury.io/rb/rspec-parameterized) ![rspec](https://github.com/tomykaira/rspec-parameterized/actions/workflows/rspec.yml/badge.svg)
|
2
2
|
|
3
3
|
Support simple parameterized test syntax in rspec.
|
4
4
|
|
@@ -105,7 +105,7 @@ end
|
|
105
105
|
|
106
106
|
# It's also possible to override each combination name using magic variable :case_name
|
107
107
|
# Output:
|
108
|
-
# Custom
|
108
|
+
# Custom names for regular syntax
|
109
109
|
# positive integers
|
110
110
|
# should do additions
|
111
111
|
# negative integers
|
@@ -130,7 +130,7 @@ end
|
|
130
130
|
|
131
131
|
# Or :case_names lambda for hash syntax
|
132
132
|
# Output:
|
133
|
-
#
|
133
|
+
# Custom naming for hash syntax
|
134
134
|
# 1 + 5 + 2
|
135
135
|
# sum is even
|
136
136
|
# 1 + 5 + 4
|
@@ -148,10 +148,39 @@ describe "Custom naming for hash syntax" do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
+
# Use ref(:symbol) to use let/let! defined variables in the where block
|
152
|
+
# Use lazy when you want to create let/let! variables after the where block
|
153
|
+
#
|
154
|
+
# Failures will be more readable in the future - https://github.com/tomykaira/rspec-parameterized/pull/65
|
155
|
+
describe "lazy and ref types" do
|
156
|
+
let(:one) { 1 }
|
157
|
+
let(:four) { 4 }
|
158
|
+
|
159
|
+
where(:a, :b, :result) do
|
160
|
+
[
|
161
|
+
[ref(:one), ref(:four), lazy { two + three }]
|
162
|
+
]
|
163
|
+
end
|
164
|
+
|
165
|
+
with_them do
|
166
|
+
context "use let after where block" do
|
167
|
+
let(:two) { 2 }
|
168
|
+
let(:three) { 3 }
|
169
|
+
|
170
|
+
it 'should equal 5' do
|
171
|
+
expect(a + b).to eq result
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
151
176
|
```
|
152
177
|
|
153
178
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|
154
179
|
|
180
|
+
## Support Versions
|
181
|
+
|
182
|
+
Ruby-2.6.0 or later.
|
183
|
+
|
155
184
|
## Installation
|
156
185
|
|
157
186
|
Add this line to your application's Gemfile:
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Parameterized
|
3
|
+
module ExampleHelperMethods
|
4
|
+
def recursive_apply(val)
|
5
|
+
return val.apply(self) if HelperMethods.applicable?(val)
|
6
|
+
|
7
|
+
if val.is_a?(Array)
|
8
|
+
return val.map { |child_val| recursive_apply(child_val) }
|
9
|
+
end
|
10
|
+
|
11
|
+
if val.is_a?(Hash)
|
12
|
+
return val.map { |key, value| [recursive_apply(key), recursive_apply(value)] }.to_h
|
13
|
+
end
|
14
|
+
|
15
|
+
val
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec/parameterized/ref_arg'
|
2
|
+
require 'rspec/parameterized/lazy_arg'
|
3
|
+
module RSpec
|
4
|
+
module Parameterized
|
5
|
+
module HelperMethods
|
6
|
+
def ref(symbol)
|
7
|
+
RefArg.new(symbol)
|
8
|
+
end
|
9
|
+
|
10
|
+
def lazy(&block)
|
11
|
+
LazyArg.new(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.applicable?(arg)
|
15
|
+
arg.is_a? Arg
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Parameterized
|
3
|
+
class LazyArg < Arg
|
4
|
+
def initialize(&block)
|
5
|
+
@block = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def apply(obj)
|
9
|
+
obj.instance_eval(&@block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
"#{@block.to_raw_source}"
|
14
|
+
rescue Parser::SyntaxError
|
15
|
+
super.inspect
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec/parameterized/arg'
|
2
|
+
module RSpec
|
3
|
+
module Parameterized
|
4
|
+
class RefArg < Arg
|
5
|
+
def initialize(symbol)
|
6
|
+
@symbol = symbol
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply(obj)
|
10
|
+
obj.send(@symbol)
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
"#{@symbol}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/lib/rspec/parameterized.rb
CHANGED
@@ -2,6 +2,8 @@ require "rspec/parameterized/version"
|
|
2
2
|
require 'parser'
|
3
3
|
require 'unparser'
|
4
4
|
require 'proc_to_ast'
|
5
|
+
require 'rspec/parameterized/helper_methods'
|
6
|
+
require 'rspec/parameterized/example_helper_methods'
|
5
7
|
|
6
8
|
module RSpec
|
7
9
|
module Parameterized
|
@@ -97,6 +99,7 @@ module RSpec
|
|
97
99
|
|
98
100
|
def define_cases(parameter, *args, &block)
|
99
101
|
instance = new # for evaluate let methods.
|
102
|
+
instance.extend HelperMethods
|
100
103
|
if defined?(self.superclass::LetDefinitions)
|
101
104
|
instance.extend self.superclass::LetDefinitions
|
102
105
|
end
|
@@ -111,8 +114,10 @@ module RSpec
|
|
111
114
|
pairs = [parameter.arg_names, param_set].transpose.to_h
|
112
115
|
pretty_params = pairs.has_key?(:case_name) ? pairs[:case_name] : pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
|
113
116
|
describe(pretty_params, *args) do
|
117
|
+
include ExampleHelperMethods
|
118
|
+
|
114
119
|
pairs.each do |name, val|
|
115
|
-
let(name) { val }
|
120
|
+
let(name) { recursive_apply(val) }
|
116
121
|
end
|
117
122
|
|
118
123
|
singleton_class.module_eval do
|
data/rspec-parameterized.gemspec
CHANGED
@@ -9,6 +9,8 @@ Gem::Specification.new do |gem|
|
|
9
9
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).}
|
10
10
|
gem.homepage = "https://github.com/tomykaira/rspec-parameterized"
|
11
11
|
|
12
|
+
gem.metadata["rubygems_mfa_required"] = "true"
|
13
|
+
|
12
14
|
gem.add_dependency('rspec', '>= 2.13', '< 4')
|
13
15
|
gem.add_dependency('parser')
|
14
16
|
gem.add_dependency('unparser')
|
data/spec/parametarized_spec.rb
CHANGED
@@ -191,6 +191,102 @@ describe RSpec::Parameterized do
|
|
191
191
|
|
192
192
|
end
|
193
193
|
|
194
|
+
describe "ref" do
|
195
|
+
context 'simple usecase' do
|
196
|
+
let(:foo) { 1 }
|
197
|
+
|
198
|
+
where(:value, :answer) do
|
199
|
+
[
|
200
|
+
[ref(:foo), 1],
|
201
|
+
]
|
202
|
+
end
|
203
|
+
|
204
|
+
with_them do
|
205
|
+
it "let variable in same example group can be used" do
|
206
|
+
expect(value).to eq answer
|
207
|
+
end
|
208
|
+
|
209
|
+
context "override let varibale" do
|
210
|
+
let(:foo) { 3 }
|
211
|
+
|
212
|
+
it "can override let variable" do
|
213
|
+
expect(value).to eq 3
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context "recursive usecase" do
|
220
|
+
let(:foo) { 1 }
|
221
|
+
|
222
|
+
where(:value, :answer) do
|
223
|
+
[
|
224
|
+
[[ref(:foo), 2], [1, 2]],
|
225
|
+
]
|
226
|
+
end
|
227
|
+
|
228
|
+
with_them do
|
229
|
+
it "let variable in same example group can be used" do
|
230
|
+
expect(value).to eq answer
|
231
|
+
end
|
232
|
+
|
233
|
+
context "override let varibale" do
|
234
|
+
let(:foo) { 3 }
|
235
|
+
|
236
|
+
it "can override let variable" do
|
237
|
+
expect(value).to eq [3, 2]
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "lazy" do
|
245
|
+
context "simple usecase" do
|
246
|
+
let(:one) { 1 }
|
247
|
+
let(:four) { 4 }
|
248
|
+
|
249
|
+
where(:a, :b, :answer) do
|
250
|
+
[
|
251
|
+
[ref(:one), ref(:four), lazy { two + three }],
|
252
|
+
]
|
253
|
+
end
|
254
|
+
|
255
|
+
with_them do
|
256
|
+
context "define two and three after where block" do
|
257
|
+
let(:two) { 2 }
|
258
|
+
let(:three) { 3 }
|
259
|
+
|
260
|
+
it "should do additions" do
|
261
|
+
expect(a + b).to eq answer
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'recursive usecase' do
|
268
|
+
let(:one) { 1 }
|
269
|
+
let(:four) { 4 }
|
270
|
+
|
271
|
+
where(:a, :b, :answer) do
|
272
|
+
[
|
273
|
+
[ref(:one), ref(:four), { result: lazy { two + three } }],
|
274
|
+
]
|
275
|
+
end
|
276
|
+
|
277
|
+
with_them do
|
278
|
+
context "define two and three after where block" do
|
279
|
+
let(:two) { 2 }
|
280
|
+
let(:three) { 3 }
|
281
|
+
|
282
|
+
it "should do additions" do
|
283
|
+
expect(a + b).to eq answer[:result]
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
194
290
|
if RUBY_VERSION >= "2.1"
|
195
291
|
describe "table separated with pipe (using TableSyntax)" do
|
196
292
|
using RSpec::Parameterized::TableSyntax
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-parameterized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomykaira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -107,9 +107,9 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".github/workflows/rspec.yml"
|
110
111
|
- ".gitignore"
|
111
112
|
- ".rspec"
|
112
|
-
- ".travis.yml"
|
113
113
|
- CHANGELOG.md
|
114
114
|
- Gemfile
|
115
115
|
- LICENSE
|
@@ -119,6 +119,11 @@ files:
|
|
119
119
|
- gemfiles/rspec3.4.gemfile
|
120
120
|
- lib/rspec-parameterized.rb
|
121
121
|
- lib/rspec/parameterized.rb
|
122
|
+
- lib/rspec/parameterized/arg.rb
|
123
|
+
- lib/rspec/parameterized/example_helper_methods.rb
|
124
|
+
- lib/rspec/parameterized/helper_methods.rb
|
125
|
+
- lib/rspec/parameterized/lazy_arg.rb
|
126
|
+
- lib/rspec/parameterized/ref_arg.rb
|
122
127
|
- lib/rspec/parameterized/table.rb
|
123
128
|
- lib/rspec/parameterized/table_syntax.rb
|
124
129
|
- lib/rspec/parameterized/version.rb
|
@@ -127,8 +132,9 @@ files:
|
|
127
132
|
- spec/spec_helper.rb
|
128
133
|
homepage: https://github.com/tomykaira/rspec-parameterized
|
129
134
|
licenses: []
|
130
|
-
metadata:
|
131
|
-
|
135
|
+
metadata:
|
136
|
+
rubygems_mfa_required: 'true'
|
137
|
+
post_install_message:
|
132
138
|
rdoc_options: []
|
133
139
|
require_paths:
|
134
140
|
- lib
|
@@ -143,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
149
|
- !ruby/object:Gem::Version
|
144
150
|
version: '0'
|
145
151
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
152
|
+
rubygems_version: 3.3.7
|
153
|
+
signing_key:
|
148
154
|
specification_version: 4
|
149
155
|
summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
|
150
156
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 2.4
|
6
|
-
- 2.5
|
7
|
-
- 2.6
|
8
|
-
- ruby-head
|
9
|
-
- jruby-9.2.7.0
|
10
|
-
|
11
|
-
gemfile:
|
12
|
-
- gemfiles/rspec3.4.gemfile
|
13
|
-
- gemfiles/rspec-head.gemfile
|
14
|
-
|
15
|
-
before_install:
|
16
|
-
- travis_retry gem update --system || travis_retry gem update --system 2.7.8
|
17
|
-
- travis_retry gem install bundler --no-document || travis_retry gem install bundler --no-document -v 1.17.3
|
18
|
-
|
19
|
-
matrix:
|
20
|
-
allow_failures:
|
21
|
-
- rvm: ruby-head
|