Class: Cucumber::RbSupport::RbLanguage
Overview
The Ruby implementation of the programming language API.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_hook, #add_transform, #after, #after_configuration, #available_step_definition, #before, #clear_hooks, #create_step_match, #execute_after_step, #execute_transforms, #hooks_for, #invoked_step_definition, #unmatched_step_definitions
Constructor Details
#initialize(step_mother) ⇒ RbLanguage
Returns a new instance of RbLanguage.
34
35
36
37
38
39
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 34
def initialize(step_mother)
@step_mother = step_mother
@step_definitions = []
RbDsl.rb_language = self
@world_proc = @world_modules = nil
end
|
Instance Attribute Details
#current_world ⇒ Object
Returns the value of attribute current_world.
32
33
34
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 32
def current_world
@current_world
end
|
Instance Method Details
#alias_adverbs(adverbs) ⇒ Object
Tell the language about other i18n translations so that they can alias Given, When Then etc. Only useful if the language has a mechanism for this - typically a dynamic language.
44
45
46
47
48
49
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 44
def alias_adverbs(adverbs)
adverbs.each do |adverb|
RbDsl.alias_adverb(adverb)
RbWorld.alias_adverb(adverb)
end
end
|
#begin_rb_scenario(scenario) ⇒ Object
94
95
96
97
98
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 94
def begin_rb_scenario(scenario)
create_world
extend_world
connect_world(scenario)
end
|
#build_rb_world_factory(world_modules, proc) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 114
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
|
#load_code_file(code_file) ⇒ Object
123
124
125
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 123
def load_code_file(code_file)
require File.expand_path(code_file) end
|
#register_rb_hook(phase, tag_names, proc) ⇒ Object
100
101
102
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 100
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
108
109
110
111
112
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 108
def register_rb_step_definition(regexp, proc)
step_definition = RbStepDefinition.new(self, regexp, proc)
@step_definitions << step_definition
step_definition
end
|
#snippet_text(step_keyword, step_name, multiline_arg_class) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 75
def snippet_text(step_keyword, step_name, multiline_arg_class)
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(", ")}|"
= ""
if(multiline_arg_class == Ast::Table)
= "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n "
end
"#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n #{}pending # express the regexp above with the code you wish you had\nend"
end
|
#step_definitions_for(rb_file) ⇒ Object
Gets called for each file under features (or whatever is overridden with –require).
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 53
def step_definitions_for(rb_file)
begin
require rb_file step_definitions
rescue LoadError => e
e.message << "\nFailed to load #{code_file}"
raise e
ensure
@step_definitions = nil
end
end
|
#step_matches(name_to_match, name_to_format) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 65
def step_matches(name_to_match, name_to_format)
@step_definitions.map do |step_definition|
if(arguments = step_definition.arguments_from(name_to_match))
StepMatch.new(step_definition, name_to_match, name_to_format, arguments)
else
nil
end
end.compact
end
|