Class: YARD::Handlers::Ruby::StepDefinitionHandler

Inherits:
Base
  • Object
show all
Defined in:
lib/yard/handlers/step_definition_handler.rb

Overview

Finds and processes all the step definitions defined in the ruby source code. By default the english gherkin language will be parsed.

To override the language you can define the step definitions in the YARD configuration file ‘~./yard/config`:

Examples:

‘~/.yard/config` with LOLCatz step definitions


:"yard-cucumber":
  language:
    step_definitions: [ 'WEN', 'I CAN HAZ', 'AN', 'DEN' ]

‘~/.yard/config` with French step definitions


:"yard-cucumber":
  language:
    step_definitions: [ 'Soit', 'Etantdonné', 'Lorsque', 'Lorsqu', 'Alors', 'Et' ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.custom_step_definitionsObject



26
27
28
# File 'lib/yard/handlers/step_definition_handler.rb', line 26

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

.custom_step_definitions_defined?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/yard/handlers/step_definition_handler.rb', line 30

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

.default_step_definitionsObject



22
23
24
# File 'lib/yard/handlers/step_definition_handler.rb', line 22

def self.default_step_definitions
  [ "When", "Given", "And", "Then" ]
end

.generate_unique_idObject



82
83
84
# File 'lib/yard/handlers/step_definition_handler.rb', line 82

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

.step_definitionsObject



36
37
38
39
40
41
42
# File 'lib/yard/handlers/step_definition_handler.rb', line 36

def self.step_definitions
  if custom_step_definitions_defined?
    custom_step_definitions
  else
    default_step_definitions
  end
end

Instance Method Details

#pending_command_statement?(line) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/yard/handlers/step_definition_handler.rb', line 65

def pending_command_statement?(line)
  (line.type == :command || line.type == :vcall) && line.first.source == pending_keyword
end

#pending_keywordObject



61
62
63
# File 'lib/yard/handlers/step_definition_handler.rb', line 61

def pending_keyword
  "pending"
end

#pending_keyword_used?(block) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/yard/handlers/step_definition_handler.rb', line 69

def pending_keyword_used?(block)
  code_in_block = block.last
  code_in_block.find { |line| pending_command_statement?(line) }
end

#step_definition_nameObject



78
79
80
# File 'lib/yard/handlers/step_definition_handler.rb', line 78

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

#step_transform_namespaceObject



74
75
76
# File 'lib/yard/handlers/step_definition_handler.rb', line 74

def step_transform_namespace
  YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
end