Skip to content

Commit

Permalink
Enabling some compatability for Cucumber 3's ParameterType. Treating …
Browse files Browse the repository at this point in the history
…them for the moment as transforms
  • Loading branch information
Stephen-Kaye committed Jan 3, 2018
1 parent fa120b7 commit 334f142
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

gem 'redcarpet'
gem 'gherkin', '~> 4.0'
gem 'gherkin', '>= 4.0', '< 6.0'

gemspec
42 changes: 24 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
PATH
remote: .
specs:
yard-cucumber (3.0.0)
cucumber (~> 2)
gherkin (~> 4.0)
yard-cucumber (3.1.0)
cucumber (~> 3)
gherkin (~> 5.0)
yard (~> 0.8, >= 0.8.1)

GEM
remote: https://rubygems.org/
specs:
builder (3.2.2)
cucumber (2.4.0)
backports (3.11.0)
builder (3.2.3)
cucumber (3.1.0)
builder (>= 2.1.2)
cucumber-core (~> 1.5.0)
cucumber-core (~> 3.1.0)
cucumber-expressions (~> 5.0.4)
cucumber-wire (~> 0.0.1)
diff-lcs (>= 1.1.3)
gherkin (~> 4.0)
diff-lcs (~> 1.3)
gherkin (~> 5.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (1.5.0)
gherkin (~> 4.0)
cucumber-core (3.1.0)
backports (>= 3.8.0)
cucumber-tag_expressions (~> 1.1.0)
gherkin (>= 5.0.0)
cucumber-expressions (5.0.7)
cucumber-tag_expressions (1.1.1)
cucumber-wire (0.0.1)
diff-lcs (1.2.5)
gherkin (4.0.0)
multi_json (1.12.1)
diff-lcs (1.3)
gherkin (5.0.0)
multi_json (1.12.2)
multi_test (0.1.2)
rake (10.4.2)
redcarpet (2.2.2)
yard (0.9.5)
rake (10.5.0)
redcarpet (3.4.0)
yard (0.9.12)

PLATFORMS
ruby

DEPENDENCIES
gherkin (~> 4.0)
gherkin (~> 5.0)
rake (~> 10)
redcarpet
yard-cucumber!

BUNDLED WITH
1.12.4
1.15.4
20 changes: 19 additions & 1 deletion lib/yard/handlers/constant_transform_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ class YARD::Handlers::Ruby::ConstantTransformHandler < YARD::Handlers::Ruby::Con
instance = register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value }
# specify the owner so that the transform can use the registered constant's name
parse_block(statement[1], {:owner => instance})
elsif statement[1][0][0] == "ParameterType"
name = statement[0][0][0]
# Move the docstring to the transform statement
statement[1].docstring = statement.docstring
# Set the docstring on the constant to reference the transform that will be processed
statement.docstring = "Reference to {#{YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE}::#{name} transform}"

value = find(statement, :label, 'regexp:').parent.children[1].source

value = substitute(value)
value = convert_captures(strip_anchors(value))
instance = register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value }
# specify the owner so that the transform can use the registered constant's name
parse_block(statement[1], {:owner => instance})
end
rescue
# This supresses any errors where any of the statement elements are out of bounds.
Expand All @@ -32,7 +45,12 @@ class YARD::Handlers::Ruby::ConstantTransformHandler < YARD::Handlers::Ruby::Con
end

private


def find(node, node_type, value)
node.traverse { |child| return(child) if node_type == child.type && child.source == value }
self
end

# Cucumber's Transform object overrides the to_s function and strips
# the anchor tags ^$ and any captures so that id it is interpolated in a step definition
# the it can appear anywhere in the step without being effected by position or captures
Expand Down
18 changes: 16 additions & 2 deletions lib/yard/handlers/step_transform_handler.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@

class YARD::Handlers::Ruby::StepTransformHandler < YARD::Handlers::Ruby::Base
handles method_call(:Transform)
handles method_call(:ParameterType)

process do

nextStatement = nil
instance = YARD::CodeObjects::StepTransformObject.new(step_transform_namespace,step_transformer_name) do |o|
o.source = statement.source
o.comments = statement.comments
o.keyword = statement[0].source
o.value = statement[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
if (o.keyword == 'Transform')
o.value = statement[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
nextStatement = statement[2]
elsif (o.keyword == 'ParameterType')
o.value = find(statement, :label, 'regexp:').parent.children[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
nextStatement = find(statement, :label, 'transformer:').parent.children[1]
end
end

obj = register instance
parse_block(statement[2],:owner => obj)
parse_block(nextStatement,:owner => obj)

end

Expand All @@ -33,4 +41,10 @@ def self.generate_unique_id
@step_transformer_count = @step_transformer_count.to_i + 1
end

private

def find(node, node_type, value)
node.traverse { |child| return(child) if node_type == child.type && child.source == value }
self
end
end
4 changes: 2 additions & 2 deletions yard-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rake', '~> 10'

s.add_dependency 'gherkin', '~> 4.0'
s.add_dependency 'cucumber', '~> 2'
s.add_dependency 'gherkin', '>= 4.0', '< 6.0'
s.add_dependency 'cucumber', '>= 2.0', '< 4.0'
s.add_dependency 'yard', '~> 0.8', '>= 0.8.1'

s.rubygems_version = "1.3.7"
Expand Down

0 comments on commit 334f142

Please sign in to comment.