Skip to content

Commit

Permalink
Step Definition Handler
Browse files Browse the repository at this point in the history
* Updated to remove use of class variable
* Made it clearer what was default and the overrides
* Cleared up the step definition unique naming convention
  • Loading branch information
Franklin Webber committed Feb 16, 2013
1 parent 2a9f4a9 commit 5402dc1
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions lib/yard/handlers/step_definition_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,33 @@
#
class YARD::Handlers::Ruby::StepDefinitionHandler < YARD::Handlers::Ruby::Base

#
# By default the english gherkin language will be parsed, however, if the
# YARD configuration file `~./yard/config` defines different step definition
# handlers those are used.
#
#
if YARD::Config.options["yard-cucumber"] and
def self.default_step_definitions
[ "When", "Given", "And", "Then" ]
end

def self.custom_step_definitions
YARD::Config.options["yard-cucumber"]["language"]["step_definitions"]
end

def self.custom_step_definitions_defined?
YARD::Config.options["yard-cucumber"] and
YARD::Config.options["yard-cucumber"]["language"] and
YARD::Config.options["yard-cucumber"]["language"]["step_definitions"]
end

YARD::Config.options["yard-cucumber"]["language"]["step_definitions"].each do |step_word|
handles method_call(step_word.to_sym)
def self.step_definitions
if custom_step_definitions_defined?
custom_step_definitions
else
default_step_definitions
end

else
handles method_call(:When),method_call(:Given),method_call(:And),method_call(:Then)
end


@@unique_name = 0
step_definitions.each { |step_def| handles method_call(step_def) }

process do
@@unique_name += 1

instance = YARD::CodeObjects::StepDefinitionObject.new(YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE,"step_definition#{@@unique_name}") do |o|
instance = YARD::CodeObjects::StepDefinitionObject.new(YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE,step_definition_name) do |o|
o.source = statement.source
o.comments = statement.comments
o.keyword = statement[0].source
Expand All @@ -55,4 +57,12 @@ class YARD::Handlers::Ruby::StepDefinitionHandler < YARD::Handlers::Ruby::Base

end

def step_definition_name
"step_definition#{self.class.generate_unique_id}"
end

def self.generate_unique_id
@step_definition_count = @step_definition_count.to_i + 1
end

end

0 comments on commit 5402dc1

Please sign in to comment.