Class: Cucumber::RbSupport::RbLanguage

Inherits:
Object
  • Object
show all
Includes:
LanguageSupport::LanguageMethods
Defined in:
lib/cucumber/rb_support/rb_language.rb

Overview

The Ruby implementation of the programming language API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LanguageSupport::LanguageMethods

#add_hook, #add_step_definition, #after, #after_configuration, #before, #execute_after_step, #hooks_for, #step_definitions

Constructor Details

#initialize(step_mother) ⇒ RbLanguage

Returns a new instance of RbLanguage.



32
33
34
35
# File 'lib/cucumber/rb_support/rb_language.rb', line 32

def initialize(step_mother)
  @step_mother = step_mother
  RbDsl.rb_language = self
end

Instance Attribute Details

#current_worldObject (readonly)

Returns the value of attribute current_world.



30
31
32
# File 'lib/cucumber/rb_support/rb_language.rb', line 30

def current_world
  @current_world
end

Instance Method Details

#alias_adverbs(adverbs) ⇒ Object



37
38
39
40
41
42
# File 'lib/cucumber/rb_support/rb_language.rb', line 37

def alias_adverbs(adverbs)
  adverbs.each do |adverb|
    RbDsl.alias_adverb(adverb)
    RbWorld.alias_adverb(adverb)
  end
end

#begin_rb_scenarioObject



75
76
77
78
79
# File 'lib/cucumber/rb_support/rb_language.rb', line 75

def begin_rb_scenario
  create_world
  extend_world
  connect_world
end

#build_rb_world_factory(world_modules, proc) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/cucumber/rb_support/rb_language.rb', line 89

def build_rb_world_factory(world_modules, proc)
  if(proc)
    raise MultipleWorld.new(@world_proc, proc) if @world_proc
    @world_proc = proc
  end
  @world_modules ||= []
  @world_modules += world_modules
end

#register_rb_hook(phase, tag_names, proc) ⇒ Object



81
82
83
# File 'lib/cucumber/rb_support/rb_language.rb', line 81

def register_rb_hook(phase, tag_names, proc)
  add_hook(phase, RbHook.new(self, tag_names, proc))
end

#register_rb_step_definition(regexp, proc) ⇒ Object



85
86
87
# File 'lib/cucumber/rb_support/rb_language.rb', line 85

def register_rb_step_definition(regexp, proc)
  add_step_definition(RbStepDefinition.new(self, regexp, proc))
end

#snippet_text(step_keyword, step_name, multiline_arg_class = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cucumber/rb_support/rb_language.rb', line 56

def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
  escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
  escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)

  n = 0
  block_args = escaped.scan(ESCAPED_PARAM_PATTERN).map do |a|
    n += 1
    "arg#{n}"
  end
  block_args << multiline_arg_class.default_arg_name unless multiline_arg_class.nil?
  block_arg_string = block_args.empty? ? "" : " |#{block_args.join(", ")}|"
  multiline_class_comment = ""
  if(multiline_arg_class == Ast::Table)
    multiline_class_comment = "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n  "
  end

  "#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n  #{multiline_class_comment}pending\nend"
end

#step_definitions_for(code_file) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cucumber/rb_support/rb_language.rb', line 44

def step_definitions_for(code_file)
  begin
    load_code_file(code_file)
    step_definitions
  rescue LoadError => e
    e.message << "\nFailed to load #{code_file}"
    raise e
  ensure
    @step_definitions = nil
  end
end