yard-cucumber 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +1 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +20 -17
  5. data/History.txt +13 -0
  6. data/README.md +10 -10
  7. data/example/scenario_outline.feature +8 -2
  8. data/example/step_definitions/example.step.rb +13 -0
  9. data/example/transform.feature +5 -0
  10. data/lib/cucumber/city_builder.rb +64 -15
  11. data/lib/templates/default/featuretags/html/namespace.erb +32 -4
  12. data/lib/templates/default/fulldoc/html/full_list_features.erb +1 -1
  13. data/lib/templates/default/fulldoc/html/full_list_tags.erb +1 -1
  14. data/lib/templates/default/fulldoc/html/js/cucumber.js +9 -0
  15. data/lib/templates/default/fulldoc/html/setup.rb +26 -4
  16. data/lib/templates/default/tag/html/alpha_table.erb +2 -1
  17. data/lib/yard-cucumber.rb +1 -0
  18. data/lib/yard-cucumber/version.rb +1 -1
  19. data/lib/yard/code_objects/cucumber/base.rb +1 -9
  20. data/lib/yard/code_objects/cucumber/feature.rb +7 -9
  21. data/lib/yard/code_objects/cucumber/namespace_object.rb +55 -49
  22. data/lib/yard/code_objects/cucumber/scenario.rb +6 -10
  23. data/lib/yard/code_objects/cucumber/scenario_outline.rb +16 -23
  24. data/lib/yard/code_objects/cucumber/step.rb +12 -9
  25. data/lib/yard/code_objects/cucumber/tag.rb +17 -13
  26. data/lib/yard/code_objects/step_definition.rb +3 -6
  27. data/lib/yard/code_objects/step_transform.rb +3 -6
  28. data/lib/yard/code_objects/step_transformer.rb +1 -4
  29. data/lib/yard/handlers/constant_transform_handler.rb +98 -0
  30. data/lib/yard/handlers/cucumber/feature_handler.rb +1 -1
  31. data/lib/yard/handlers/step_transform_handler.rb +22 -3
  32. data/yard-cucumber.gemspec +2 -2
  33. metadata +44 -26
@@ -10,7 +10,7 @@
10
10
  <div class="item" style="padding-left: 30px">
11
11
  <%= "<a class='toggle'></a>" unless feature.scenarios.empty? %>
12
12
  <%= linkify feature, feature.value %>
13
- <small><%= feature.location %></small>
13
+ <small style="display: inline;"><%= feature.total_scenarios %></small>
14
14
  </div>
15
15
 
16
16
  <% n = n == 'odd' ? 'even' : 'odd' %>
@@ -9,7 +9,7 @@
9
9
  <li class="<%= n %>">
10
10
  <div class="item" style="padding-left: 30px;">
11
11
  <%= linkify tag, tag.value %>
12
- <small style="display: inline;"><%= tag.all_scenarios.size %></small>
12
+ <small style="display: inline;"><%= tag.total_scenarios %></small>
13
13
  </div>
14
14
  </li>
15
15
  <% n = n == 'odd' ? 'even' : 'odd' %>
@@ -277,6 +277,15 @@ function displayQualifyingFeaturesAndScenarios(tags) {
277
277
 
278
278
  }
279
279
 
280
+ function updateScenarioCount() {
281
+ var count = 0;
282
+ $(".scenario:visible").each(function(index) {
283
+ count += parseInt($(this).attr("count"))
284
+ });
285
+ count_header = " (" + count + ")";
286
+ document.getElementById("scenario_count").innerHTML = count_header;
287
+ }
288
+
280
289
  function generateCssSelectorFromTags(tagGroups) {
281
290
 
282
291
  var tagSelectors = [ "" ];
@@ -73,7 +73,6 @@ def serialize_feature_directories_recursively(namespaces)
73
73
  end
74
74
  end
75
75
 
76
-
77
76
  # Generate feature list
78
77
  # @note this method is called automatically by YARD based on the menus defined in the layout
79
78
  def generate_feature_list
@@ -82,11 +81,32 @@ def generate_feature_list
82
81
  generate_full_list features_ordered_by_name, :features
83
82
  end
84
83
 
84
+ # Count scenarios for features
85
+ def record_feature_scenarios(features)
86
+ count_with_examples = 0
87
+ features.each do |f|
88
+ count_with_examples += f.total_scenarios
89
+ end
90
+ return count_with_examples
91
+ end
92
+
93
+ # Count scenarios for tags
94
+ def record_tagged_scenarios(tags)
95
+ scenario_count = 0
96
+ count_with_examples = 0
97
+ tags.each do |t|
98
+ scenario_count += t.all_scenarios.size
99
+ count_with_examples += t.total_scenarios
100
+ end
101
+ end
102
+
85
103
  # Generate tag list
86
104
  # @note this method is called automatically by YARD based on the menus defined in the layout
87
105
  def generate_tag_list
88
106
  tags = Registry.all(:tag)
89
- tags_ordered_by_use = Array(tags).sort {|x,y| y.all_scenarios.size <=> x.all_scenarios.size }
107
+ tags_ordered_by_use = Array(tags).sort {|x,y| y.total_scenarios <=> x.total_scenarios }
108
+
109
+ record_tagged_scenarios(tags)
90
110
 
91
111
  generate_full_list tags_ordered_by_use, :tags
92
112
  end
@@ -162,10 +182,12 @@ end
162
182
  # When there are is just one feature directory then we want to link to that directory
163
183
  #
164
184
  def all_features_link
185
+ features = Registry.all(:feature)
186
+ count_with_examples = record_feature_scenarios(features)
165
187
  if root_feature_directories.length == 0 || root_feature_directories.length > 1
166
- linkify YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE, "All Features"
188
+ linkify YARD::CodeObjects::Cucumber::CUCUMBER_NAMESPACE, "All Features (#{count_with_examples})"
167
189
  else
168
- linkify root_feature_directories.first, "All Features"
190
+ linkify root_feature_directories.first, "All Features (#{count_with_examples})"
169
191
  end
170
192
  end
171
193
 
@@ -14,7 +14,8 @@
14
14
  <% objects.each do |obj| %>
15
15
  <li>
16
16
  <% if obj.is_a?(YARD::CodeObjects::Cucumber::Scenario) || obj.is_a?(YARD::CodeObjects::Cucumber::ScenarioOutline) %>
17
- <a href="<%= url_for(obj.feature,"scenario_#{obj.path[(/.+_(\d+)$/),1]}") %>">
17
+ <% index = obj.path[(/.+_(\d+)$/),1].to_i - 1 %>
18
+ <a href="<%= url_for(obj.feature,"scenario_#{index}") %>">
18
19
  <%= h obj.value %>
19
20
  </a>
20
21
  <% else %>
@@ -25,6 +25,7 @@ require File.dirname(__FILE__) + "/yard/handlers/cucumber/feature_handler.rb"
25
25
  if RUBY19
26
26
  require File.dirname(__FILE__) + "/yard/handlers/step_definition_handler.rb"
27
27
  require File.dirname(__FILE__) + "/yard/handlers/step_transform_handler.rb"
28
+ require File.dirname(__FILE__) + "/yard/handlers/constant_transform_handler.rb"
28
29
  end
29
30
 
30
31
  require File.dirname(__FILE__) + "/yard/handlers/legacy/step_definition_handler.rb"
@@ -1,3 +1,3 @@
1
1
  module CucumberInTheYARD
2
- VERSION = '3.1.0'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -1,6 +1,4 @@
1
-
2
1
  module YARD::CodeObjects::Cucumber
3
-
4
2
  module LocationHelper
5
3
 
6
4
  def line_number
@@ -14,19 +12,13 @@ module YARD::CodeObjects::Cucumber
14
12
  def location
15
13
  "#{file}:#{line_number}"
16
14
  end
17
-
18
15
  end
19
16
 
20
17
  class Base < YARD::CodeObjects::Base
21
18
  include LocationHelper
22
-
19
+
23
20
  def path
24
21
  @value || super
25
22
  end
26
-
27
23
  end
28
-
29
-
30
-
31
24
  end
32
-
@@ -1,18 +1,16 @@
1
-
2
-
3
1
  module YARD::CodeObjects::Cucumber
4
-
5
2
  class Feature < NamespaceObject
6
-
7
3
  attr_accessor :background, :comments, :description, :keyword, :scenarios, :tags, :value
8
4
 
9
- def initialize(namespace,name)
5
+ def total_scenarios
6
+ scenarios.count
7
+ end
8
+
9
+ def initialize(namespace, name)
10
10
  @comments = ""
11
11
  @scenarios = []
12
12
  @tags = []
13
- super(namespace,name.to_s.strip)
13
+ super(namespace, name.to_s.strip)
14
14
  end
15
-
16
15
  end
17
-
18
- end
16
+ end
@@ -1,49 +1,55 @@
1
-
2
- module YARD::CodeObjects::Cucumber
3
-
4
- class NamespaceObject < YARD::CodeObjects::NamespaceObject
5
- include LocationHelper
6
- def value ; nil ; end
7
- end
8
-
9
- class Requirements < NamespaceObject ; end
10
- class FeatureTags < NamespaceObject ; end
11
- class StepTransformersObject < NamespaceObject ; end
12
-
13
- class FeatureDirectory < YARD::CodeObjects::NamespaceObject
14
-
15
- attr_accessor :description
16
-
17
- def initialize(namespace,name)
18
- super(namespace,name)
19
- @description = ""
20
- end
21
-
22
- def location
23
- files.first.first if files && !files.empty?
24
- end
25
-
26
- def expanded_path
27
- to_s.split('::')[1..-1].join('/')
28
- end
29
-
30
- def value ; name ; end
31
-
32
- def features
33
- children.find_all {|d| d.is_a?(Feature) }
34
- end
35
-
36
- def subdirectories
37
- subdirectories = children.find_all {|d| d.is_a?(FeatureDirectory) }
38
- subdirectories + subdirectories.collect {|s| s.subdirectories }.flatten
39
- end
40
-
41
- end
42
-
43
- CUCUMBER_NAMESPACE = Requirements.new(:root, "requirements") unless defined?(CUCUMBER_NAMESPACE)
44
-
45
- CUCUMBER_TAG_NAMESPACE = FeatureTags.new(CUCUMBER_NAMESPACE, "tags") unless defined?(CUCUMBER_TAG_NAMESPACE)
46
-
47
- CUCUMBER_STEPTRANSFORM_NAMESPACE = StepTransformersObject.new(CUCUMBER_NAMESPACE, "step_transformers") unless defined?(CUCUMBER_STEPTRANSFORM_NAMESPACE)
48
-
49
- end
1
+ module YARD::CodeObjects::Cucumber
2
+ class NamespaceObject < YARD::CodeObjects::NamespaceObject
3
+ include LocationHelper
4
+
5
+ def value;
6
+ nil;
7
+ end
8
+ end
9
+
10
+ class Requirements < NamespaceObject;
11
+ end
12
+ class FeatureTags < NamespaceObject;
13
+ end
14
+ class StepTransformersObject < NamespaceObject;
15
+ end
16
+
17
+ class FeatureDirectory < YARD::CodeObjects::NamespaceObject
18
+
19
+ attr_accessor :description
20
+
21
+ def initialize(namespace, name)
22
+ super(namespace, name)
23
+ @description = ""
24
+ end
25
+
26
+ def location
27
+ files.first.first if files && !files.empty?
28
+ end
29
+
30
+ def expanded_path
31
+ to_s.split('::')[1..-1].join('/')
32
+ end
33
+
34
+ def value;
35
+ name;
36
+ end
37
+
38
+ def features
39
+ children.find_all { |d| d.is_a?(Feature) }
40
+ end
41
+
42
+ def subdirectories
43
+ subdirectories = children.find_all { |d| d.is_a?(FeatureDirectory) }
44
+ subdirectories + subdirectories.collect { |s| s.subdirectories }.flatten
45
+ end
46
+
47
+ end
48
+
49
+ CUCUMBER_NAMESPACE = Requirements.new(:root, "requirements") unless defined?(CUCUMBER_NAMESPACE)
50
+
51
+ CUCUMBER_TAG_NAMESPACE = FeatureTags.new(CUCUMBER_NAMESPACE, "tags") unless defined?(CUCUMBER_TAG_NAMESPACE)
52
+
53
+ CUCUMBER_STEPTRANSFORM_NAMESPACE = StepTransformersObject.new(CUCUMBER_NAMESPACE, "step_transformers") unless defined?(CUCUMBER_STEPTRANSFORM_NAMESPACE)
54
+
55
+ end
@@ -1,26 +1,22 @@
1
-
2
-
3
1
  module YARD::CodeObjects::Cucumber
4
2
 
5
3
  class Scenario < NamespaceObject
6
-
4
+
7
5
  attr_accessor :value, :comments, :keyword, :description, :steps, :tags, :feature
8
-
9
- def initialize(namespace,name)
10
- super(namespace,name.to_s.strip)
6
+
7
+ def initialize(namespace, name)
8
+ super(namespace, name.to_s.strip)
11
9
  @comments = @description = @keyword = @value = @feature = nil
12
10
  @steps = []
13
11
  @tags = []
14
12
  end
15
-
13
+
16
14
  def background?
17
15
  @keyword == "Background"
18
16
  end
19
-
17
+
20
18
  def outline?
21
19
  false
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
@@ -1,14 +1,11 @@
1
-
2
-
3
1
  module YARD::CodeObjects::Cucumber
4
-
5
2
  class ScenarioOutline < NamespaceObject
6
3
 
7
4
  attr_accessor :value, :comments, :keyword, :description, :steps, :tags, :feature
8
5
  attr_accessor :scenarios, :examples
9
6
 
10
- def initialize(namespace,name)
11
- super(namespace,name.to_s.strip)
7
+ def initialize(namespace, name)
8
+ super(namespace, name.to_s.strip)
12
9
  @comments = @description = @value = @feature = nil
13
10
  @steps = []
14
11
  @tags = []
@@ -23,53 +20,49 @@ module YARD::CodeObjects::Cucumber
23
20
  def outline?
24
21
  true
25
22
  end
26
-
23
+
27
24
  def examples?
28
- @examples.find {|example| example.rows }
25
+ @examples.find { |example| example.rows }
29
26
  end
30
-
31
-
27
+
32
28
  class Examples
33
-
34
- attr_accessor :name, :line, :keyword, :comments, :rows
35
-
29
+
30
+ attr_accessor :name, :line, :keyword, :comments, :rows, :tags, :scenario
31
+
36
32
  # The first row of the rows contains the headers for the table
37
33
  def headers
38
34
  rows.first
39
35
  end
40
-
36
+
41
37
  # The data of the table starts at the second row. When there is no data then
42
38
  # return a empty string.
43
39
  def data
44
40
  rows ? rows[1..-1] : ""
45
41
  end
46
-
42
+
47
43
  def values_for_row(row)
48
44
  hash = {}
49
45
 
50
- headers.each_with_index do |header,index|
46
+ headers.each_with_index do |header, index|
51
47
  hash[header] = data[row][index]
52
48
  end
53
49
 
54
50
  hash
55
51
  end
56
-
52
+
57
53
  def to_hash
58
54
  hash = {}
59
55
 
60
- rows.each_with_index do |header,index|
61
- hash[header] = rows.collect {|row| row[index] }
56
+ rows.each_with_index do |header, index|
57
+ hash[header] = rows.collect { |row| row[index] }
62
58
  end
63
59
 
64
60
  hash
65
61
  end
66
-
62
+
67
63
  def initialize(parameters = {})
68
- parameters.each {|key,value| send("#{key.to_sym}=",value) if respond_to? "#{key.to_sym}=" }
64
+ parameters.each { |key, value| send("#{key.to_sym}=", value) if respond_to? "#{key.to_sym}=" }
69
65
  end
70
-
71
66
  end
72
-
73
67
  end
74
-
75
68
  end
@@ -1,13 +1,18 @@
1
-
2
-
3
1
  module YARD::CodeObjects::Cucumber
4
-
5
2
  class Step < Base
6
3
 
7
- attr_accessor :comments, :definition, :examples, :keyword, :scenario, :table, :text, :transforms, :value
8
-
9
- def initialize(namespace,name)
10
- super(namespace,name.to_s.strip)
4
+ attr_accessor :comments,
5
+ :definition,
6
+ :examples,
7
+ :keyword,
8
+ :scenario,
9
+ :table,
10
+ :text,
11
+ :transforms,
12
+ :value
13
+
14
+ def initialize(namespace, name)
15
+ super(namespace, name.to_s.strip)
11
16
  @comments = @definition = @description = @keyword = @table = @text = @value = nil
12
17
  @examples = {}
13
18
  @transforms = []
@@ -32,7 +37,5 @@ module YARD::CodeObjects::Cucumber
32
37
  def transformed?
33
38
  !@transforms.empty?
34
39
  end
35
-
36
40
  end
37
-
38
41
  end
@@ -1,27 +1,31 @@
1
-
2
-
3
1
  module YARD::CodeObjects::Cucumber
4
-
5
2
  class Tag < NamespaceObject
6
3
 
7
- attr_accessor :value, :owners
8
-
4
+ attr_accessor :value, :owners, :total_scenarios
5
+
9
6
  def features
10
- @owners.find_all{|owner| owner.is_a?(Feature) }
7
+ @owners.find_all { |owner| owner.is_a?(Feature) }
11
8
  end
12
-
9
+
13
10
  def scenarios
14
- @owners.find_all{|owner| owner.is_a?(Scenario) || owner.is_a?(ScenarioOutline) }
11
+ all = @owners.find_all do |owner|
12
+ owner.is_a?(Scenario) || owner.is_a?(ScenarioOutline) || ()
13
+ end
14
+
15
+ @owners.each do |owner|
16
+ if owner.is_a?(ScenarioOutline::Examples) && !all.include?(owner.scenario)
17
+ all << owner.scenario
18
+ end
19
+ end
20
+ all
15
21
  end
16
-
22
+
17
23
  def indirect_scenarios
18
- @owners.find_all{|owner| owner.is_a?(Feature) }.collect {|feature| feature.scenarios }.flatten
24
+ @owners.find_all { |owner| owner.is_a?(Feature) }.collect { |feature| feature.scenarios }.flatten
19
25
  end
20
-
26
+
21
27
  def all_scenarios
22
28
  scenarios + indirect_scenarios
23
29
  end
24
-
25
30
  end
26
-
27
31
  end