rspec-parameterized 0.2.0 → 0.3.0

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
2
  SHA1:
3
- metadata.gz: aff30f7544b6df92c5886fa92c44d40f49c602ce
4
- data.tar.gz: 31b86112cf15b6540876b2d31f2c5a84ef701889
3
+ metadata.gz: 5b1e47f21d0fa2e6268bb78df5922518f9adb747
4
+ data.tar.gz: 8897c535ddd9f8fec343989981e1939c43b32ddf
5
5
  SHA512:
6
- metadata.gz: 5edaf41862d9f151f14364f981ea9c44423b1134956ee788e1675ce9f3902a2932ddced532d6a588a59be3527c9212114910d144d29588a494a40a39edfefa39
7
- data.tar.gz: f51339e6c2bf33e5d579f044199515bb92600043a8975ea981512d4ceb3f32969d9eff12d12d63af810524f9a589305915093806e39cff28462734927228fdde
6
+ metadata.gz: febab443a471a5a06141f9b3d995c68d19d62ac9eabc3a892114f777910f5bcf9403153c1cf4ac6d80b22b23c7feb091ada7fb3d004d8fd99c3997ef33a3a140
7
+ data.tar.gz: 4fdb021af367becb415dfa560b530a34b8003c774b40c9fe75728c1d2ee3a0959b3cfddb2ab872ec1a46f220762fcf27a9bab9926dcd0fe35afa65549711a7a8
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
1
  sudo: false
2
2
  rvm:
3
- - 2.1
4
3
  - 2.2
4
+ - 2.3.0
5
5
 
6
6
  gemfile:
7
7
  - gemfiles/rspec2.gemfile
8
- - gemfiles/rspec3.gemfile
9
- - gemfiles/rspec3.2.gemfile
10
8
  - gemfiles/rspec3.3.gemfile
9
+ - gemfiles/rspec3.4.gemfile
data/README.md CHANGED
@@ -18,6 +18,14 @@ describe "plus" do
18
18
  expect(a + b).to eq answer
19
19
  end
20
20
  end
21
+
22
+ with_them do
23
+ # Can browse parameters via `params` method in with_them block
24
+ # Can browse all parameters via `all_params` method in with_them block
25
+ it "#{params[:a]} + #{params[:b]} == #{params[:answer]}" do
26
+ expect(a + b).to eq answer
27
+ end
28
+ end
21
29
  end
22
30
 
23
31
  # Hash and Array Style
data/Rakefile CHANGED
@@ -11,17 +11,19 @@ begin
11
11
  end
12
12
 
13
13
  namespace :spec do
14
- %w(rspec2 rspec3 rspec3.2).each do |gemfile|
14
+ %w(rspec2 rspec3.3 rspec3.4).each do |gemfile|
15
15
  desc "Run Tests by #{gemfile}.gemfile"
16
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"
17
+ Bundler.with_clean_env do
18
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
19
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
20
+ end
19
21
  end
20
22
  end
21
23
 
22
24
  desc "Run All Tests"
23
25
  task :all do
24
- %w(rspec2 rspec3 rspec3.2).each do |gemfile|
26
+ %w(rspec2 rspec3.3 rspec3.4).each do |gemfile|
25
27
  Rake::Task["spec:#{gemfile}"].invoke
26
28
  end
27
29
  end
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rspec", "~> 3.2.0"
3
+ gem "rspec", "~> 3.4.0"
4
4
 
5
5
  gemspec path: "../"
@@ -10,10 +10,10 @@ module RSpec
10
10
  module ExampleGroupMethods
11
11
  # capsulize parameter attributes
12
12
  class Parameter
13
- attr_reader :arg_names, :table_format, :block
13
+ attr_reader :arg_names, :block
14
14
 
15
- def initialize(arg_names, table_format, &block)
16
- @arg_names, @table_format, @block = arg_names, table_format, block
15
+ def initialize(arg_names, &block)
16
+ @arg_names, @block = arg_names, block
17
17
  end
18
18
  end
19
19
 
@@ -43,31 +43,14 @@ module RSpec
43
43
  params = args[0]
44
44
  first, *rest = params.values
45
45
 
46
- set_parameters(params.keys, false) {
46
+ set_parameters(params.keys) {
47
47
  first.product(*rest)
48
48
  }
49
49
  else
50
- set_parameters(args, false, &b)
50
+ set_parameters(args, &b)
51
51
  end
52
52
  end
53
53
 
54
- # Set parameters to be bound in specs under this example group.
55
- # You can separate fields with | like a cucumber table.
56
- #
57
- # ## Example
58
- #
59
- # where_table(:a, :b, :answer) do
60
- # 1 | 2 | 3
61
- # 5 | 8 | 13
62
- # 0 | 0 | 0
63
- # end
64
- #
65
- def where_table(*args, &b)
66
- warn "deprecated: `where_table` method is deprecated. Please use `using RSpec::Parameterized::TableSyntax`"
67
- warn caller.first
68
- set_parameters(args, true, &b)
69
- end
70
-
71
54
  # Use parameters to execute the block.
72
55
  # The given block is converted into +describe+s for each parameter set.
73
56
  #
@@ -88,8 +71,8 @@ module RSpec
88
71
  end
89
72
 
90
73
  private
91
- def set_parameters(arg_names, table_format, &b)
92
- @parameter = Parameter.new(arg_names, table_format, &b)
74
+ def set_parameters(arg_names, &b)
75
+ @parameter = Parameter.new(arg_names, &b)
93
76
 
94
77
  if @parameterized_pending_cases
95
78
  @parameterized_pending_cases.each { |e|
@@ -98,68 +81,42 @@ module RSpec
98
81
  end
99
82
  end
100
83
 
101
- def separate_table_like_block(b)
102
- ast = b.to_ast
103
- inner_ast = ast.children[2]
104
- if inner_ast.type == :send
105
- lines = [inner_ast]
106
- else
107
- lines = inner_ast.children
108
- end
109
-
110
- lines.map do |node|
111
- if node.type == :send
112
- buf = []
113
- extract_value(node, buf)
114
- buf.reverse
115
- end
116
- end
117
- end
118
-
119
- def extract_value(node, buf)
120
- receiver, method, arg = node.children
121
-
122
- if method == :|
123
- buf << eval_source_fragment(Unparser.unparse(arg))
124
- end
125
-
126
- if receiver.is_a?(AST::Node) && receiver.type == :send && receiver.children[1] == :|
127
- extract_value(receiver, buf)
128
- else
129
- buf << eval_source_fragment(Unparser.unparse(receiver))
130
- end
131
- end
132
-
133
- def eval_source_fragment(source_fragment)
134
- instance = new # for evaluate let methods.
135
- if defined?(self.superclass::LetDefinitions)
136
- instance.extend self.superclass::LetDefinitions
137
- end
138
- instance.instance_eval(source_fragment)
139
- end
140
-
141
84
  def define_cases(parameter, *args, &block)
142
85
  instance = new # for evaluate let methods.
143
86
  if defined?(self.superclass::LetDefinitions)
144
87
  instance.extend self.superclass::LetDefinitions
145
88
  end
146
89
 
147
- if parameter.table_format
148
- param_sets = separate_table_like_block(parameter.block)
149
- else
150
- extracted = instance.instance_eval(&parameter.block)
151
- param_sets = extracted.is_a?(Array) ? extracted : extracted.to_params
152
- end
90
+ extracted = instance.instance_eval(&parameter.block)
91
+ param_sets = extracted.is_a?(Array) ? extracted : extracted.to_params
153
92
 
154
93
  # for only one parameters
155
94
  param_sets = param_sets.map { |x| Array[x] } if !param_sets[0].is_a?(Array)
156
95
 
157
- param_sets.each do |params|
158
- pairs = [parameter.arg_names, params].transpose
159
- pretty_params = pairs.map {|t| "#{t[0]}: #{params_inspect(t[1])}"}.join(", ")
96
+ param_sets.each do |param_set|
97
+ pairs = [parameter.arg_names, param_set].transpose.to_h
98
+ pretty_params = pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
160
99
  describe(pretty_params, *args) do
161
- pairs.each do |n|
162
- let(n[0]) { n[1] }
100
+ pairs.each do |name, val|
101
+ let(name) { val }
102
+ end
103
+
104
+ singleton_class.module_eval do
105
+ if respond_to?(:params)
106
+ warn "ExampleGroup.params method is overrided."
107
+ end
108
+
109
+ define_method(:params) do
110
+ pairs
111
+ end
112
+
113
+ if respond_to?(:all_params)
114
+ warn "ExampleGroup.all_params method is overrided."
115
+ end
116
+
117
+ define_method(:all_params) do
118
+ param_sets
119
+ end
163
120
  end
164
121
 
165
122
  module_eval(&block)
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Parameterized
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -26,6 +26,12 @@ describe RSpec::Parameterized do
26
26
  end
27
27
  end
28
28
 
29
+ with_them do
30
+ it "#{params[:a]} + #{params[:b]} == #{params[:answer]}" do
31
+ expect(a + b).to eq answer
32
+ end
33
+ end
34
+
29
35
  with_them pending: "PENDING" do
30
36
  it "should do additions" do
31
37
  expect(a + b).to == answer
@@ -60,20 +66,6 @@ describe RSpec::Parameterized do
60
66
  end
61
67
  end
62
68
 
63
- describe "table separated with pipe" do
64
- where_table(:a, :b, :answer) do
65
- 1 | 2 | 3
66
- "hello " | "world" | "hello world"
67
- [1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6]
68
- end
69
-
70
- with_them do
71
- it "a plus b is answer" do
72
- expect(a + b).to eq answer
73
- end
74
- end
75
- end
76
-
77
69
  if RUBY_VERSION >= "2.1"
78
70
  describe "table separated with pipe (using TableSyntax)" do
79
71
  using RSpec::Parameterized::TableSyntax
@@ -162,18 +154,6 @@ describe RSpec::Parameterized do
162
154
  end
163
155
  end
164
156
 
165
- context "when the table has only a row" do
166
- where_table(:a, :b, :answer) do
167
- 1 | 2 | 3
168
- end
169
-
170
- with_them do
171
- it "a plus b is answer" do
172
- expect(a + b).to eq answer
173
- end
174
- end
175
- end
176
-
177
157
  if RUBY_VERSION >= "2.1"
178
158
  context "when the table has only a row (using TableSyntax)" do
179
159
  using RSpec::Parameterized::TableSyntax
@@ -224,19 +204,6 @@ describe RSpec::Parameterized do
224
204
  end
225
205
  end
226
206
 
227
- describe "child 2 (where_table)" do
228
- where_table(:a, :b, :answer) do
229
- 1 | 2 | 3
230
- five | eight | 13
231
- end
232
-
233
- with_them do
234
- it "a plus b is answer" do
235
- expect(a + b).to eq answer
236
- end
237
- end
238
- end
239
-
240
207
  if RUBY_VERSION >= "2.1"
241
208
  describe "child 3 (Using TableSyntax)" do
242
209
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomykaira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -115,9 +115,8 @@ files:
115
115
  - README.md
116
116
  - Rakefile
117
117
  - gemfiles/rspec2.gemfile
118
- - gemfiles/rspec3.2.gemfile
119
118
  - gemfiles/rspec3.3.gemfile
120
- - gemfiles/rspec3.gemfile
119
+ - gemfiles/rspec3.4.gemfile
121
120
  - lib/rspec-parameterized.rb
122
121
  - lib/rspec/parameterized.rb
123
122
  - lib/rspec/parameterized/table.rb
@@ -145,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
144
  version: '0'
146
145
  requirements: []
147
146
  rubyforge_project:
148
- rubygems_version: 2.4.8
147
+ rubygems_version: 2.5.1
149
148
  signing_key:
150
149
  specification_version: 4
151
150
  summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem "rspec", ">= 3.0.0.rc1", "< 3.1"
4
-
5
- gemspec path: "../"