Module: Cucumber::RbSupport::RbDsl
- Defined in:
- lib/cucumber/rb_support/rb_dsl.rb
Overview
This module defines the methods you can use to define pure Ruby Step Definitions and Hooks. This module is mixed into the toplevel object.
Class Attribute Summary collapse
-
.rb_language ⇒ Object
writeonly
Sets the attribute rb_language.
Class Method Summary collapse
- .alias_adverb(adverb) ⇒ Object
- .build_rb_world_factory(world_modules, proc) ⇒ Object
- .register_rb_hook(phase, tag_names, proc) ⇒ Object
- .register_rb_step_definition(regexp, proc) ⇒ Object
Instance Method Summary collapse
-
#After(*tag_names, &proc) ⇒ Object
Registers a proc that will run after each Scenario.
-
#AfterConfiguration(&proc) ⇒ Object
Registers a proc that will run after Cucumber is configured.
-
#AfterStep(*tag_names, &proc) ⇒ Object
Registers a proc that will run after each Step.
-
#Before(*tag_names, &proc) ⇒ Object
Registers a proc that will run before each Scenario.
-
#register_rb_step_definition(regexp, &proc) ⇒ Object
Registers a new Ruby StepDefinition.
-
#Transform(*args, &proc) ⇒ Object
Registers a proc that will be called with a step definition argument if it matches the pattern passed as the first argument to Transform.
-
#World(*world_modules, &proc) ⇒ Object
Registers any number of
world_modules
(Ruby Modules) and/or a Proc.
Class Attribute Details
.rb_language=(value) ⇒ Object (writeonly)
Sets the attribute rb_language
10 11 12 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 10 def rb_language=(value) @rb_language = value end |
Class Method Details
.alias_adverb(adverb) ⇒ Object
12 13 14 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 12 def alias_adverb(adverb) alias_method adverb, :register_rb_step_definition end |
.build_rb_world_factory(world_modules, proc) ⇒ Object
16 17 18 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 16 def build_rb_world_factory(world_modules, proc) @rb_language.build_rb_world_factory(world_modules, proc) end |
.register_rb_hook(phase, tag_names, proc) ⇒ Object
20 21 22 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 20 def register_rb_hook(phase, tag_names, proc) @rb_language.register_rb_hook(phase, tag_names, proc) end |
.register_rb_step_definition(regexp, proc) ⇒ Object
24 25 26 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 24 def register_rb_step_definition(regexp, proc) @rb_language.register_rb_step_definition(regexp, proc) end |
Instance Method Details
#After(*tag_names, &proc) ⇒ Object
Registers a proc that will run after each Scenario. You can register as as you want (typically from ruby scripts under support/hooks.rb
).
59 60 61 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 59 def After(*tag_names, &proc) RbDsl.register_rb_hook('after', tag_names, proc) end |
#AfterConfiguration(&proc) ⇒ Object
Registers a proc that will run after Cucumber is configured. You can register as as you want (typically from ruby scripts under support/hooks.rb
).
80 81 82 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 80 def AfterConfiguration(&proc) RbDsl.register_rb_hook('after_configuration', [], proc) end |
#AfterStep(*tag_names, &proc) ⇒ Object
Registers a proc that will run after each Step. You can register as as you want (typically from ruby scripts under support/hooks.rb
).
65 66 67 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 65 def AfterStep(*tag_names, &proc) RbDsl.register_rb_hook('after_step', tag_names, proc) end |
#Before(*tag_names, &proc) ⇒ Object
Registers a proc that will run before each Scenario. You can register as as you want (typically from ruby scripts under support/hooks.rb
).
53 54 55 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 53 def Before(*tag_names, &proc) RbDsl.register_rb_hook('before', tag_names, proc) end |
#register_rb_step_definition(regexp, &proc) ⇒ Object
Registers a new Ruby StepDefinition. This method is aliased to Given
, When
and Then
, and also to the i18n translations whenever a feature of a new language is loaded.
The &proc gets executed in the context of a World
object, which is defined by #World. A new World
object is created for each scenario and is shared across step definitions within that scenario.
93 94 95 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 93 def register_rb_step_definition(regexp, &proc) RbDsl.register_rb_step_definition(regexp, proc) end |
#Transform(*args, &proc) ⇒ Object
Registers a proc that will be called with a step definition argument if it matches the pattern passed as the first argument to Transform. Alternatively, if the pattern contains captures then they will be yielded as arguments to the provided proc. The return value of the proc is consequently yielded to the step definition.
74 75 76 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 74 def Transform(*args, &proc) StepMother.register_transform(*args, &proc) end |
#World(*world_modules, &proc) ⇒ Object
Registers any number of world_modules
(Ruby Modules) and/or a Proc. The proc
will be executed once before each scenario to create an Object that the scenario’s steps will run within. Any world_modules
will be mixed into this Object (via Object#extend).
This method is typically called from one or more Ruby scripts under features/support
. You can call this method as many times as you like (to register more modules), but if you try to register more than one Proc you will get an error.
Cucumber will not yield anything to the proc
. Examples:
World do
MyClass.new
end
World(MyModule)
47 48 49 |
# File 'lib/cucumber/rb_support/rb_dsl.rb', line 47 def World(*world_modules, &proc) RbDsl.build_rb_world_factory(world_modules, proc) end |