rspec-parameterized 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +5 -0
- data/README.md +32 -14
- data/Rakefile +18 -1
- data/gemfiles/rspec2.gemfile +5 -0
- data/gemfiles/rspec3.gemfile +5 -0
- data/lib/rspec/parameterized.rb +13 -7
- data/lib/rspec/parameterized/table.rb +49 -0
- data/lib/rspec/parameterized/table_syntax.rb +43 -0
- data/lib/rspec/parameterized/version.rb +1 -1
- data/rspec-parameterized.gemspec +2 -1
- data/spec/parametarized_spec.rb +85 -17
- data/spec/spec_helper.rb +0 -1
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24dea93292aa96d393a92768be187af611221e77
|
4
|
+
data.tar.gz: 68e63fb870c354828faf43f206bec637409fe720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 628f3013962c640461b7924e464b53a756baaf2d1a609662b72b8492daa7947eb565229bcff5eca7aa84a0713afe4d9b88c5d9ab8ec796ee40be6e7c590c48a5
|
7
|
+
data.tar.gz: c3d753b0284206cf8e659078a153cce04cdecbaa786c3592ce644a0c7e969a2373b00f7bbb39928d0114f67051c476aef6ce06c5c2eab31cf2b0886e50cfb20f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,21 +2,39 @@
|
|
2
2
|
|
3
3
|
Support simple parameterized test syntax in rspec.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
5
|
+
```ruby
|
6
|
+
describe "plus" do
|
7
|
+
where(:a, :b, :answer) do
|
8
|
+
[
|
9
|
+
[1 , 2 , 3],
|
10
|
+
[5 , 8 , 13],
|
11
|
+
[0 , 0 , 0]
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
with_them do
|
16
|
+
it "should do additions" do
|
17
|
+
(a + b).should == answer
|
19
18
|
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "plus" do
|
23
|
+
using RSpec::Parameterized::TableSyntax
|
24
|
+
|
25
|
+
where(:a, :b, :answer) do
|
26
|
+
1 | 2 | 3
|
27
|
+
5 | 8 | 13
|
28
|
+
0 | 0 | 0
|
29
|
+
end
|
30
|
+
|
31
|
+
with_them do
|
32
|
+
it "should do additions" do
|
33
|
+
(a + b).should == answer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
20
38
|
|
21
39
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).
|
22
40
|
|
data/Rakefile
CHANGED
@@ -6,6 +6,23 @@ begin
|
|
6
6
|
require 'rspec/core/rake_task'
|
7
7
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
8
|
spec.pattern = 'spec/**/*_spec.rb'
|
9
|
-
spec.rspec_opts = ['-
|
9
|
+
spec.rspec_opts = ['-c -f d']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
namespace :spec do
|
14
|
+
%w(rspec2 rspec3).each do |gemfile|
|
15
|
+
desc "Run Tests by #{gemfile}.gemfile"
|
16
|
+
task gemfile do
|
17
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
|
18
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Run All Tests"
|
23
|
+
task :all do
|
24
|
+
%w(rspec2 rspec3).each do |gemfile|
|
25
|
+
Rake::Task["spec:#{gemfile}"].invoke
|
26
|
+
end
|
10
27
|
end
|
11
28
|
end
|
data/lib/rspec/parameterized.rb
CHANGED
@@ -5,8 +5,9 @@ require 'proc_to_ast'
|
|
5
5
|
|
6
6
|
module RSpec
|
7
7
|
module Parameterized
|
8
|
-
|
8
|
+
autoload :TableSyntax, 'rspec/parameterized/table_syntax'
|
9
9
|
|
10
|
+
module ExampleGroupMethods
|
10
11
|
# capsulize parameter attributes
|
11
12
|
class Parameter
|
12
13
|
attr_reader :arg_names, :table_format, :block
|
@@ -18,7 +19,7 @@ module RSpec
|
|
18
19
|
|
19
20
|
# Set parameters to be bound in specs under this example group.
|
20
21
|
#
|
21
|
-
# ##
|
22
|
+
# ## Example1
|
22
23
|
#
|
23
24
|
# where(:a, :b, :answer) do
|
24
25
|
# [
|
@@ -28,6 +29,14 @@ module RSpec
|
|
28
29
|
# ]
|
29
30
|
# end
|
30
31
|
#
|
32
|
+
# ## Example2
|
33
|
+
# using RSpec::Parameterized::TableSyntax
|
34
|
+
# where(:a, :b, :answer) do
|
35
|
+
# 1 | 2 | 3 >
|
36
|
+
# 5 | 8 | 13 >
|
37
|
+
# 0 | 0 | 0
|
38
|
+
# end
|
39
|
+
#
|
31
40
|
def where(*args, &b)
|
32
41
|
set_parameters(args, false, &b)
|
33
42
|
end
|
@@ -117,10 +126,6 @@ module RSpec
|
|
117
126
|
instance.instance_eval(source_fragment)
|
118
127
|
end
|
119
128
|
|
120
|
-
def ruby2ruby
|
121
|
-
@ruby2ruby ||= Ruby2Ruby.new
|
122
|
-
end
|
123
|
-
|
124
129
|
def define_cases(parameter, *args, &block)
|
125
130
|
instance = new # for evaluate let methods.
|
126
131
|
if defined?(self.superclass::LetDefinitions)
|
@@ -130,7 +135,8 @@ module RSpec
|
|
130
135
|
if parameter.table_format
|
131
136
|
param_sets = separate_table_like_block(parameter.block)
|
132
137
|
else
|
133
|
-
|
138
|
+
extracted = instance.instance_eval(¶meter.block)
|
139
|
+
param_sets = extracted.is_a?(Array) ? extracted : extracted.to_params
|
134
140
|
end
|
135
141
|
|
136
142
|
# for only one parameters
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Parameterized
|
3
|
+
class Table
|
4
|
+
attr_reader :last_row
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@rows = []
|
8
|
+
@last_row = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_row(row)
|
12
|
+
unless @rows.find {|r| r.object_id == row.object_id}
|
13
|
+
@rows << row
|
14
|
+
@last_row = row
|
15
|
+
end
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_param_to_last_row(param)
|
20
|
+
last_row.add_param(param)
|
21
|
+
self
|
22
|
+
end
|
23
|
+
alias :| :add_param_to_last_row
|
24
|
+
|
25
|
+
def to_a
|
26
|
+
@rows.map(&:to_a)
|
27
|
+
end
|
28
|
+
alias :to_params :to_a
|
29
|
+
|
30
|
+
class Row
|
31
|
+
def initialize(param)
|
32
|
+
@params = [param]
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_param(param)
|
36
|
+
@params << param
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_a
|
40
|
+
@params
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_params
|
44
|
+
[@params]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'binding_of_caller'
|
2
|
+
require 'rspec/parameterized/table'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Parameterized
|
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)
|
10
|
+
|
11
|
+
if caller_instance.instance_variable_defined?(:@__parameter_table)
|
12
|
+
table = caller_instance.instance_variable_get(:@__parameter_table)
|
13
|
+
else
|
14
|
+
table = RSpec::Parameterized::Table.new
|
15
|
+
caller_instance.instance_variable_set(:@__parameter_table, table)
|
16
|
+
end
|
17
|
+
|
18
|
+
row = Table::Row.new(self)
|
19
|
+
table.add_row(row)
|
20
|
+
row.add_param(other)
|
21
|
+
table
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module TableSyntax
|
26
|
+
refine Object do
|
27
|
+
include TableSyntaxImplement
|
28
|
+
end
|
29
|
+
|
30
|
+
refine Fixnum do
|
31
|
+
include TableSyntaxImplement
|
32
|
+
end
|
33
|
+
|
34
|
+
refine Bignum do
|
35
|
+
include TableSyntaxImplement
|
36
|
+
end
|
37
|
+
|
38
|
+
refine Array do
|
39
|
+
include TableSyntaxImplement
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/rspec-parameterized.gemspec
CHANGED
@@ -9,10 +9,11 @@ Gem::Specification.new do |gem|
|
|
9
9
|
I was inspired by [udzura's mock](https://gist.github.com/1881139).}
|
10
10
|
gem.homepage = ""
|
11
11
|
|
12
|
-
gem.add_dependency('rspec', '
|
12
|
+
gem.add_dependency('rspec', '>= 2.13', '< 4')
|
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')
|
16
17
|
gem.add_development_dependency('rake')
|
17
18
|
|
18
19
|
gem.files = `git ls-files`.split($\)
|
data/spec/parametarized_spec.rb
CHANGED
@@ -22,13 +22,13 @@ describe RSpec::Parameterized do
|
|
22
22
|
|
23
23
|
with_them do
|
24
24
|
it "should do additions" do
|
25
|
-
(a + b).
|
25
|
+
expect(a + b).to eq answer
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
with_them :
|
29
|
+
with_them pending: "PENDING" do
|
30
30
|
it "should do additions" do
|
31
|
-
(a + b).
|
31
|
+
expect(a + b).to == answer
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -50,7 +50,6 @@ describe RSpec::Parameterized do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
54
53
|
describe "table separated with pipe" do
|
55
54
|
where_table(:a, :b, :answer) do
|
56
55
|
1 | 2 | 3
|
@@ -60,7 +59,41 @@ describe RSpec::Parameterized do
|
|
60
59
|
|
61
60
|
with_them do
|
62
61
|
it "a plus b is answer" do
|
63
|
-
(a + b).
|
62
|
+
expect(a + b).to eq answer
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if RUBY_VERSION >= "2.1"
|
68
|
+
describe "table separated with pipe (using TableSyntax)" do
|
69
|
+
using RSpec::Parameterized::TableSyntax
|
70
|
+
|
71
|
+
where(:a, :b, :answer) do
|
72
|
+
1 | 2 | 3
|
73
|
+
"hello " | "world" | "hello world"
|
74
|
+
[1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6]
|
75
|
+
end
|
76
|
+
|
77
|
+
with_them do
|
78
|
+
it "a plus b is answer" do
|
79
|
+
expect(a + b).to eq answer
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "table separated with pipe and lambda parameter (using TableSyntax)" do
|
85
|
+
using RSpec::Parameterized::TableSyntax
|
86
|
+
|
87
|
+
where(:a, :b, :matcher) do
|
88
|
+
1 | 2 | -> { eq(3) }
|
89
|
+
"hello " | "world" | -> { eq("hello world") }
|
90
|
+
[1, 2, 3] | [4, 5, 6] | -> { be_a(Array) }
|
91
|
+
end
|
92
|
+
|
93
|
+
with_them do
|
94
|
+
it "a plus b is answer" do
|
95
|
+
expect(a + b).to instance_exec(&matcher)
|
96
|
+
end
|
64
97
|
end
|
65
98
|
end
|
66
99
|
end
|
@@ -68,13 +101,13 @@ describe RSpec::Parameterized do
|
|
68
101
|
context "when the where block is after with_them" do
|
69
102
|
with_them do
|
70
103
|
it "should do additions" do
|
71
|
-
(a + b).
|
104
|
+
expect(a + b).to eq answer
|
72
105
|
end
|
73
106
|
end
|
74
107
|
|
75
108
|
with_them do
|
76
109
|
subject { a }
|
77
|
-
it { should
|
110
|
+
it { should be_a Numeric }
|
78
111
|
end
|
79
112
|
|
80
113
|
where(:a, :b, :answer) do
|
@@ -89,7 +122,7 @@ describe RSpec::Parameterized do
|
|
89
122
|
context "when the where block is between with_thems" do
|
90
123
|
with_them do
|
91
124
|
it "should do additions" do
|
92
|
-
(a + b).
|
125
|
+
expect(a + b).to eq answer
|
93
126
|
end
|
94
127
|
end
|
95
128
|
|
@@ -103,7 +136,7 @@ describe RSpec::Parameterized do
|
|
103
136
|
|
104
137
|
with_them do
|
105
138
|
subject { a }
|
106
|
-
it { should
|
139
|
+
it { should be_a Numeric }
|
107
140
|
end
|
108
141
|
end
|
109
142
|
|
@@ -114,7 +147,7 @@ describe RSpec::Parameterized do
|
|
114
147
|
|
115
148
|
with_them do
|
116
149
|
it 'can take an array of elements' do
|
117
|
-
x.
|
150
|
+
expect(x).to eq x
|
118
151
|
end
|
119
152
|
end
|
120
153
|
end
|
@@ -126,7 +159,23 @@ describe RSpec::Parameterized do
|
|
126
159
|
|
127
160
|
with_them do
|
128
161
|
it "a plus b is answer" do
|
129
|
-
(a + b).
|
162
|
+
expect(a + b).to eq answer
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
if RUBY_VERSION >= "2.1"
|
168
|
+
context "when the table has only a row (using TableSyntax)" do
|
169
|
+
using RSpec::Parameterized::TableSyntax
|
170
|
+
|
171
|
+
where(:a, :b, :answer) do
|
172
|
+
1 | 2 | 3
|
173
|
+
end
|
174
|
+
|
175
|
+
with_them do
|
176
|
+
it "a plus b is answer" do
|
177
|
+
expect(a + b).to eq answer
|
178
|
+
end
|
130
179
|
end
|
131
180
|
end
|
132
181
|
end
|
@@ -146,7 +195,7 @@ describe RSpec::Parameterized do
|
|
146
195
|
|
147
196
|
with_them do
|
148
197
|
it "a plus b is answer" do
|
149
|
-
(a + b).
|
198
|
+
expect(a + b).to eq answer
|
150
199
|
end
|
151
200
|
end
|
152
201
|
end
|
@@ -159,21 +208,40 @@ describe RSpec::Parameterized do
|
|
159
208
|
|
160
209
|
with_them do
|
161
210
|
it "a plus b is answer" do
|
162
|
-
(a + b).
|
211
|
+
expect(a + b).to eq answer
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
if RUBY_VERSION >= "2.1"
|
217
|
+
describe "child 3 (Using TableSyntax)" do
|
218
|
+
using RSpec::Parameterized::TableSyntax
|
219
|
+
|
220
|
+
where(:a, :b, :answer) do
|
221
|
+
1 | 2 | 3
|
222
|
+
five | eight | 13
|
223
|
+
end
|
224
|
+
|
225
|
+
with_them do
|
226
|
+
it "a plus b is answer" do
|
227
|
+
expect(a + b).to eq answer
|
228
|
+
end
|
163
229
|
end
|
164
230
|
end
|
165
231
|
end
|
166
232
|
|
167
233
|
let(:eq_matcher) { eq(13) }
|
168
234
|
describe "child 3 (use matcher)" do
|
169
|
-
|
170
|
-
|
171
|
-
|
235
|
+
where(:a, :b, :matcher) do
|
236
|
+
[
|
237
|
+
[1 , 2 , eq(3) ],
|
238
|
+
[five , eight , eq_matcher],
|
239
|
+
]
|
172
240
|
end
|
173
241
|
|
174
242
|
with_them do
|
175
243
|
it "a plus b is answer" do
|
176
|
-
(a + b).
|
244
|
+
expect(a + b).to matcher
|
177
245
|
end
|
178
246
|
end
|
179
247
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-parameterized
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomykaira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04
|
11
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.13'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '2.13'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: parser
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +72,20 @@ dependencies:
|
|
66
72
|
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: binding_of_caller
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
name: rake
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,8 +114,12 @@ files:
|
|
94
114
|
- LICENSE
|
95
115
|
- README.md
|
96
116
|
- Rakefile
|
117
|
+
- gemfiles/rspec2.gemfile
|
118
|
+
- gemfiles/rspec3.gemfile
|
97
119
|
- lib/rspec-parameterized.rb
|
98
120
|
- lib/rspec/parameterized.rb
|
121
|
+
- lib/rspec/parameterized/table.rb
|
122
|
+
- lib/rspec/parameterized/table_syntax.rb
|
99
123
|
- lib/rspec/parameterized/version.rb
|
100
124
|
- rspec-parameterized.gemspec
|
101
125
|
- spec/parametarized_spec.rb
|