yard-cucumber2 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +37 -0
- data/History.txt +274 -0
- data/LICENSE.txt +22 -0
- data/README.md +188 -0
- data/Rakefile +25 -0
- data/example/README.md +8 -0
- data/example/child_feature/README.md +21 -0
- data/example/child_feature/child.feature +11 -0
- data/example/child_feature/grandchild_feature/grandchild.feature +12 -0
- data/example/empty.feature +2 -0
- data/example/french.feature +18 -0
- data/example/scenario.feature +63 -0
- data/example/scenario_outline.feature +94 -0
- data/example/scenario_outline_multi.feature +15 -0
- data/example/step_definitions/example.step.rb +109 -0
- data/example/step_definitions/first.step.rb +21 -0
- data/example/step_definitions/french_steps.rb +32 -0
- data/example/step_definitions/struct.rb +11 -0
- data/example/step_definitions/support/env.rb +7 -0
- data/example/step_definitions/support/env_support.rb +12 -0
- data/example/step_definitions/support/support.rb +6 -0
- data/example/tags.feature +18 -0
- data/example/transform.feature +13 -0
- data/lib/cucumber/city_builder.rb +331 -0
- data/lib/docserver/default/fulldoc/html/js/cucumber.js +85 -0
- data/lib/docserver/default/layout/html/headers.erb +14 -0
- data/lib/docserver/doc_server/full_list/html/full_list.erb +39 -0
- data/lib/docserver/doc_server/full_list/html/setup.rb +18 -0
- data/lib/templates/default/feature/html/feature.erb +39 -0
- data/lib/templates/default/feature/html/no_steps_defined.erb +1 -0
- data/lib/templates/default/feature/html/outline.erb +56 -0
- data/lib/templates/default/feature/html/pystring.erb +3 -0
- data/lib/templates/default/feature/html/scenario.erb +55 -0
- data/lib/templates/default/feature/html/setup.rb +55 -0
- data/lib/templates/default/feature/html/steps.erb +39 -0
- data/lib/templates/default/feature/html/table.erb +20 -0
- data/lib/templates/default/featuredirectory/html/alpha_table.erb +30 -0
- data/lib/templates/default/featuredirectory/html/directory.erb +32 -0
- data/lib/templates/default/featuredirectory/html/setup.rb +41 -0
- data/lib/templates/default/featuretags/html/namespace.erb +131 -0
- data/lib/templates/default/featuretags/html/setup.rb +34 -0
- data/lib/templates/default/fulldoc/html/css/cucumber.css +227 -0
- data/lib/templates/default/fulldoc/html/directories.erb +53 -0
- data/lib/templates/default/fulldoc/html/full_list_featuredirectories.erb +11 -0
- data/lib/templates/default/fulldoc/html/full_list_features.erb +29 -0
- data/lib/templates/default/fulldoc/html/full_list_stepdefinitions.erb +16 -0
- data/lib/templates/default/fulldoc/html/full_list_steps.erb +17 -0
- data/lib/templates/default/fulldoc/html/full_list_tags.erb +12 -0
- data/lib/templates/default/fulldoc/html/js/cucumber.js +305 -0
- data/lib/templates/default/fulldoc/html/setup.rb +175 -0
- data/lib/templates/default/layout/html/setup.rb +56 -0
- data/lib/templates/default/requirements/html/alpha_table.erb +26 -0
- data/lib/templates/default/requirements/html/requirements.erb +50 -0
- data/lib/templates/default/requirements/html/setup.rb +51 -0
- data/lib/templates/default/steptransformers/html/header.erb +12 -0
- data/lib/templates/default/steptransformers/html/index.erb +10 -0
- data/lib/templates/default/steptransformers/html/setup.rb +94 -0
- data/lib/templates/default/steptransformers/html/transformers.erb +79 -0
- data/lib/templates/default/steptransformers/html/undefinedsteps.erb +26 -0
- data/lib/templates/default/tag/html/alpha_table.erb +32 -0
- data/lib/templates/default/tag/html/setup.rb +27 -0
- data/lib/templates/default/tag/html/tag.erb +35 -0
- data/lib/yard-cucumber.rb +47 -0
- data/lib/yard-cucumber/version.rb +3 -0
- data/lib/yard/code_objects/cucumber/base.rb +32 -0
- data/lib/yard/code_objects/cucumber/feature.rb +18 -0
- data/lib/yard/code_objects/cucumber/namespace_object.rb +49 -0
- data/lib/yard/code_objects/cucumber/scenario.rb +26 -0
- data/lib/yard/code_objects/cucumber/scenario_outline.rb +75 -0
- data/lib/yard/code_objects/cucumber/step.rb +38 -0
- data/lib/yard/code_objects/cucumber/tag.rb +27 -0
- data/lib/yard/code_objects/step_definition.rb +7 -0
- data/lib/yard/code_objects/step_transform.rb +7 -0
- data/lib/yard/code_objects/step_transformer.rb +97 -0
- data/lib/yard/handlers/cucumber/base.rb +21 -0
- data/lib/yard/handlers/cucumber/feature_handler.rb +131 -0
- data/lib/yard/handlers/legacy/step_definition_handler.rb +45 -0
- data/lib/yard/handlers/legacy/step_transform_handler.rb +24 -0
- data/lib/yard/handlers/step_definition_handler.rb +86 -0
- data/lib/yard/handlers/step_transform_handler.rb +31 -0
- data/lib/yard/parser/cucumber/feature.rb +73 -0
- data/lib/yard/server/adapter.rb +43 -0
- data/lib/yard/server/commands/list_command.rb +31 -0
- data/lib/yard/server/router.rb +32 -0
- data/lib/yard/templates/helpers/base_helper.rb +26 -0
- data/yard-cucumber.gemspec +65 -0
- metadata +199 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
def init
|
|
2
|
+
super
|
|
3
|
+
@tag = object
|
|
4
|
+
|
|
5
|
+
sections.push :tag
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def features
|
|
9
|
+
@tag.features
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def scenarios
|
|
13
|
+
@tag.scenarios
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def alpha_table(objects)
|
|
18
|
+
@elements = Hash.new
|
|
19
|
+
|
|
20
|
+
objects = run_verifier(objects)
|
|
21
|
+
objects.each {|o| (@elements[o.value.to_s[0,1].upcase] ||= []) << o }
|
|
22
|
+
@elements.values.each {|v| v.sort! {|a,b| b.value.to_s <=> a.value.to_s } }
|
|
23
|
+
@elements = @elements.sort_by {|l,o| l.to_s }
|
|
24
|
+
|
|
25
|
+
@elements.each {|letter,objects| objects.sort! {|a,b| b.value.to_s <=> a.value.to_s }}
|
|
26
|
+
erb(:alpha_table)
|
|
27
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<div class="tag">
|
|
2
|
+
<div class="title">
|
|
3
|
+
<span class="pre">Tag:</span>
|
|
4
|
+
<span class="name"><%= @tag.value %></span>
|
|
5
|
+
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<div class="meta">
|
|
9
|
+
<div class="file">
|
|
10
|
+
<%= @tag.features.size > 0 ? "#{@tag.features.size} feature#{@tag.features.size > 1 ? 's' : ''} (with #{@tag.indirect_scenarios.size} scenario#{@tag.indirect_scenarios.size > 1 ? 's' : ''})" : "" %>
|
|
11
|
+
<%= " and " if @tag.features.size > 0 && @tag.scenarios.size > 0 %>
|
|
12
|
+
<%= @tag.scenarios.size > 0 ? "#{@tag.scenarios.size} scenario#{@tag.scenarios.size > 1 ? 's' : ''}" : "" %>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div style="margin-top: 20px;"> </div>
|
|
17
|
+
|
|
18
|
+
<% if features && !features.empty? %>
|
|
19
|
+
<div id="features" style="margin-left: 40px;">
|
|
20
|
+
<div class="title"><span class="name">Features</span></div>
|
|
21
|
+
</div>
|
|
22
|
+
<%= alpha_table(features) %>
|
|
23
|
+
|
|
24
|
+
<% end %>
|
|
25
|
+
|
|
26
|
+
<% if scenarios && !scenarios.empty? %>
|
|
27
|
+
<div id="features" style="margin-left: 40px;">
|
|
28
|
+
<div class="title"><span class="name">Scenarios</span></div>
|
|
29
|
+
</div>
|
|
30
|
+
<%= alpha_table(scenarios) %>
|
|
31
|
+
|
|
32
|
+
<% end %>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
</div>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'cucumber/platform'
|
|
2
|
+
require 'gherkin/parser/parser'
|
|
3
|
+
require 'gherkin/formatter/tag_count_formatter'
|
|
4
|
+
|
|
5
|
+
require File.dirname(__FILE__) + "/yard-cucumber/version.rb"
|
|
6
|
+
|
|
7
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/base.rb"
|
|
8
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/namespace_object.rb"
|
|
9
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/feature.rb"
|
|
10
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/scenario_outline.rb"
|
|
11
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/scenario.rb"
|
|
12
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/step.rb"
|
|
13
|
+
require File.dirname(__FILE__) + "/yard/code_objects/cucumber/tag.rb"
|
|
14
|
+
|
|
15
|
+
require File.dirname(__FILE__) + "/cucumber/city_builder.rb"
|
|
16
|
+
|
|
17
|
+
require File.dirname(__FILE__) + "/yard/code_objects/step_transformer.rb"
|
|
18
|
+
require File.dirname(__FILE__) + "/yard/code_objects/step_definition.rb"
|
|
19
|
+
require File.dirname(__FILE__) + "/yard/code_objects/step_transform.rb"
|
|
20
|
+
|
|
21
|
+
require File.dirname(__FILE__) + "/yard/parser/cucumber/feature.rb"
|
|
22
|
+
|
|
23
|
+
require File.dirname(__FILE__) + "/yard/handlers/cucumber/base.rb"
|
|
24
|
+
require File.dirname(__FILE__) + "/yard/handlers/cucumber/feature_handler.rb"
|
|
25
|
+
|
|
26
|
+
if RUBY19
|
|
27
|
+
require File.dirname(__FILE__) + "/yard/handlers/step_definition_handler.rb"
|
|
28
|
+
require File.dirname(__FILE__) + "/yard/handlers/step_transform_handler.rb"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
require File.dirname(__FILE__) + "/yard/handlers/legacy/step_definition_handler.rb"
|
|
32
|
+
require File.dirname(__FILE__) + "/yard/handlers/legacy/step_transform_handler.rb"
|
|
33
|
+
|
|
34
|
+
#require File.dirname(__FILE__) + "/yard/parser/source_parser.rb"
|
|
35
|
+
require File.dirname(__FILE__) + "/yard/templates/helpers/base_helper.rb"
|
|
36
|
+
|
|
37
|
+
require File.dirname(__FILE__) + "/yard/server/adapter.rb"
|
|
38
|
+
require File.dirname(__FILE__) + "/yard/server/commands/list_command.rb"
|
|
39
|
+
require File.dirname(__FILE__) + "/yard/server/router.rb"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# This registered template works for yardoc
|
|
43
|
+
YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + '/templates'
|
|
44
|
+
|
|
45
|
+
# The following static paths and templates are for yard server
|
|
46
|
+
YARD::Server.register_static_path File.dirname(__FILE__) + "/templates/default/fulldoc/html"
|
|
47
|
+
YARD::Server.register_static_path File.dirname(__FILE__) + "/docserver/default/fulldoc/html"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
module YARD::CodeObjects::Cucumber
|
|
3
|
+
|
|
4
|
+
module LocationHelper
|
|
5
|
+
|
|
6
|
+
def line_number
|
|
7
|
+
files.first.last
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def file
|
|
11
|
+
files.first.first if files && !files.empty?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def location
|
|
15
|
+
"#{file}:#{line_number}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Base < YARD::CodeObjects::Base
|
|
21
|
+
include LocationHelper
|
|
22
|
+
|
|
23
|
+
def path
|
|
24
|
+
@value || super
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module YARD::CodeObjects::Cucumber
|
|
4
|
+
|
|
5
|
+
class Feature < NamespaceObject
|
|
6
|
+
|
|
7
|
+
attr_accessor :background, :comments, :description, :keyword, :scenarios, :tags, :value
|
|
8
|
+
|
|
9
|
+
def initialize(namespace,name)
|
|
10
|
+
@comments = ""
|
|
11
|
+
@scenarios = []
|
|
12
|
+
@tags = []
|
|
13
|
+
super(namespace,name.to_s.strip)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module YARD::CodeObjects::Cucumber
|
|
4
|
+
|
|
5
|
+
class Scenario < NamespaceObject
|
|
6
|
+
|
|
7
|
+
attr_accessor :value, :comments, :keyword, :description, :steps, :tags, :feature
|
|
8
|
+
|
|
9
|
+
def initialize(namespace,name)
|
|
10
|
+
super(namespace,name.to_s.strip)
|
|
11
|
+
@comments = @description = @keyword = @value = @feature = nil
|
|
12
|
+
@steps = []
|
|
13
|
+
@tags = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def background?
|
|
17
|
+
@keyword == "Background"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def outline?
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module YARD::CodeObjects::Cucumber
|
|
4
|
+
|
|
5
|
+
class ScenarioOutline < NamespaceObject
|
|
6
|
+
|
|
7
|
+
attr_accessor :value, :comments, :keyword, :description, :steps, :tags, :feature
|
|
8
|
+
attr_accessor :scenarios, :examples
|
|
9
|
+
|
|
10
|
+
def initialize(namespace,name)
|
|
11
|
+
super(namespace,name.to_s.strip)
|
|
12
|
+
@comments = @description = @value = @feature = nil
|
|
13
|
+
@steps = []
|
|
14
|
+
@tags = []
|
|
15
|
+
@scenarios = []
|
|
16
|
+
@examples = []
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def background?
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def outline?
|
|
24
|
+
true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def examples?
|
|
28
|
+
@examples.find {|example| example.rows }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
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 = {}
|
|
49
|
+
|
|
50
|
+
headers.each_with_index do |header,index|
|
|
51
|
+
hash[header] = data[row][index]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
hash
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def to_hash
|
|
58
|
+
hash = {}
|
|
59
|
+
|
|
60
|
+
rows.each_with_index do |header,index|
|
|
61
|
+
hash[header] = rows.collect {|row| row[index] }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
hash
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def initialize(parameters = {})
|
|
68
|
+
parameters.each {|key,value| send("#{key.to_sym}=",value) if respond_to? "#{key.to_sym}=" }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module YARD::CodeObjects::Cucumber
|
|
4
|
+
|
|
5
|
+
class Step < Base
|
|
6
|
+
|
|
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)
|
|
11
|
+
@comments = @definition = @description = @keyword = @table = @text = @value = nil
|
|
12
|
+
@examples = {}
|
|
13
|
+
@transforms = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def has_table?
|
|
17
|
+
!@table.nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def has_text?
|
|
21
|
+
!@text.nil?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def definition=(stepdef)
|
|
25
|
+
@definition = stepdef
|
|
26
|
+
|
|
27
|
+
unless stepdef.steps.map(&:files).include?(files)
|
|
28
|
+
stepdef.steps << self
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def transformed?
|
|
33
|
+
!@transforms.empty?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module YARD::CodeObjects::Cucumber
|
|
4
|
+
|
|
5
|
+
class Tag < NamespaceObject
|
|
6
|
+
|
|
7
|
+
attr_accessor :value, :owners
|
|
8
|
+
|
|
9
|
+
def features
|
|
10
|
+
@owners.find_all{|owner| owner.is_a?(Feature) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def scenarios
|
|
14
|
+
@owners.find_all{|owner| owner.is_a?(Scenario) || owner.is_a?(ScenarioOutline) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def indirect_scenarios
|
|
18
|
+
@owners.find_all{|owner| owner.is_a?(Feature) }.collect {|feature| feature.scenarios }.flatten
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def all_scenarios
|
|
22
|
+
scenarios + indirect_scenarios
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
|
|
2
|
+
module YARD::CodeObjects
|
|
3
|
+
|
|
4
|
+
class StepTransformerObject < Base
|
|
5
|
+
|
|
6
|
+
include Cucumber::LocationHelper
|
|
7
|
+
|
|
8
|
+
attr_reader :constants, :keyword, :source, :value, :literal_value
|
|
9
|
+
attr_accessor :steps, :pending, :substeps
|
|
10
|
+
|
|
11
|
+
# This defines an escape pattern within a string or regex:
|
|
12
|
+
# /^the first #{CONSTANT} step$/
|
|
13
|
+
#
|
|
14
|
+
# This is used below in the value to process it if there happen to be
|
|
15
|
+
# constants defined here.
|
|
16
|
+
#
|
|
17
|
+
# @note this does not handle the result of method calls
|
|
18
|
+
# @note this does not handle multiple constants within the same escaped area
|
|
19
|
+
#
|
|
20
|
+
def escape_pattern
|
|
21
|
+
/#\{\s*(\w+)\s*\}/
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# When requesting a step tranformer object value, process it, if it hasn't
|
|
26
|
+
# alredy been processed, replacing any constants that may be lurking within
|
|
27
|
+
# the value.
|
|
28
|
+
#
|
|
29
|
+
# Processing it means looking for any escaped characters that happen to be
|
|
30
|
+
# CONSTANTS that could be matched and then replaced. This is done recursively
|
|
31
|
+
# as CONSTANTS can be defined with more CONSTANTS.
|
|
32
|
+
#
|
|
33
|
+
def value
|
|
34
|
+
unless @processed
|
|
35
|
+
@processed = true
|
|
36
|
+
until (nested = constants_from_value).empty?
|
|
37
|
+
nested.each {|n| @value.gsub!(value_regex(n),find_value_for_constant(n)) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@value
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#
|
|
45
|
+
# Set the literal value and the value of the step definition.
|
|
46
|
+
#
|
|
47
|
+
# The literal value is as it appears in the step definition file with any
|
|
48
|
+
# constants. The value, when retrieved will attempt to replace those
|
|
49
|
+
# constants with their regex or string equivalents to hopefully match more
|
|
50
|
+
# steps and step definitions.
|
|
51
|
+
#
|
|
52
|
+
#
|
|
53
|
+
def value=(value)
|
|
54
|
+
@literal_value = format_source(value)
|
|
55
|
+
@value = format_source(value)
|
|
56
|
+
|
|
57
|
+
@steps = []
|
|
58
|
+
value
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Generate a regex with the step transformers value
|
|
62
|
+
def regex
|
|
63
|
+
@regex ||= /#{strip_regex_from(value)}/
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Look through the specified data for the escape pattern and return an array
|
|
67
|
+
# of those constants found. This defaults to the @value within step transformer
|
|
68
|
+
# as it is used internally, however, it can be called externally if it's
|
|
69
|
+
# needed somewhere.
|
|
70
|
+
def constants_from_value(data=@value)
|
|
71
|
+
data.scan(escape_pattern).flatten.collect { |value| value.strip }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
protected
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Looking through all the constants in the registry and returning the value
|
|
78
|
+
# with the regex items replaced from the constnat if present
|
|
79
|
+
#
|
|
80
|
+
def find_value_for_constant(name)
|
|
81
|
+
constant = YARD::Registry.all(:constant).find{|c| c.name == name.to_sym }
|
|
82
|
+
log.warn "StepTransformer#find_value_for_constant : Could not find the CONSTANT [#{name}] using the string value." unless constant
|
|
83
|
+
constant ? strip_regex_from(constant.value) : name
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Return a regex of the value
|
|
87
|
+
def value_regex(value)
|
|
88
|
+
/#\{\s*#{value}\s*\}/
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Step the regex starting / and ending / from the value
|
|
92
|
+
def strip_regex_from(value)
|
|
93
|
+
value.gsub(/^\/|\/$/,'')
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|