cucumber-in-the-yard 1.3 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/History.txt +24 -0
  2. data/Manifest +54 -41
  3. data/README.md +45 -1
  4. data/Rakefile +4 -3
  5. data/cucumber-in-the-yard.gemspec +5 -5
  6. data/example/{example.step.rb → step_definitions/example.step.rb} +0 -0
  7. data/example/step_definitions/support/env.rb +0 -0
  8. data/example/step_definitions/support/env_support.rb +0 -0
  9. data/example/step_definitions/support/support.rb +0 -0
  10. data/features/definitions/city_step.rb +89 -0
  11. data/features/definitions/test.setup.and.teardown.rb +27 -0
  12. data/features/features.feature +44 -0
  13. data/lib/city.rb +20 -11
  14. data/lib/cucumber/city_builder.rb +60 -55
  15. data/lib/templates/default/feature/html/background.erb +92 -0
  16. data/lib/templates/default/feature/html/feature.erb +22 -0
  17. data/lib/templates/default/feature/html/no_steps_defined.erb +1 -0
  18. data/lib/templates/default/feature/html/outline.erb +19 -0
  19. data/lib/templates/default/feature/html/pystring.erb +3 -0
  20. data/lib/templates/default/feature/html/scenario.erb +43 -0
  21. data/lib/templates/default/feature/html/steps.erb +34 -0
  22. data/lib/templates/default/feature/html/table.erb +20 -0
  23. data/lib/templates/default/feature/setup.rb +28 -0
  24. data/lib/{yard/templates → templates}/default/fulldoc/html/css/common.css +0 -0
  25. data/lib/{yard/templates → templates}/default/fulldoc/html/full_list.erb +0 -0
  26. data/lib/templates/default/fulldoc/html/full_list_features.erb +7 -0
  27. data/lib/templates/default/fulldoc/html/full_list_requirements.erb +1 -0
  28. data/lib/templates/default/fulldoc/html/full_list_scenarios.erb +8 -0
  29. data/lib/{yard/templates → templates}/default/fulldoc/html/full_list_stepdefinitions.erb +2 -2
  30. data/lib/{yard/templates → templates}/default/fulldoc/html/full_list_steps.erb +0 -0
  31. data/lib/templates/default/fulldoc/html/full_list_tags.erb +8 -0
  32. data/lib/{yard/templates → templates}/default/fulldoc/html/index.erb +0 -0
  33. data/lib/{yard/templates → templates}/default/fulldoc/html/js/cucumber.js +1 -1
  34. data/lib/templates/default/fulldoc/html/setup.rb +56 -0
  35. data/lib/{yard/templates → templates}/default/layout/html/headers.erb +0 -0
  36. data/lib/{yard/templates → templates}/default/layout/html/search.erb +0 -0
  37. data/lib/{yard/templates → templates}/default/scenario/html/scenario.erb +0 -0
  38. data/lib/{yard/templates → templates}/default/scenario/setup.rb +0 -0
  39. data/lib/templates/default/steptransformers/html/stepdefinition.erb +38 -0
  40. data/lib/templates/default/steptransformers/html/steptransformers.erb +7 -0
  41. data/lib/templates/default/steptransformers/setup.rb +17 -0
  42. data/lib/templates/default/tag/html/feature.erb +23 -0
  43. data/lib/templates/default/tag/html/scenario.erb +21 -0
  44. data/lib/templates/default/tag/html/tag.erb +18 -0
  45. data/lib/templates/default/tag/setup.rb +5 -0
  46. data/lib/yard/code_objects/{base.rb → cucumber/base.rb} +3 -9
  47. data/lib/yard/code_objects/{feature.rb → cucumber/feature.rb} +1 -1
  48. data/lib/yard/code_objects/cucumber/namespace_object.rb +18 -0
  49. data/lib/yard/code_objects/{scenario.rb → cucumber/scenario.rb} +1 -1
  50. data/lib/yard/code_objects/{step.rb → cucumber/step.rb} +0 -0
  51. data/lib/yard/code_objects/cucumber/tag.rb +27 -0
  52. data/lib/yard/{extensions.rb → code_objects/namespace_object.rb} +11 -2
  53. data/lib/yard/code_objects/step_definition.rb +38 -0
  54. data/lib/yard/code_objects/step_transform.rb +14 -0
  55. data/lib/yard/handlers/{base.rb → cucumber/base.rb} +0 -0
  56. data/lib/yard/handlers/{feature_handler.rb → cucumber/feature_handler.rb} +3 -2
  57. data/lib/yard/handlers/step_definition_handler.rb +57 -0
  58. data/lib/yard/handlers/step_transform_handler.rb +21 -0
  59. data/lib/yard/parser/{feature.rb → cucumber/feature.rb} +0 -0
  60. data/lib/yard/parser/source_parser.rb +54 -0
  61. data/lib/yard/rake/city_task.rb +1 -1
  62. data/lib/yard/templates/helpers/base_helper.rb +20 -0
  63. metadata +105 -77
  64. data/lib/yard/code_objects/tags.rb +0 -55
  65. data/lib/yard/rb_extensions.rb +0 -156
  66. data/lib/yard/templates/default/feature/html/feature.erb +0 -245
  67. data/lib/yard/templates/default/feature/setup.rb +0 -5
  68. data/lib/yard/templates/default/fulldoc/html/full_list_features.erb +0 -10
  69. data/lib/yard/templates/default/fulldoc/html/full_list_scenarios.erb +0 -10
  70. data/lib/yard/templates/default/fulldoc/html/full_list_tagusages.erb +0 -10
  71. data/lib/yard/templates/default/fulldoc/html/setup.rb +0 -73
  72. data/lib/yard/templates/default/module/html/step_transforms.erb +0 -23
  73. data/lib/yard/templates/default/module/setup.rb +0 -5
  74. data/lib/yard/templates/default/steptransformers/html/stepdefinition.erb +0 -50
  75. data/lib/yard/templates/default/steptransformers/setup.rb +0 -5
  76. data/lib/yard/templates/default/tagusage/html/tagusage.erb +0 -65
  77. data/lib/yard/templates/default/tagusage/setup.rb +0 -5
  78. data/spec/city/feature_parser_spec_examples.rb +0 -153
  79. data/spec/city/gherkin_loader_spec.rb +0 -39
  80. data/spec/city/test.feature +0 -36
  81. data/spec/city/yard_handlers_cucumber_spec.rb +0 -24
  82. data/spec/city/yard_namespace_object_spec.rb +0 -8
  83. data/spec/city/yard_parser_cucumber_spec.rb +0 -215
  84. data/spec/city/yard_rb_extensions_spec.rb +0 -128
  85. data/spec/spec_helper.rb +0 -5
@@ -1,156 +0,0 @@
1
-
2
- module YARD::CodeObjects
3
-
4
-
5
- #
6
- # StepDefinitions, as implemented in a ruby file
7
- #
8
- class StepDefinitionObject < Base
9
- include Cucumber::LocationHelper
10
-
11
- attr_reader :keyword, :value, :compare_value, :source
12
- attr_accessor :constants, :steps
13
-
14
- def value=(value)
15
- @value = format_source(value)
16
- @constants = {}
17
- @steps = []
18
- end
19
-
20
- def compare_value
21
- base_value = value.gsub(/^\/|\/$/,'')
22
- @constants.each do |name,value|
23
- base_value.gsub!(/\#\{\s*#{name.to_s}\s*\}/,value.gsub(/^\/|\/$/,''))
24
- end
25
- base_value
26
- end
27
-
28
- def _value_constants(data=@value)
29
- #Hash[*data.scan(/\#\{([^\}]+)\}/).flatten.collect {|value| [value.strip,nil]}.flatten]
30
- data.scan(/\#\{([^\}]+)\}/).flatten.collect { |value| value.strip }
31
- end
32
-
33
- def constants=(value)
34
- value.each do |val|
35
- @constants[val.name.to_s] = val if val.respond_to?(:name) && val.respond_to?(:value)
36
- end
37
- end
38
-
39
- end
40
-
41
- class StepTransformersObject < Base
42
-
43
- attr_reader :source
44
- attr_accessor :definitions, :transforms
45
-
46
- def push(stepobject)
47
- if stepobject.is_a?(StepDefinitionObject)
48
- @definitions = [] unless @definitions
49
- @definitions << stepobject
50
- elsif stepobject.ia_a?(StepTransformObject)
51
- @transforms = [] unless @transforms
52
- @transforms << stepobject
53
- end
54
- end
55
-
56
- alias_method :<< , :push
57
-
58
-
59
- end
60
-
61
-
62
- #
63
- # Transforms
64
- #
65
- class StepTransformObject < Base
66
- include Cucumber::LocationHelper
67
-
68
- attr_reader :value
69
-
70
- def value=(value)
71
- @value = format_source(value)
72
- end
73
- end
74
-
75
-
76
-
77
-
78
- end
79
-
80
-
81
- class StepDefinitionHandler < YARD::Handlers::Ruby::Legacy::Base
82
- MATCH = /^((When|Given|And|Then)\s*(\/[^\/]+\/).+)$/
83
- handles MATCH
84
-
85
- @@unique_name = 0
86
-
87
- def process
88
-
89
- keyword = statement.tokens.to_s[MATCH,2]
90
- step_definition = statement.tokens.to_s[MATCH,3]
91
- @@unique_name = @@unique_name + 1
92
-
93
- stepdef_instance = StepDefinitionObject.new(namespace, "StepDefinition_#{@@unique_name}") do |o|
94
- o.source = "#{keyword} #{step_definition} do #{statement.block.to_s =~ /^\s*\|.+/ ? '' : "\n "}#{statement.block.to_s}\nend"
95
- o.value = step_definition
96
- o.keyword = keyword
97
- end
98
-
99
- begin
100
- # Look for all constants within the step definitions
101
- stepdef_instance.constants = stepdef_instance._value_constants.each do |stepdef_constant|
102
- owner.constants.each do |constant|
103
- if stepdef_constant.to_sym == constant.name
104
- #log.debug "Replacing #{constant.name} with its value in the step definition #{stepdef_instance.value}"
105
- stepdef_instance.constants[constant.name] = unpack_constants(constant.value)
106
- end
107
- end
108
- end
109
-
110
- rescue Exception => e
111
- log.error "Failed to link step definition to constants. This will make step definition to step linking impossible if constants are present. #{e}"
112
- end
113
-
114
-
115
- obj = register stepdef_instance
116
-
117
-
118
- parse_block :owner => obj
119
- rescue YARD::Handlers::NamespaceMissingError
120
- end
121
-
122
-
123
- def unpack_constants(constant_value)
124
- constant_value.scan(/\#\{([^\}]+)\}/).flatten.collect { |value| value.strip }.each do |inner_constant|
125
- inner_constant_match = owner.constants.find {|constant| constant.name.to_s == inner_constant }
126
- if inner_constant_match
127
- constant_value.gsub!(/\#\{#{inner_constant}\}/,unpack_constants(inner_constant_match.value))
128
- end
129
- end
130
-
131
- constant_value.gsub!(/^('|"|\/)|('|"|\/)$/,'')
132
- constant_value
133
- end
134
-
135
- end
136
-
137
-
138
- class StepTransformHandler < YARD::Handlers::Ruby::Legacy::Base
139
- MATCH = /^Transform\s*(\/[^\/]+\/).+$/
140
- handles MATCH
141
-
142
- @@unique_name = 0
143
-
144
- def process
145
- transformDefinition = statement.tokens.to_s[MATCH,1]
146
- #log.debug "#process - transformDefinition = #{transformDefinition}"
147
- @@unique_name = @@unique_name + 1
148
-
149
- obj = register StepTransformObject.new(namespace, "StepTransform_#{@@unique_name}") {|o| o.source = statement.block.to_s ; o.value = transformDefinition }
150
-
151
- parse_block :owner => obj
152
-
153
- rescue YARD::Handlers::NamespaceMissingError
154
- end
155
- end
156
-
@@ -1,245 +0,0 @@
1
- <div class="feature">
2
- <div class="title">
3
- <span class="pre"><%= @feature.keyword %>:</span>
4
- <span class="name"><%= @feature.value %></span>
5
- </div>
6
-
7
- <div class="meta">
8
- <div class="file"><%= h(@feature.file) %></div>
9
- <div class="tags">
10
- <% @feature.tags.each do |tag| %>
11
- <a href="tag_<%= tag.value %>.html"><%= tag.value %></a>
12
- <% end %>
13
- </div>
14
- </div>
15
-
16
- <div class="description">
17
- <%= @feature.description %>
18
- </div>
19
-
20
- <% if @feature.background %>
21
-
22
- <script type="text/javascript" charset="utf-8">
23
- $(function() {
24
- $('#background .toggle').click(function() {
25
- $("#backgroundSteps").toggle('blind');
26
-
27
- var stateIndicator = $('#background a.toggle')[0]
28
-
29
- stateIndicator.innerHTML = (stateIndicator.innerHTML === '+' ? '-' : '+');
30
- return false;
31
- });
32
- });
33
- </script>
34
-
35
- <div id="background">
36
- <div class="title">
37
- <a class="toggle">-</a>
38
- <span class="pre">Background</span>
39
- </div>
40
- <% unless @feature.background.description.empty? %>
41
- <div class="description">
42
- <%= h(@feature.background.description) %>
43
- </div>
44
- <% end %>
45
-
46
- <!-- Background and scenario should have the same display with some minor changes -->
47
-
48
- <div id="backgroundSteps" class="steps">
49
- <% if @feature.background.steps %>
50
- <% @feature.background.steps.each_with_index do |step,index| %>
51
- <div <%= "id='backgroundStep#{index}'" %> class="step <%= (index + 1) % 2 == 0 ? 'even' : 'odd' %>">
52
- <span class="predicate"><%= step.keyword %></span>
53
-
54
- <% if step.definition %>
55
- <script type="text/javascript" charset="utf-8">
56
- $('<%= "#backgroundStep#{index}" %>').hover(
57
- function () { $('<%= "#backgroundStep#{index} div.details" %>').toggle('slide'); },
58
- function () { $('<%= "#backgroundStep#{index} div.details" %>').toggle('slide'); }
59
- );
60
-
61
- $('<%= "#backgroundStep#{index} div.details" %>').show();
62
-
63
- </script>
64
- <span class="defined">
65
- <a href="steptransformers.html#<%= step.definition.name %>"><%= h(step.value) %></a>
66
- <div class="details" style="display: none;">
67
- (<%= h( step.definition.location ) %>)
68
- </div>
69
- </span>
70
- <% else %>
71
- <span class="undefined"><%= h(step.value) %></span>
72
- <% end %>
73
-
74
- </div>
75
-
76
- <% if step.has_table? %>
77
- <div class="multiline">
78
- <table style="">
79
-
80
- <thead>
81
- <tr>
82
- <% step.table.first.each_with_index do |column,column_index| %>
83
- <th class="<%= (column_index + 1) % 2 == 0 ? 'even' : 'odd' %>"><%= h(column.strip) %></th>
84
- <% end %>
85
- </tr>
86
- </thead>
87
-
88
- <% step.table[1..-1].each_with_index do |row,row_index| %>
89
- <tr class="<%= (row_index + 1) % 2 == 0 ? 'even' : 'odd' %>">
90
- <% row.each_with_index do |column,column_index| %>
91
- <td><%= h(column.strip) %></td>
92
- <% end %>
93
- </tr>
94
- <% end %>
95
- </table>
96
- </div>
97
- <% end %>
98
-
99
- <% if step.has_text? %>
100
- <div class="text">
101
- <%= h(step.text) %>
102
- </div>
103
- <% end %>
104
-
105
-
106
- <% end %>
107
- <% else %>
108
- <span>No Steps Defined</span>
109
- <% end %>
110
- </div>
111
-
112
- </div>
113
- <% end %>
114
-
115
- <% if @feature.scenarios %>
116
- <% @feature.scenarios.each_with_index do |scenario,scenario_index| %>
117
-
118
- <script type="text/javascript" charset="utf-8">
119
- $(function() {
120
- $('#scenario<%=scenario_index%> .toggle').click(function() {
121
- $("#scenario<%=scenario_index%>Steps").toggle('blind');
122
-
123
- var stateIndicator = $('#scenario<%=scenario_index%> a.toggle')[0]
124
-
125
- stateIndicator.innerHTML = (stateIndicator.innerHTML === '+' ? '-' : '+');
126
- return false;
127
- });
128
- });
129
- </script>
130
-
131
- <div <%= "id='scenario#{scenario_index}'" %> class="scenario">
132
- <div class="title">
133
- <a class="toggle">-</a>
134
- <span class="pre">Scenario<%= !scenario.examples.empty? ? " Outline" : "" %>:</span>
135
- <span class="name"><%= h(scenario.value) %></span>
136
- </div>
137
- <div class="meta">
138
- <div class="file">Line: <%= scenario.files.first.last %></div>
139
- <% unless scenario.tags.empty? %>
140
- <div class="tags">
141
- <% scenario.tags.each do |tag| %>
142
- <a href="tag_<%= tag.value %>.html"><%= tag.value %></a>
143
- <% end %>
144
- </div>
145
- <% end%>
146
- </div>
147
- <% unless scenario.description.empty? %>
148
- <div class="description">
149
- <%= h(scenario.description) %>
150
- </div>
151
- <% end %>
152
-
153
- <div <%= "id='scenario#{scenario_index}Steps'" %> class="steps">
154
- <% if scenario.steps %>
155
- <% scenario.steps.each_with_index do |step,index| %>
156
- <div <%= "id='scenario#{scenario_index}Step#{index}'" %> class="step <%= (index + 1) % 2 == 0 ? 'even' : 'odd' %>">
157
- <span class="predicate"><%= step.keyword %></span>
158
-
159
- <% if step.definition %>
160
- <script type="text/javascript" charset="utf-8">
161
- $('<%= "#scenario#{scenario_index}Step#{index}" %>').hover(
162
- function () { $('<%= "#scenario#{scenario_index}Step#{index} div.details" %>').toggle('slide'); },
163
- function () { $('<%= "#scenario#{scenario_index}Step#{index} div.details" %>').toggle('slide'); }
164
- );
165
-
166
- $('<%= "#scenario#{scenario_index}Step#{index} div.details" %>').show();
167
-
168
- </script>
169
- <span class="defined">
170
- <a href="steptransformers.html#<%= step.definition.name %>"><%= h(step.value) %></a>
171
- <div class="details" style="display: none;">
172
- (<%= h("#{step.definition.files.first.first}:#{step.definition.files.first.last}") %>)
173
- </div>
174
- </span>
175
- <% else %>
176
- <span class="undefined"><%= h(step.value) %></span>
177
- <% end %>
178
-
179
- </div>
180
-
181
- <% if step.has_table? %>
182
- <div class="multiline">
183
- <table style="">
184
-
185
- <thead>
186
- <tr>
187
- <% step.table.first.each_with_index do |column,column_index| %>
188
- <th class="<%= (column_index + 1) % 2 == 0 ? 'even' : 'odd' %>"><%= h(column.strip) %></th>
189
- <% end %>
190
- </tr>
191
- </thead>
192
-
193
- <% step.table[1..-1].each_with_index do |row,row_index| %>
194
- <tr class="<%= (row_index + 1) % 2 == 0 ? 'even' : 'odd' %>">
195
- <% row.each_with_index do |column,column_index| %>
196
- <td><%= h(column.strip) %></td>
197
- <% end %>
198
- </tr>
199
- <% end %>
200
- </table>
201
- </div>
202
- <% end %>
203
-
204
- <% if step.has_text? %>
205
- <div class="text">
206
- <%= h(step.text) %>
207
- </div>
208
- <% end %>
209
-
210
-
211
-
212
- <% end %>
213
- <% else %>
214
- <span>No Steps Defined</span>
215
- <% end %>
216
- </div>
217
-
218
- <% if scenario.outline? %>
219
- <div class="outline">
220
- <div class="keyword"> <%= h(scenario.example_keyword) %> </div>
221
- <table>
222
- <thead>
223
- <tr>
224
- <% scenario.example_headers.each_with_index do |header,header_index| %>
225
- <th><%= h(header) %></th>
226
- <% end %>
227
- </tr>
228
- </thead>
229
- <% scenario.example_data.each_with_index do |row,row_index| %>
230
- <tr class="<%= (row_index + 1) % 2 == 0 ? 'even' : 'odd' %>" >
231
- <% row.each_with_index do |column,column_index| %>
232
- <td><%= h(column.to_s.strip) %></td>
233
- <% end %>
234
- </tr>
235
- <% end %>
236
- </table>
237
- </div>
238
- <% end %>
239
-
240
- </div>
241
- <% end %>
242
- <% end %>
243
-
244
- </div>
245
-
@@ -1,5 +0,0 @@
1
- def init
2
- super
3
- sections.push :feature
4
- @feature = object
5
- end
@@ -1,10 +0,0 @@
1
- <% n = 1 %>
2
- <% @items.each do |feature| %>
3
- <li class="r<%= n %>">
4
- <span class='object_link'>
5
- <a href="<%= "#{feature.name}.html" %>"><%= h(feature.value) %></a>
6
- </span>
7
- <span class="">(<%= h(feature.file) %>)<span>
8
- </li>
9
- <% n = n == 2 ? 1 : 2 %>
10
- <% end %>
@@ -1,10 +0,0 @@
1
- <% n = 1 %>
2
- <% @items.each do |scenario| %>
3
- <li class="r<%= n %>">
4
- <span class='object_link'>
5
- <a href="<%= "#{scenario.feature.name}.html" %>"><%= h(scenario.value) %></a>
6
- </span>
7
- <span class="">(<%= h(scenario.location) %>)<span>
8
- </li>
9
- <% n = n == 2 ? 1 : 2 %>
10
- <% end %>
@@ -1,10 +0,0 @@
1
- <% n = 1 %>
2
- <% @items.each do |usage| %>
3
- <li class="r<%= n %>">
4
- <span class='object_link'>
5
- <a href="<%= "#{usage.name}.html" %>"><%= h(usage.value) %></a>
6
- </span>
7
- <small><%= usage.total_scenario_count %></small>
8
- </li>
9
- <% n = n == 2 ? 1 : 2 %>
10
- <% end %>
@@ -1,73 +0,0 @@
1
- include YARD::Templates::Helpers::HtmlHelper
2
-
3
- def init
4
- super
5
- asset("js/cucumber.js",file("js/cucumber.js",true))
6
-
7
- @features = Registry.all(:feature)
8
-
9
- if @features
10
- @features.each {|feature| serialize(feature) }
11
- generate_full_list(@features)
12
- end
13
-
14
-
15
- @tags = find_unique_tags(@tags)
16
-
17
- if @tags
18
- @tags.each { |tag,tag_objects| serialize_tags(tag_objects) }
19
-
20
- @tagusage = @tags.values.sort {|x,y| y.total_scenario_count <=> x.total_scenario_count }
21
- generate_full_list(@tagusage,"Tag Usage") if @tagusage
22
- end
23
-
24
- @scenarios = Registry.all(:scenario).find_all {|scenario| !scenario.background? }
25
- generate_full_list(@scenarios) if @scenarios
26
-
27
- @steps = Registry.all(:step)
28
- generate_full_list(@steps) if @steps
29
-
30
- @step_definitions = Registry.all(:stepdefinition)
31
-
32
- if @step_definitions
33
- generate_full_list(@step_definitions,"Step Definition")
34
- @step_transformers = YARD::CodeObjects::StepTransformersObject.new(:root,"steptransformers")
35
- @step_definitions.each {|stepdef| @step_transformers << stepdef }
36
- serialize(@step_transformers)
37
- end
38
-
39
-
40
- end
41
-
42
- def generate_full_list(objects,friendly_name=nil)
43
- if !objects.empty?
44
- @items = objects
45
- @list_type = "#{objects.first.type.to_s}s"
46
- @list_title = "#{friendly_name || objects.first.type.to_s.capitalize} List"
47
- asset("#{objects.first.type}_list.html",erb(:full_list))
48
- else
49
- log.warn "Full List: Failed to create a list because the objects array is empty."
50
- end
51
- end
52
-
53
- def serialize_tags(tags)
54
- options[:object] = tags
55
- Templates::Engine.with_serializer("#{tags.name}.html", options[:serializer]) do
56
- T('layout').run(options)
57
- end
58
- end
59
-
60
- def find_unique_tags(tags)
61
-
62
- tags_hash = {}
63
-
64
- Registry.all(:tag).each do |tag|
65
- unless tags_hash[tag.value]
66
- tags_hash[tag.value] = YARD::CodeObjects::Cucumber::TagUsage.new(:root,"tag_#{tag.value}") {|t| t.value = tag.value }
67
- end
68
- tags_hash[tag.value.to_s] << tag
69
- end
70
-
71
- tags_hash
72
- end
73
-