rspec-parameterized 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +8 -1
- data/README.md +27 -2
- data/lib/rspec/parameterized.rb +7 -1
- 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/version.rb +1 -1
- data/spec/parametarized_spec.rb +46 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
|
-
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.
|
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
|
4
11
|
|
5
12
|
## [v0.4.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.1) (2018-12-06)
|
6
13
|
[Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.0...v0.4.1)
|
data/README.md
CHANGED
@@ -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,6 +148,31 @@ 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).
|
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
|
@@ -97,6 +98,7 @@ module RSpec
|
|
97
98
|
|
98
99
|
def define_cases(parameter, *args, &block)
|
99
100
|
instance = new # for evaluate let methods.
|
101
|
+
instance.extend HelperMethods
|
100
102
|
if defined?(self.superclass::LetDefinitions)
|
101
103
|
instance.extend self.superclass::LetDefinitions
|
102
104
|
end
|
@@ -112,7 +114,11 @@ module RSpec
|
|
112
114
|
pretty_params = pairs.has_key?(:case_name) ? pairs[:case_name] : pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
|
113
115
|
describe(pretty_params, *args) do
|
114
116
|
pairs.each do |name, val|
|
115
|
-
|
117
|
+
if HelperMethods.applicable? val
|
118
|
+
let(name) { val.apply(self) }
|
119
|
+
else
|
120
|
+
let(name) { val }
|
121
|
+
end
|
116
122
|
end
|
117
123
|
|
118
124
|
singleton_class.module_eval do
|
@@ -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/spec/parametarized_spec.rb
CHANGED
@@ -191,6 +191,52 @@ describe RSpec::Parameterized do
|
|
191
191
|
|
192
192
|
end
|
193
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
|
+
|
194
240
|
if RUBY_VERSION >= "2.1"
|
195
241
|
describe "table separated with pipe (using TableSyntax)" do
|
196
242
|
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.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
|
@@ -119,6 +119,10 @@ 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/helper_methods.rb
|
124
|
+
- lib/rspec/parameterized/lazy_arg.rb
|
125
|
+
- lib/rspec/parameterized/ref_arg.rb
|
122
126
|
- lib/rspec/parameterized/table.rb
|
123
127
|
- lib/rspec/parameterized/table_syntax.rb
|
124
128
|
- lib/rspec/parameterized/version.rb
|
@@ -128,7 +132,7 @@ files:
|
|
128
132
|
homepage: https://github.com/tomykaira/rspec-parameterized
|
129
133
|
licenses: []
|
130
134
|
metadata: {}
|
131
|
-
post_install_message:
|
135
|
+
post_install_message:
|
132
136
|
rdoc_options: []
|
133
137
|
require_paths:
|
134
138
|
- lib
|
@@ -143,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
147
|
- !ruby/object:Gem::Version
|
144
148
|
version: '0'
|
145
149
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
150
|
+
rubygems_version: 3.2.3
|
151
|
+
signing_key:
|
148
152
|
specification_version: 4
|
149
153
|
summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
|
150
154
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|