Top Level Namespace
Defined Under Namespace
Modules: CucumberTricks, KnowsCucumberTables
Instance Method Summary collapse
- #GivenEither(inline_regex, table_regex, &block) ⇒ Object
-
#NameOrPronounTransform(kind, default_value) ⇒ Object
Special capture form able to match short pronoun forms.
-
#register_either_step_definitions(adverb, inline_regex, table_regex, &block) ⇒ Object
GivenEither, WhenEither and ThenEither defines 2 steps in 1 call.
- #ThenEither(inline_regex, table_regex, &block) ⇒ Object
- #WhenEither(inline_regex, table_regex, &block) ⇒ Object
Instance Method Details
#GivenEither(inline_regex, table_regex, &block) ⇒ Object
63 64 65 |
# File 'lib/cucumber_tricks/dsl_extensions.rb', line 63 def GivenEither(inline_regex, table_regex, &block) register_either_step_definitions('Given', inline_regex, table_regex, &block) end |
#NameOrPronounTransform(kind, default_value) ⇒ Object
Special capture form able to match short pronoun forms. NameOrPronounTransform(‘tool’, ‘hammer’) would use the regex
/^(a|an|the|this) tool( "([^"]*)")?$/
Allowing to match things like
* the tool "saw"
* a tool
* this tool
The first time this capture is matched in a scenario, the given value is stored for any subsequent capture where no value is specified.
If ever the first capture does not provide an explicit value, then the given default value is used (aka ‘hammer’ in the previous example)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cucumber_tricks/dsl_extensions.rb', line 20 def NameOrPronounTransform(kind, default_value) knows_this_kind_of_things = Module.new do self.send(:define_method, "main_#{kind}_name") do @main_value ||= default_value end self.send(:define_method, "register_#{kind}_name") do |value| @main_value ||= value end end World(knows_this_kind_of_things) Transform(/^(a|an|the|this|of) #{kind}( "([^"]*)")?$/) do |_prefix, _quoted_thing_name, thing_name| if thing_name.nil? self.send("main_#{kind}_name") else self.send("register_#{kind}_name",thing_name) thing_name end end end |
#register_either_step_definitions(adverb, inline_regex, table_regex, &block) ⇒ Object
GivenEither, WhenEither and ThenEither defines 2 steps in 1 call.
* &bloc : is the implementation of the step, taking a table as argument
* table_regex : is the regex with no arguments, matching the table
* inline_regex : is a regex matching a single textual argument, that
will be in a one cell table before calling the block
example:
GivenEither(/^I have an? ("[^"]*")$/,
/^I have the following animals$/) do |table|
create_animals(table)
end
57 58 59 60 61 62 |
# File 'lib/cucumber_tricks/dsl_extensions.rb', line 57 def register_either_step_definitions(adverb, inline_regex, table_regex, &block) send(adverb,inline_regex) do |arg| self.instance_exec(cucumber_table(arg), &block) end send(adverb,table_regex, &block) end |
#ThenEither(inline_regex, table_regex, &block) ⇒ Object
69 70 71 |
# File 'lib/cucumber_tricks/dsl_extensions.rb', line 69 def ThenEither(inline_regex, table_regex, &block) register_either_step_definitions('Then', inline_regex, table_regex, &block) end |
#WhenEither(inline_regex, table_regex, &block) ⇒ Object
66 67 68 |
# File 'lib/cucumber_tricks/dsl_extensions.rb', line 66 def WhenEither(inline_regex, table_regex, &block) register_either_step_definitions('When', inline_regex, table_regex, &block) end |