rspec-parameterized 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +10 -5
- data/CHANGELOG.md +47 -0
- data/README.md +102 -1
- data/gemfiles/{rspec2.gemfile → rspec-head.gemfile} +1 -1
- data/lib/rspec/parameterized.rb +37 -4
- data/lib/rspec/parameterized/arg.rb +7 -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/table_syntax.rb +17 -9
- data/lib/rspec/parameterized/version.rb +1 -1
- data/rspec-parameterized.gemspec +2 -2
- data/spec/parametarized_spec.rb +173 -0
- metadata +16 -14
- data/gemfiles/rspec3.3.gemfile +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13272c9240c96a67c05aac16ced725a1ca74f7983a7b4efdda6ba64d377fddaf
|
4
|
+
data.tar.gz: 5a7c41cb7738620b94d789b4db10f8954e139886a2c3c3ea683d807d68d1b89f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b193a8ae72948274d5f2e3723d99ca84c75150ffb0ebce618afcab90f04159ea995c7331a528c77764c9844bbec0a5c4d0c1a507c7d1b220359fd62e6e6877
|
7
|
+
data.tar.gz: 22bedbee2bbddbf8a5874b591ca0d66ad05671caeb9df8af8a7a2769fe019cee1b188a42d2af7ca64d60ff03815276f74e0fde9237657e7cc8fe27aac0393d8c
|
data/.travis.yml
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
|
-
sudo: false
|
4
3
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
4
|
+
- 2.4
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
- 2.7
|
7
8
|
- ruby-head
|
9
|
+
- jruby-9.2.8.0
|
8
10
|
|
9
11
|
gemfile:
|
10
|
-
- gemfiles/rspec2.gemfile
|
11
|
-
- gemfiles/rspec3.3.gemfile
|
12
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
|
13
18
|
|
14
19
|
matrix:
|
15
20
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,51 @@
|
|
1
1
|
# Change Log
|
2
|
+
## Unreleased
|
3
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.2...master)
|
4
|
+
|
5
|
+
## [v0.4.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.2) (2019-04-26)
|
6
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.1...v0.4.2)
|
7
|
+
|
8
|
+
- Support jruby
|
9
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/54
|
10
|
+
- https://github.com/tomykaira/rspec-parameterized/issues/49
|
11
|
+
|
12
|
+
## [v0.4.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.1) (2018-12-06)
|
13
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.0...v0.4.1)
|
14
|
+
|
15
|
+
- Replace binding_of_caller with binding_ninja
|
16
|
+
- https://github.com/tomykaira/rspec-parameterized/pull/44
|
17
|
+
- https://github.com/tomykaira/rspec-parameterized/issues/48
|
18
|
+
|
19
|
+
## [v0.4.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.0) (2017-06-13)
|
20
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.2...v0.4.0)
|
21
|
+
|
22
|
+
**Merged pull requests:**
|
23
|
+
|
24
|
+
- Verbose test syntax [\#42](https://github.com/tomykaira/rspec-parameterized/pull/42) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich))
|
25
|
+
- Customizable description [\#41](https://github.com/tomykaira/rspec-parameterized/pull/41) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich))
|
26
|
+
|
27
|
+
## [v0.3.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.2) (2016-12-26)
|
28
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.1...v0.3.2)
|
29
|
+
|
30
|
+
**Merged pull requests:**
|
31
|
+
|
32
|
+
- Fix deprecation warning on ruby 2.4.0 [\#40](https://github.com/tomykaira/rspec-parameterized/pull/40) ([sue445](https://github.com/sue445))
|
33
|
+
- Add release note for v0.3.1 [\#39](https://github.com/tomykaira/rspec-parameterized/pull/39) ([sue445](https://github.com/sue445))
|
34
|
+
- Add rubygems version badge [\#38](https://github.com/tomykaira/rspec-parameterized/pull/38) ([sue445](https://github.com/sue445))
|
35
|
+
|
36
|
+
## [v0.3.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.1) (2016-08-17)
|
37
|
+
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.0...v0.3.1)
|
38
|
+
|
39
|
+
**Closed issues:**
|
40
|
+
|
41
|
+
- Support "||" syntax [\#34](https://github.com/tomykaira/rspec-parameterized/issues/34)
|
42
|
+
|
43
|
+
**Merged pull requests:**
|
44
|
+
|
45
|
+
- Set the caller of `.with\_them` to metadata of ExampleGroup [\#37](https://github.com/tomykaira/rspec-parameterized/pull/37) ([nalabjp](https://github.com/nalabjp))
|
46
|
+
- Add homepage url in gemspec [\#33](https://github.com/tomykaira/rspec-parameterized/pull/33) ([sue445](https://github.com/sue445))
|
47
|
+
- Tweak travis setting [\#32](https://github.com/tomykaira/rspec-parameterized/pull/32) ([sue445](https://github.com/sue445))
|
48
|
+
- Generate CHANGELOG [\#31](https://github.com/tomykaira/rspec-parameterized/pull/31) ([sue445](https://github.com/sue445))
|
2
49
|
|
3
50
|
## [v0.3.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.0) (2016-02-22)
|
4
51
|
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.2.0...v0.3.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec::Parameterized [](https://travis-ci.org/tomykaira/rspec-parameterized)
|
1
|
+
# RSpec::Parameterized [](https://badge.fury.io/rb/rspec-parameterized) [](https://travis-ci.org/tomykaira/rspec-parameterized)
|
2
2
|
|
3
3
|
Support simple parameterized test syntax in rspec.
|
4
4
|
|
@@ -72,6 +72,107 @@ describe "plus" do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
# Verbose Syntax
|
77
|
+
# For complex inputs or if you just want to be super explicit
|
78
|
+
describe "Verbose syntax" do
|
79
|
+
where do
|
80
|
+
{
|
81
|
+
"positive integers" => {
|
82
|
+
a: 1,
|
83
|
+
b: 2,
|
84
|
+
answer: 3,
|
85
|
+
},
|
86
|
+
"negative_integers" => {
|
87
|
+
a: -1,
|
88
|
+
b: -2,
|
89
|
+
answer: -3,
|
90
|
+
},
|
91
|
+
"mixed_integers" => {
|
92
|
+
a: 3,
|
93
|
+
b: -3,
|
94
|
+
answer: 0,
|
95
|
+
},
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
with_them do
|
100
|
+
it "should do additions" do
|
101
|
+
expect(a + b).to eq answer
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# It's also possible to override each combination name using magic variable :case_name
|
107
|
+
# Output:
|
108
|
+
# Custom names for regular syntax
|
109
|
+
# positive integers
|
110
|
+
# should do additions
|
111
|
+
# negative integers
|
112
|
+
# should do additions
|
113
|
+
# mixed integers
|
114
|
+
# should do additions
|
115
|
+
describe "Custom names for regular syntax" do
|
116
|
+
where(:case_name, :a, :b, :answer) do
|
117
|
+
[
|
118
|
+
["positive integers", 6, 2, 8],
|
119
|
+
["negative integers", -1, -2, -3],
|
120
|
+
[ "mixed integers", -5, 3, -2],
|
121
|
+
]
|
122
|
+
end
|
123
|
+
|
124
|
+
with_them do
|
125
|
+
it "should do additions" do
|
126
|
+
expect(a + b).to eq answer
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Or :case_names lambda for hash syntax
|
132
|
+
# Output:
|
133
|
+
# Custom naming for hash syntax
|
134
|
+
# 1 + 5 + 2
|
135
|
+
# sum is even
|
136
|
+
# 1 + 5 + 4
|
137
|
+
# sum is even
|
138
|
+
# 1 + 7 + 2
|
139
|
+
# sum is even
|
140
|
+
# ...
|
141
|
+
describe "Custom naming for hash syntax" do
|
142
|
+
where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4])
|
143
|
+
|
144
|
+
with_them do
|
145
|
+
it "sum is even" do
|
146
|
+
expect(a + b + c).to be_even
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
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
|
75
176
|
```
|
76
177
|
|
77
178
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|
data/lib/rspec/parameterized.rb
CHANGED
@@ -2,6 +2,7 @@ require "rspec/parameterized/version"
|
|
2
2
|
require 'parser'
|
3
3
|
require 'unparser'
|
4
4
|
require 'proc_to_ast'
|
5
|
+
require 'rspec/parameterized/helper_methods'
|
5
6
|
|
6
7
|
module RSpec
|
7
8
|
module Parameterized
|
@@ -40,12 +41,22 @@ module RSpec
|
|
40
41
|
def where(*args, &b)
|
41
42
|
|
42
43
|
if args.size == 1 && args[0].instance_of?(Hash)
|
44
|
+
naming_func = args.first.delete(:case_names)
|
43
45
|
params = args[0]
|
44
46
|
first, *rest = params.values
|
47
|
+
arg_names = params.keys
|
48
|
+
arg_values = first.product(*rest)
|
45
49
|
|
46
|
-
|
47
|
-
|
50
|
+
if naming_func && naming_func.respond_to?(:call)
|
51
|
+
arg_names << :case_name
|
52
|
+
arg_values.map! { |row| row << naming_func.call(*row) }
|
53
|
+
end
|
54
|
+
|
55
|
+
set_parameters(arg_names) {
|
56
|
+
arg_values
|
48
57
|
}
|
58
|
+
elsif args.size == 0
|
59
|
+
set_verbose_parameters(&b)
|
49
60
|
else
|
50
61
|
set_parameters(args, &b)
|
51
62
|
end
|
@@ -87,6 +98,7 @@ module RSpec
|
|
87
98
|
|
88
99
|
def define_cases(parameter, *args, &block)
|
89
100
|
instance = new # for evaluate let methods.
|
101
|
+
instance.extend HelperMethods
|
90
102
|
if defined?(self.superclass::LetDefinitions)
|
91
103
|
instance.extend self.superclass::LetDefinitions
|
92
104
|
end
|
@@ -99,10 +111,14 @@ module RSpec
|
|
99
111
|
|
100
112
|
param_sets.each do |param_set|
|
101
113
|
pairs = [parameter.arg_names, param_set].transpose.to_h
|
102
|
-
pretty_params = pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
|
114
|
+
pretty_params = pairs.has_key?(:case_name) ? pairs[:case_name] : pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
|
103
115
|
describe(pretty_params, *args) do
|
104
116
|
pairs.each do |name, val|
|
105
|
-
|
117
|
+
if HelperMethods.applicable? val
|
118
|
+
let(name) { val.apply(self) }
|
119
|
+
else
|
120
|
+
let(name) { val }
|
121
|
+
end
|
106
122
|
end
|
107
123
|
|
108
124
|
singleton_class.module_eval do
|
@@ -135,6 +151,23 @@ module RSpec
|
|
135
151
|
return obj.inspect
|
136
152
|
end
|
137
153
|
end
|
154
|
+
|
155
|
+
def set_verbose_parameters(&block)
|
156
|
+
arguments_hash = yield
|
157
|
+
arg_names = arguments_hash.values.reduce(Set.new) { |memo, pairs| memo | pairs.keys }.to_a
|
158
|
+
arg_values = []
|
159
|
+
arguments_hash.each do |name, values_hash|
|
160
|
+
row = [name]
|
161
|
+
arg_names.each do |argument_name|
|
162
|
+
row << values_hash[argument_name]
|
163
|
+
end
|
164
|
+
arg_values << row
|
165
|
+
end
|
166
|
+
arg_names.unshift(:case_name)
|
167
|
+
set_parameters(arg_names) {
|
168
|
+
arg_values
|
169
|
+
}
|
170
|
+
end
|
138
171
|
end
|
139
172
|
end
|
140
173
|
|
@@ -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
|
+
|
@@ -1,12 +1,13 @@
|
|
1
|
-
require 'binding_of_caller'
|
2
1
|
require 'rspec/parameterized/table'
|
2
|
+
require 'binding_ninja'
|
3
3
|
|
4
4
|
module RSpec
|
5
5
|
module Parameterized
|
6
6
|
module TableSyntaxImplement
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
extend BindingNinja
|
8
|
+
|
9
|
+
def |(where_binding, other)
|
10
|
+
caller_instance = where_binding.receiver # get caller instance (ExampleGroup)
|
10
11
|
|
11
12
|
if caller_instance.instance_variable_defined?(:@__parameter_table)
|
12
13
|
table = caller_instance.instance_variable_get(:@__parameter_table)
|
@@ -20,6 +21,7 @@ module RSpec
|
|
20
21
|
row.add_param(other)
|
21
22
|
table
|
22
23
|
end
|
24
|
+
auto_inject_binding :|
|
23
25
|
end
|
24
26
|
|
25
27
|
module TableSyntax
|
@@ -27,12 +29,18 @@ module RSpec
|
|
27
29
|
include TableSyntaxImplement
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create("2.4.0")
|
33
|
+
refine Integer do
|
34
|
+
include TableSyntaxImplement
|
35
|
+
end
|
36
|
+
else
|
37
|
+
refine Fixnum do
|
38
|
+
include TableSyntaxImplement
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
refine Bignum do
|
42
|
+
include TableSyntaxImplement
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
38
46
|
refine Array do
|
data/rspec-parameterized.gemspec
CHANGED
@@ -13,8 +13,8 @@ I was inspired by [udzura's mock](https://gist.github.com/1881139).}
|
|
13
13
|
gem.add_dependency('parser')
|
14
14
|
gem.add_dependency('unparser')
|
15
15
|
gem.add_dependency('proc_to_ast')
|
16
|
-
gem.add_dependency('
|
17
|
-
gem.add_development_dependency('rake')
|
16
|
+
gem.add_dependency('binding_ninja', '>= 0.2.3')
|
17
|
+
gem.add_development_dependency('rake', '>= 12.0.0')
|
18
18
|
|
19
19
|
gem.files = `git ls-files`.split($\)
|
20
20
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/spec/parametarized_spec.rb
CHANGED
@@ -66,6 +66,177 @@ describe RSpec::Parameterized do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe "Verbose syntax" do
|
70
|
+
where do
|
71
|
+
{
|
72
|
+
"positive integers" => {
|
73
|
+
a: 1,
|
74
|
+
b: 2,
|
75
|
+
answer: 3,
|
76
|
+
},
|
77
|
+
"negative_integers" => {
|
78
|
+
a: -1,
|
79
|
+
b: -2,
|
80
|
+
answer: -3,
|
81
|
+
},
|
82
|
+
"mixed_integers" => {
|
83
|
+
a: 3,
|
84
|
+
b: -3,
|
85
|
+
answer: 0,
|
86
|
+
},
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
with_them do
|
91
|
+
it "should do additions" do
|
92
|
+
expect(a + b).to eq answer
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should have custom name" do |example|
|
96
|
+
expect(example.metadata[:example_group][:description]).to eq case_name
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "lambda parameter" do
|
101
|
+
where do
|
102
|
+
{
|
103
|
+
"integers" => {
|
104
|
+
a: 1,
|
105
|
+
b: 2,
|
106
|
+
answer: -> {expect(subject).to eq 3},
|
107
|
+
},
|
108
|
+
"strings" => {
|
109
|
+
a: "hello ",
|
110
|
+
b: "world",
|
111
|
+
answer: -> {expect(subject).to include "lo wo"},
|
112
|
+
},
|
113
|
+
"arrays" => {
|
114
|
+
a: [1, 2, 3],
|
115
|
+
b: [4, 5, 6],
|
116
|
+
answer: -> {expect(subject.size).to eq 6}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
with_them do
|
122
|
+
subject {a + b}
|
123
|
+
it "should do additions" do
|
124
|
+
self.instance_exec(&answer)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should have custom name" do |example|
|
128
|
+
expect(example.metadata[:example_group][:description]).to eq(case_name)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "Custom test case name" do
|
135
|
+
context "when regular arguments" do
|
136
|
+
where(:case_name, :a, :b, :answer) do
|
137
|
+
[
|
138
|
+
["positive integers", 6, 2, 8],
|
139
|
+
["negative integers", -1, -2, -3],
|
140
|
+
[ "mixed integers", -5, 3, -2],
|
141
|
+
]
|
142
|
+
end
|
143
|
+
|
144
|
+
with_them do
|
145
|
+
it "should do additions" do
|
146
|
+
expect(a + b).to eq answer
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should have custom test name" do |example|
|
150
|
+
expect(example.metadata[:example_group][:description]).to eq case_name
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when hash arguments" do
|
156
|
+
where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4])
|
157
|
+
|
158
|
+
with_them do
|
159
|
+
it "sum is even" do
|
160
|
+
expect(a + b + c).to be_even
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should have custom names" do |example|
|
164
|
+
expect(example.metadata[:example_group][:description]).to include "+"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
if RUBY_VERSION >= "2,1"
|
170
|
+
context "when arguments are separated with pipe (using TableSyntax)" do
|
171
|
+
using RSpec::Parameterized::TableSyntax
|
172
|
+
|
173
|
+
where(:case_name, :a, :b, :answer) do
|
174
|
+
"integers" | 1 | 2 | 3
|
175
|
+
"strings" | "hello " | "world" | "hello world"
|
176
|
+
"arrays" | [1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6]
|
177
|
+
"giant numbers" | 100000000000000000000 | 100000000000000000000 | 200000000000000000000
|
178
|
+
end
|
179
|
+
|
180
|
+
with_them do
|
181
|
+
it "a plus b is answer" do
|
182
|
+
expect(a + b).to eq answer
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should have custom test name" do |example|
|
186
|
+
expect(example.metadata[:example_group][:description]).to eq case_name
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "ref" do
|
195
|
+
let(:foo) { 1 }
|
196
|
+
|
197
|
+
where(:value, :answer) do
|
198
|
+
[
|
199
|
+
[ref(:foo), 1],
|
200
|
+
]
|
201
|
+
end
|
202
|
+
|
203
|
+
with_them do
|
204
|
+
it "let variable in same example group can be used" do
|
205
|
+
expect(value).to eq answer
|
206
|
+
end
|
207
|
+
|
208
|
+
context "override let varibale" do
|
209
|
+
let(:foo) { 3 }
|
210
|
+
|
211
|
+
it "can override let variable" do
|
212
|
+
expect(value).to eq 3
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "lazy" do
|
219
|
+
let(:one) { 1 }
|
220
|
+
let(:four) { 4 }
|
221
|
+
|
222
|
+
where(:a, :b, :answer) do
|
223
|
+
[
|
224
|
+
[ref(:one), ref(:four), lazy { two + three }],
|
225
|
+
]
|
226
|
+
end
|
227
|
+
|
228
|
+
with_them do
|
229
|
+
context "define two and three after where block" do
|
230
|
+
let(:two) { 2 }
|
231
|
+
let(:three) { 3 }
|
232
|
+
|
233
|
+
it "should do additions" do
|
234
|
+
expect(a + b).to eq answer
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
69
240
|
if RUBY_VERSION >= "2.1"
|
70
241
|
describe "table separated with pipe (using TableSyntax)" do
|
71
242
|
using RSpec::Parameterized::TableSyntax
|
@@ -74,6 +245,7 @@ describe RSpec::Parameterized do
|
|
74
245
|
1 | 2 | 3
|
75
246
|
"hello " | "world" | "hello world"
|
76
247
|
[1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6]
|
248
|
+
100000000000000000000 | 100000000000000000000 | 200000000000000000000
|
77
249
|
end
|
78
250
|
|
79
251
|
with_them do
|
@@ -90,6 +262,7 @@ describe RSpec::Parameterized do
|
|
90
262
|
1 | 2 | -> { eq(3) }
|
91
263
|
"hello " | "world" | -> { eq("hello world") }
|
92
264
|
[1, 2, 3] | [4, 5, 6] | -> { be_a(Array) }
|
265
|
+
100000000000000000000 | 100000000000000000000 | -> { eq(200000000000000000000) }
|
93
266
|
end
|
94
267
|
|
95
268
|
with_them do
|
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.0
|
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: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -73,33 +73,33 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: binding_ninja
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 0.2.3
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 0.2.3
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rake
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 12.0.0
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 12.0.0
|
103
103
|
description: RSpec::Parameterized supports simple parameterized test syntax in rspec.
|
104
104
|
email:
|
105
105
|
- tomykaira@gmail.com
|
@@ -115,11 +115,14 @@ files:
|
|
115
115
|
- LICENSE
|
116
116
|
- README.md
|
117
117
|
- Rakefile
|
118
|
-
- gemfiles/
|
119
|
-
- gemfiles/rspec3.3.gemfile
|
118
|
+
- gemfiles/rspec-head.gemfile
|
120
119
|
- gemfiles/rspec3.4.gemfile
|
121
120
|
- lib/rspec-parameterized.rb
|
122
121
|
- lib/rspec/parameterized.rb
|
122
|
+
- lib/rspec/parameterized/arg.rb
|
123
|
+
- lib/rspec/parameterized/helper_methods.rb
|
124
|
+
- lib/rspec/parameterized/lazy_arg.rb
|
125
|
+
- lib/rspec/parameterized/ref_arg.rb
|
123
126
|
- lib/rspec/parameterized/table.rb
|
124
127
|
- lib/rspec/parameterized/table_syntax.rb
|
125
128
|
- lib/rspec/parameterized/version.rb
|
@@ -129,7 +132,7 @@ files:
|
|
129
132
|
homepage: https://github.com/tomykaira/rspec-parameterized
|
130
133
|
licenses: []
|
131
134
|
metadata: {}
|
132
|
-
post_install_message:
|
135
|
+
post_install_message:
|
133
136
|
rdoc_options: []
|
134
137
|
require_paths:
|
135
138
|
- lib
|
@@ -144,9 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
147
|
- !ruby/object:Gem::Version
|
145
148
|
version: '0'
|
146
149
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
150
|
+
rubygems_version: 3.2.3
|
151
|
+
signing_key:
|
150
152
|
specification_version: 4
|
151
153
|
summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
|
152
154
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|