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, #before, #create_step_match, #execute_after_step, #execute_transforms, #hooks_for
Constructor Details
#initialize(step_mother) ⇒ RbLanguage
Returns a new instance of RbLanguage.
35
36
37
38
39
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 35
def initialize(step_mother)
@step_mother = step_mother
@step_definitions = []
RbDsl.rb_language = self
end
|
Instance Attribute Details
#current_world ⇒ Object
Returns the value of attribute current_world.
33
34
35
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 33
def current_world
@current_world
end
|
Instance Method Details
#alias_adverbs(adverbs) ⇒ Object
41
42
43
44
45
46
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 41
def alias_adverbs(adverbs)
adverbs.each do |adverb|
RbDsl.alias_adverb(adverb)
RbWorld.alias_adverb(adverb)
end
end
|
#arguments_from(regexp, step_name) ⇒ Object
66
67
68
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 66
def arguments_from(regexp, step_name)
@regexp_argument_matcher.arguments_from(regexp, step_name)
end
|
#begin_rb_scenario ⇒ Object
93
94
95
96
97
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 93
def begin_rb_scenario
create_world
extend_world
connect_world
end
|
#build_rb_world_factory(world_modules, proc) ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 113
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
122
123
124
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 122
def load_code_file(code_file)
require code_file end
|
#register_rb_hook(phase, tag_names, proc) ⇒ Object
99
100
101
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 99
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
107
108
109
110
111
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 107
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 = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 74
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(", ")}|"
= ""
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\nend"
end
|
#step_definitions_for(code_file) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 48
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
|
#step_matches(step_name, formatted_step_name) ⇒ Object
60
61
62
63
64
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 60
def step_matches(step_name, formatted_step_name)
@step_definitions.map do |step_definition|
step_definition.step_match(step_name, formatted_step_name)
end.compact
end
|
#unmatched_step_definitions ⇒ Object
70
71
72
|
# File 'lib/cucumber/rb_support/rb_language.rb', line 70
def unmatched_step_definitions
@step_definitions.select{|step_definition| !step_definition.matched?}
end
|