Class: Cucumber::Runtime::SupportCode

Inherits:
Object
  • Object
show all
Includes:
Constantize
Defined in:
lib/cucumber/runtime/support_code.rb

Defined Under Namespace

Classes: StepInvoker

Instance Method Summary collapse

Methods included from Constantize

#constantize, #underscore

Constructor Details

#initialize(step_mother, in_guess_mode) ⇒ SupportCode

Returns a new instance of SupportCode.



35
36
37
38
39
40
41
# File 'lib/cucumber/runtime/support_code.rb', line 35

def initialize(step_mother, in_guess_mode)
  @step_mother = step_mother
  @guess_step_matches = in_guess_mode
  @unsupported_programming_languages = []
  @programming_languages = []
  @language_map = {}
end

Instance Method Details

#around(scenario, block) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/cucumber/runtime/support_code.rb', line 94

def around(scenario, block)
  @programming_languages.reverse.inject(block) do |blk, programming_language|
    proc do
      programming_language.around(scenario) do
        blk.call(scenario)
      end
    end
  end.call
end

#fire_hook(name, *args) ⇒ Object



88
89
90
91
92
# File 'lib/cucumber/runtime/support_code.rb', line 88

def fire_hook(name, *args)
  @programming_languages.each do |programming_language|
    programming_language.send(name, *args)
  end
end

#invoke(step_name, multiline_argument = nil) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/cucumber/runtime/support_code.rb', line 118

def invoke(step_name, multiline_argument=nil)
  begin
    step_match(step_name).invoke(multiline_argument)
  rescue Exception => e
    e.nested! if Undefined === e
    raise e
  end
end

#invoke_steps(steps_text, i18n, file_colon_line) ⇒ Object



43
44
45
46
47
# File 'lib/cucumber/runtime/support_code.rb', line 43

def invoke_steps(steps_text, i18n, file_colon_line)
  file, line = file_colon_line.split(':')
  parser = Gherkin::Parser::Parser.new(StepInvoker.new(self), true, 'steps')
  parser.parse(steps_text, file, line.to_i)
end

#load_files!(files) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/cucumber/runtime/support_code.rb', line 58

def load_files!(files)
  log.debug("Code:\n")
  files.each do |file|
    load_file(file)
  end
  log.debug("\n")
end

#load_files_from_paths(paths) ⇒ Object



66
67
68
69
# File 'lib/cucumber/runtime/support_code.rb', line 66

def load_files_from_paths(paths)
  files = paths.map { |path| Dir["#{path}/**/*"] }.flatten
  load_files! files
end

#load_programming_language!(ext) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/cucumber/runtime/support_code.rb', line 49

def load_programming_language!(ext)
  return @language_map[ext] if @language_map[ext]
  programming_language_class = constantize("Cucumber::#{ext.capitalize}Support::#{ext.capitalize}Language")
  programming_language = programming_language_class.new(@step_mother)
  @programming_languages << programming_language
  @language_map[ext] = programming_language
  programming_language
end

#snippet_text(step_keyword, step_name, multiline_arg_class) ⇒ Object

:nodoc:



77
78
79
80
81
82
# File 'lib/cucumber/runtime/support_code.rb', line 77

def snippet_text(step_keyword, step_name, multiline_arg_class) #:nodoc:
  load_programming_language!('rb') if unknown_programming_language?
  @programming_languages.map do |programming_language|
    programming_language.snippet_text(step_keyword, step_name, multiline_arg_class)
  end.join("\n")
end

#step_definitionsObject



104
105
106
107
108
# File 'lib/cucumber/runtime/support_code.rb', line 104

def step_definitions
  @programming_languages.map do |programming_language|
    programming_language.step_definitions
  end.flatten
end

#step_match(step_name, name_to_report = nil) ⇒ Object

:nodoc:

Raises:



110
111
112
113
114
115
116
# File 'lib/cucumber/runtime/support_code.rb', line 110

def step_match(step_name, name_to_report=nil) #:nodoc:
  matches = matches(step_name, name_to_report)
  raise Undefined.new(step_name) if matches.empty?
  matches = best_matches(step_name, matches) if matches.size > 1 && guess_step_matches?
  raise Ambiguous.new(step_name, matches, guess_step_matches?) if matches.size > 1
  matches[0]
end

#unknown_programming_language?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/cucumber/runtime/support_code.rb', line 84

def unknown_programming_language?
  @programming_languages.empty?
end

#unmatched_step_definitionsObject



71
72
73
74
75
# File 'lib/cucumber/runtime/support_code.rb', line 71

def unmatched_step_definitions
  @programming_languages.map do |programming_language| 
    programming_language.unmatched_step_definitions
  end.flatten
end