yard-cucumber 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.1.4 / 2011-10-10
2
+
3
+ * Support for multiple scenario outlines (Thanks @jmerrifield)
4
+
1
5
  === 2.1.3 / 2011-09-24
2
6
 
3
7
  * Support for Gherkin ~ 2.5 (Thanks @turboladen)
@@ -77,4 +77,18 @@ Feature: Displaying Scenario Outlines
77
77
  And I expect <denomination> to be replaced by the example denomination
78
78
 
79
79
  Examples:
80
- | name | price | denomination |
80
+ | name | price | denomination |
81
+
82
+ Scenario Outline: Multiple Example Table
83
+ Given that <Customer> is a valid customer
84
+ And that the product, named '<Product>', is a valid product
85
+ When the customer has purchased the product
86
+ Then I expect the customer to be a member of the '<Product>' group
87
+
88
+ Examples: Example group A
89
+ | Customer | Product |
90
+ | Customer A | Product A |
91
+
92
+ Examples: Example group B
93
+ | Customer | Product |
94
+ | Customer B | Product A |
@@ -0,0 +1,15 @@
1
+ Feature: My Feature
2
+
3
+ Scenario Outline: Multiple Example Table
4
+ Given that <Customer> is a valid customer
5
+ And that the product, named '<Product>', is a valid product
6
+ When the customer has purchased the product
7
+ Then I expect the customer to be a member of the '<Product>' group
8
+
9
+ Examples: Example group A
10
+ | Customer | Product |
11
+ | Customer A | Product A |
12
+
13
+ Examples: Example group B
14
+ | Customer | Product |
15
+ | Customer B | Product A |
@@ -0,0 +1,11 @@
1
+ #
2
+ # @see https://github.com/burtlo/yard-cucumber/issues/18
3
+ #
4
+ CustomerUsageBehavior = Struct.new(:weight, :days, :time, :location, :other_party, :usage_type, :direction, :quantity)
5
+
6
+
7
+ class CustomerProfile
8
+ def generate_winner(max=@total_weight)
9
+ # blah
10
+ end
11
+ end
@@ -186,16 +186,24 @@ module Cucumber
186
186
  #
187
187
  def examples(examples)
188
188
  #log.debug "EXAMPLES"
189
-
190
- @step_container.examples = { :keyword => examples.keyword,
189
+
190
+ example = YARD::CodeObjects::Cucumber::ScenarioOutline::Examples.new(:keyword => examples.keyword,
191
191
  :name => examples.name,
192
192
  :line => examples.line,
193
193
  :comments => examples.comments.map{|comment| comment.value}.join("\n"),
194
- :rows => matrix(examples.rows) }
194
+ :rows => matrix(examples.rows))
195
+
196
+
197
+ # add the example to the step containers list of examples
195
198
 
196
- # For each example generate a scenario and steps
197
-
198
- @step_container.example_data.length.times do |row_index|
199
+ @step_container.examples << example
200
+
201
+ # For each example data row we want to generate a new scenario using our
202
+ # current scenario as the template.
203
+
204
+ example.data.length.times do |row_index|
205
+
206
+ # Generate a copy of the scenario.
199
207
 
200
208
  scenario = YARD::CodeObjects::Cucumber::Scenario.new(@step_container,"example_#{@step_container.scenarios.length + 1}") do |s|
201
209
  s.comments = @step_container.comments
@@ -205,6 +213,8 @@ module Cucumber
205
213
  s.value = "#{@step_container.value} (#{@step_container.scenarios.length + 1})"
206
214
  end
207
215
 
216
+ # Generate a copy of the scenario steps.
217
+
208
218
  @step_container.steps.each do |step|
209
219
  step_instance = YARD::CodeObjects::Cucumber::Step.new(scenario,step.line_number) do |s|
210
220
  s.keyword = step.keyword.dup
@@ -215,23 +225,29 @@ module Cucumber
215
225
  s.table = clone_table(step.table) if step.has_table?
216
226
  end
217
227
 
218
- @step_container.example_values_for_row(row_index).each do |key,text|
228
+ # Look at the particular data for the example row and do a simple
229
+ # find and replace of the <key> with the associated values.
230
+
231
+ example.values_for_row(row_index).each do |key,text|
219
232
  text ||= "" #handle empty cells in the example table
220
233
  step_instance.value.gsub!("<#{key}>",text)
221
234
  step_instance.text.gsub!("<#{key}>",text) if step_instance.has_text?
222
235
  step_instance.table.each{|row| row.each{|col| col.gsub!("<#{key}>",text)}} if step_instance.has_table?
223
236
  end
224
-
237
+
238
+ # Connect these steps that we created to the scenario we created
239
+ # and then add the steps to the scenario created.
240
+
225
241
  step_instance.scenario = scenario
226
242
  scenario.steps << step_instance
227
243
  end
228
244
 
229
- # Scenario instances of an outline link to the feature but are not linked from the feature
230
- # @feature.scenarios << scenario
231
-
245
+ # Add the scenario to the list of scenarios maintained by the feature
246
+ # and add the feature to the scenario
247
+
232
248
  scenario.feature = @feature
233
249
  @step_container.scenarios << scenario
234
-
250
+
235
251
  end
236
252
 
237
253
  end
@@ -261,6 +277,8 @@ module Cucumber
261
277
  rubify(step.rows)
262
278
  end
263
279
 
280
+ log.debug "Step: #{multiline_arg}"
281
+
264
282
  case(multiline_arg)
265
283
  when gherkin_multiline_string_class
266
284
  @table_owner.text = multiline_arg.value
@@ -9,32 +9,40 @@
9
9
  <div class="outline">
10
10
 
11
11
  <% if @scenario.examples? %>
12
- <div class="keyword"> <%= h @scenario.example_keyword %></div>
13
- <table>
14
- <thead>
15
- <tr>
16
- <% @scenario.example_headers.each_with_index do |header,header_index| %>
17
- <th><%= h(header) %></th>
12
+
13
+ <% @scenario.examples.each_with_index do |example,example_index| %>
14
+ <div class="keyword">
15
+ <%= h example.keyword %><%= example.name != "" ? ':' : '' %>
16
+ </div>
17
+ <div class="example-group-name"><%= h example.name %></div>
18
+ <br style="clear: both;"/>
19
+ <table>
20
+ <thead>
21
+ <tr>
22
+ <% example.headers.each_with_index do |header,header_index| %>
23
+ <th><%= h(header) %></th>
24
+ <% end %>
25
+ </tr>
26
+ </thead>
27
+ <% unless example.data.empty? %>
28
+ <% example.data.each_with_index do |row,row_index| %>
29
+ <tr class="<%= (row_index + 1) % 2 == 0 ? "even example#{example_index+1}-#{row_index +1}" : "odd example#{example_index+1}-#{row_index +1}" %>">
30
+ <% row.each_with_index do |column,column_index| %>
31
+ <td><%= h(column.to_s.strip) %></td>
32
+ <% end %>
33
+ </tr>
34
+ <% end %>
35
+ <% else %>
36
+ <!-- Scenario Outline example table is empty -->
37
+ <tr class="odd">
38
+ <td colspan="<%= example.headers.length %>" style="text-align: center;">
39
+ No Examples Defined
40
+ </td>
41
+ </tr>
18
42
  <% end %>
19
- </tr>
20
- </thead>
21
- <% unless @scenario.example_data.empty? %>
22
- <% @scenario.example_data.each_with_index do |row,row_index| %>
23
- <tr class="<%= (row_index + 1) % 2 == 0 ? "even example#{row_index +1}" : "odd example#{row_index +1}" %>">
24
- <% row.each_with_index do |column,column_index| %>
25
- <td><%= h(column.to_s.strip) %></td>
26
- <% end %>
27
- </tr>
28
- <% end %>
29
- <% else %>
30
- <!-- Scenario Outline example table is empty -->
31
- <tr class="odd">
32
- <td colspan="<%= @scenario.example_headers.length %>" style="text-align: center;">
33
- No Examples Defined
34
- </td>
35
- </tr>
36
- <% end %>
37
- </table>
43
+ </table>
44
+ <% end %>
45
+
38
46
  <% else %>
39
47
  <div class="keyword">No Example Table Defined</div>
40
48
  <div class="keyword suggestion developer">[!] Did you mean to create a Scenario?</div>
@@ -123,11 +123,19 @@ div.undefined { padding: 6px; }
123
123
  margin-left: 40px;
124
124
  }
125
125
  .outline .keyword {
126
+ float: left;
127
+ margin-top: 20px;
126
128
  padding: 4px;
127
129
  font-weight: bold;
128
130
  font-size: 16px;
129
131
  }
130
-
132
+ .outline .example-group-name {
133
+ float: left;
134
+ margin-top: 20px;
135
+ padding: 4px 4px 4px 20px;
136
+ font-size: 14px;
137
+ color: #343332;
138
+ }
131
139
  .multiline table tr, .outline table tr {
132
140
  padding: 4px;
133
141
  }
@@ -13,7 +13,7 @@ module YARD::CodeObjects::Cucumber
13
13
  @steps = []
14
14
  @tags = []
15
15
  @scenarios = []
16
- @examples = {}
16
+ @examples = []
17
17
  end
18
18
 
19
19
  def background?
@@ -25,40 +25,49 @@ module YARD::CodeObjects::Cucumber
25
25
  end
26
26
 
27
27
  def examples?
28
- !@examples[:rows].nil?
29
- end
30
-
31
- def example_keyword
32
- @examples[:keyword]
28
+ @examples.find {|example| example.rows }
33
29
  end
34
30
 
35
- def example_headers
36
- @examples[:rows].first
37
- end
38
31
 
39
- def example_data
40
- return "" unless @examples[:rows]
41
- @examples[:rows][1..-1]
42
- end
32
+ class Examples
33
+
34
+ attr_accessor :name, :line, :keyword, :comments, :rows
35
+
36
+ # The first row of the rows contains the headers for the table
37
+ def headers
38
+ rows.first
39
+ end
40
+
41
+ # The data of the table starts at the second row. When there is no data then
42
+ # return a empty string.
43
+ def data
44
+ rows ? rows[1..-1] : ""
45
+ end
46
+
47
+ def values_for_row(row)
48
+ hash = {}
43
49
 
44
- def example_values_for_row(row)
45
- hash = {}
50
+ headers.each_with_index do |header,index|
51
+ hash[header] = data[row][index]
52
+ end
46
53
 
47
- example_headers.each_with_index do |header,index|
48
- hash[header] = example_data[row][index]
54
+ hash
49
55
  end
56
+
57
+ def to_hash
58
+ hash = {}
50
59
 
51
- hash
52
- end
53
-
54
- def example_hash
55
- hash = {}
60
+ rows.each_with_index do |header,index|
61
+ hash[header] = rows.collect {|row| row[index] }
62
+ end
63
+
64
+ hash
65
+ end
56
66
 
57
- @examples[:rows].each_with_index do |header,index|
58
- hash[header] = @examples[:rows].collect {|row| row[index] }
67
+ def initialize(parameters = {})
68
+ parameters.each {|key,value| send("#{key.to_sym}=",value) if respond_to? "#{key.to_sym}=" }
59
69
  end
60
70
 
61
- hash
62
71
  end
63
72
 
64
73
  end
data/lib/yard-cucumber.rb CHANGED
@@ -4,7 +4,7 @@ require 'gherkin/formatter/tag_count_formatter'
4
4
 
5
5
 
6
6
  module CucumberInTheYARD
7
- VERSION = '2.1.3'
7
+ VERSION = '2.1.4'
8
8
  end
9
9
 
10
10
  require File.dirname(__FILE__) + "/yard/code_objects/cucumber/base.rb"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yard-cucumber
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.3
5
+ version: 2.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Franklin Webber
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-24 00:00:00 Z
13
+ date: 2011-10-10 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gherkin
@@ -68,9 +68,11 @@ files:
68
68
  - example/french.feature
69
69
  - example/scenario.feature
70
70
  - example/scenario_outline.feature
71
+ - example/scenario_outline_multi.feature
71
72
  - example/step_definitions/example.step.rb
72
73
  - example/step_definitions/first.step.rb
73
74
  - example/step_definitions/french_steps.rb
75
+ - example/step_definitions/struct.rb
74
76
  - example/step_definitions/support/env.rb
75
77
  - example/step_definitions/support/env_support.rb
76
78
  - example/step_definitions/support/support.rb
@@ -139,7 +141,7 @@ homepage: http://github.com/burtlo/yard-cucumber
139
141
  licenses: []
140
142
 
141
143
  post_install_message: "\n\
142
- (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n\n Thank you for installing yard-cucumber 2.1.3 / 2011-09-24.\n \n Changes:\n \n * Support for Gherkin ~ 2.5 (Thanks @turboladen)\n \n\n\
144
+ (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n\n Thank you for installing yard-cucumber 2.1.4 / 2011-10-10.\n \n Changes:\n \n * Support for multiple scenario outlines (Thanks @jmerrifield)\n \n\n\
143
145
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n\n"
144
146
  rdoc_options:
145
147
  - --charset=UTF-8