rspec-parameterized 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e6be52e986b05c5db18dc2355e2ee393b0ee954
4
- data.tar.gz: 191bb660e0afdc89f466f1213a4ce756ba9566e1
2
+ SHA256:
3
+ metadata.gz: 59435a789f542a5f80075f3dead8b2ffec470174a91b134b8a6c8cec3ae5bdc2
4
+ data.tar.gz: 5f1282e9687857cad7d18afb679779eb44c06aefe662cb743000082df4a4dece
5
5
  SHA512:
6
- metadata.gz: 7cce6711e56fb75d458b75b1fc4a9d47f7908395040bfc0eec9b809b66b5cbe0f5ec8663747b1b40e053286aafccfd9884eb4d2c97358414cc09191cfe74cef7
7
- data.tar.gz: 9a5e59b1d28cd1bf826346c61d0953daba8bb6f198966d03024c98f1570a02e50b79f6ed5a89032fb805b7a50131ff5ceea8159965d59dc5c8cfd94ccf8c183f
6
+ metadata.gz: 4c719dc2e53f0d0070b76169115efa6e40b09b927f1440acd89a3cf7c7e97e7ac7f71c2dd7bbbbe139712ee4dcb0145d7d1b09475bf1103c653ba84246be2944
7
+ data.tar.gz: 181acdafb5baeec82d9e90dd3a29254f523b8432d850c6946b42d24532dc29bb80777af4a360019129062404da0685152b0841f6cc8508b382eab6583fd8d9a0
@@ -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,4 +1,41 @@
1
1
  # Change Log
2
+ ## Unreleased
3
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.1...master)
4
+
5
+ ## [v0.5.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.1) (2022-01-04)
6
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.0...v0.5.1)
7
+
8
+ - Changes to apply method calls recursively when parameter is Array or Hash.
9
+ - https://github.com/tomykaira/rspec-parameterized/pull/75
10
+
11
+ ## [v0.5.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.0) (2021-06-29)
12
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.2...v0.5.0)
13
+
14
+ - Support new parameter type: ref and lazy
15
+ - https://github.com/tomykaira/rspec-parameterized/pull/62
16
+ - https://github.com/tomykaira/rspec-parameterized/pull/65
17
+
18
+ ## [v0.4.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.2) (2019-04-26)
19
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.1...v0.4.2)
20
+
21
+ - Support jruby
22
+ - https://github.com/tomykaira/rspec-parameterized/pull/54
23
+ - https://github.com/tomykaira/rspec-parameterized/issues/49
24
+
25
+ ## [v0.4.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.1) (2018-12-06)
26
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.0...v0.4.1)
27
+
28
+ - Replace binding_of_caller with binding_ninja
29
+ - https://github.com/tomykaira/rspec-parameterized/pull/44
30
+ - https://github.com/tomykaira/rspec-parameterized/issues/48
31
+
32
+ ## [v0.4.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.0) (2017-06-13)
33
+ [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.2...v0.4.0)
34
+
35
+ **Merged pull requests:**
36
+
37
+ - Verbose test syntax [\#42](https://github.com/tomykaira/rspec-parameterized/pull/42) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich))
38
+ - Customizable description [\#41](https://github.com/tomykaira/rspec-parameterized/pull/41) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich))
2
39
 
3
40
  ## [v0.3.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.2) (2016-12-26)
4
41
  [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.1...v0.3.2)
@@ -139,4 +176,4 @@
139
176
  ## [v0.0.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.1) (2012-05-20)
140
177
 
141
178
 
142
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
179
+ \* *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) [![Build Status](https://travis-ci.org/tomykaira/rspec-parameterized.svg)](https://travis-ci.org/tomykaira/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 test case name
108
+ # Custom names for regular syntax
109
109
  # positive integers
110
110
  # should do additions
111
111
  # negative integers
@@ -124,12 +124,13 @@ describe "Custom names for regular syntax" do
124
124
  with_them do
125
125
  it "should do additions" do
126
126
  expect(a + b).to eq answer
127
+ end
127
128
  end
128
129
  end
129
130
 
130
131
  # Or :case_names lambda for hash syntax
131
132
  # Output:
132
- # when hash arguments
133
+ # Custom naming for hash syntax
133
134
  # 1 + 5 + 2
134
135
  # sum is even
135
136
  # 1 + 5 + 4
@@ -147,10 +148,39 @@ describe "Custom naming for hash syntax" do
147
148
  end
148
149
  end
149
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
150
176
  ```
151
177
 
152
178
  I was inspired by [udzura's mock](https://gist.github.com/1881139).
153
179
 
180
+ ## Support Versions
181
+
182
+ Ruby-2.6.0 or later.
183
+
154
184
  ## Installation
155
185
 
156
186
  Add this line to your application's Gemfile:
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rspec", "~> 2.14"
3
+ gem "rspec"
4
4
 
5
5
  gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ module RSpec
2
+ module Parameterized
3
+ class Arg
4
+ def apply(obj) ; end
5
+ end
6
+ end
7
+ end
@@ -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
+
@@ -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
- def |(other)
8
- where_binding = binding.of_caller(1) # get where block binding
9
- caller_instance = eval("self", where_binding) # get caller instance (ExampleGroup)
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Parameterized
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.1"
4
4
  end
5
5
  end
@@ -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
@@ -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('binding_of_caller')
17
- gem.add_development_dependency('rake', '< 12.0.0')
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) }
@@ -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.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomykaira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -73,31 +73,31 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: binding_of_caller
76
+ name: binding_ninja
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
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: '0'
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
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
102
  version: 12.0.0
103
103
  description: RSpec::Parameterized supports simple parameterized test syntax in rspec.
@@ -107,19 +107,23 @@ 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
116
116
  - README.md
117
117
  - Rakefile
118
- - gemfiles/rspec2.gemfile
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/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
123
127
  - lib/rspec/parameterized/table.rb
124
128
  - lib/rspec/parameterized/table_syntax.rb
125
129
  - lib/rspec/parameterized/version.rb
@@ -129,7 +133,7 @@ files:
129
133
  homepage: https://github.com/tomykaira/rspec-parameterized
130
134
  licenses: []
131
135
  metadata: {}
132
- post_install_message:
136
+ post_install_message:
133
137
  rdoc_options: []
134
138
  require_paths:
135
139
  - lib
@@ -144,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
148
  - !ruby/object:Gem::Version
145
149
  version: '0'
146
150
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.6.12
149
- signing_key:
151
+ rubygems_version: 3.2.22
152
+ signing_key:
150
153
  specification_version: 4
151
154
  summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
152
155
  I was inspired by [udzura's mock](https://gist.github.com/1881139).
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- rvm:
5
- - 2.2
6
- - 2.3.0
7
- - 2.4.0
8
- - ruby-head
9
-
10
- gemfile:
11
- - gemfiles/rspec2.gemfile
12
- - gemfiles/rspec3.3.gemfile
13
- - gemfiles/rspec3.4.gemfile
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem "rspec", "~> 3.3.0"
4
-
5
- gemspec path: "../"