Module: Cucumber::RbSupport::RbWorld
- Defined in:
- lib/cucumber/rb_support/rb_world.rb
Overview
Defines the basic DSL methods availlable in all Cucumber step definitions.
You can, and probably should, extend this DSL with your own methods that make sense in your domain. For more on that, see Cucumber::RbSupport::RbDsl#World
Instance Method Summary collapse
-
#announce(*messages) ⇒ Object
deprecated
Deprecated.
Use #puts instead.
-
#ask(question, timeout_seconds = 60) ⇒ Object
Pause the tests and ask the operator for input.
-
#doc_string(string_without_triple_quotes, content_type = '', line_offset = 0) ⇒ Object
Create an Ast::DocString object.
-
#embed(file, mime_type, label = 'Screenshot') ⇒ Object
Embed an image in the output.
-
#inspect ⇒ Object
Prints the list of modules that are included in the World.
-
#pending(message = "TODO") ⇒ Object
Mark the matched step as pending.
-
#puts(*messages) ⇒ Object
Print a message to the output.
-
#skip_this_scenario(message = "Scenario skipped") ⇒ Object
Skips this step and the remaining steps in the scenario.
-
#step(name, raw_multiline_arg = nil) ⇒ Object
Run a single Gherkin step.
-
#steps(steps_text) ⇒ Object
Run a snippet of Gherkin.
-
#table(text_or_table, file = nil, line_offset = 0) ⇒ Object
Parse Gherkin into a Ast::Table object.
-
#to_s ⇒ Object
see #inspect.
-
#Transform(arg) ⇒ Object
Call a Transform with a string from another Transform definition.
Instance Method Details
#announce(*messages) ⇒ Object
Use #puts instead.
82 83 84 85 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 82 def announce(*) STDERR.puts AnsiEscapes.failed + "WARNING: #announce is deprecated. Use #puts instead:" + caller[0] + AnsiEscapes.reset puts(*) end |
#ask(question, timeout_seconds = 60) ⇒ Object
Pause the tests and ask the operator for input
99 100 101 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 99 def ask(question, timeout_seconds=60) @__cucumber_runtime.ask(question, timeout_seconds) end |
#doc_string(string_without_triple_quotes, content_type = '', line_offset = 0) ⇒ Object
Create an Ast::DocString object
Useful in conjunction with the #step method, when want to specify a content type.
76 77 78 79 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 76 def doc_string(string_without_triple_quotes, content_type='', line_offset=0) # TODO: rename this method to multiline_string @__cucumber_runtime.doc_string(string_without_triple_quotes, content_type, line_offset) end |
#embed(file, mime_type, label = 'Screenshot') ⇒ Object
Embed an image in the output
104 105 106 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 104 def (file, mime_type, label='Screenshot') @__cucumber_runtime.(file, mime_type, label) end |
#inspect ⇒ Object
Prints the list of modules that are included in the World
128 129 130 131 132 133 134 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 128 def inspect modules = [self.class] (class << self; self; end).instance_eval do modules += included_modules end sprintf("#<%s:0x%x>", modules.join('+'), self.object_id) end |
#pending(message = "TODO") ⇒ Object
Mark the matched step as pending.
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 109 def pending( = "TODO") if block_given? begin yield rescue Exception raise Pending, end raise Pending, "Expected pending '#{}' to fail. No Error was raised. No longer pending?" else raise Pending, end end |
#puts(*messages) ⇒ Object
Cucumber might surprise you with the behaviour of this method. Instead of sending the output directly to STDOUT, Cucumber will intercept and cache the message until the current step has finished, and then display it.
If you’d prefer to see the message immediately, call Kernel.puts instead.
Print a message to the output.
94 95 96 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 94 def puts(*) @__cucumber_runtime.puts(*) end |
#skip_this_scenario(message = "Scenario skipped") ⇒ Object
Skips this step and the remaining steps in the scenario
123 124 125 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 123 def skip_this_scenario( = "Scenario skipped") raise Core::Test::Result::Skipped, end |
#step(name, raw_multiline_arg = nil) ⇒ Object
Run a single Gherkin step
38 39 40 41 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 38 def step(name, raw_multiline_arg=nil) location = Core::Ast::Location.of_caller @__cucumber_runtime.invoke_dynamic_step(name, MultilineArgument.from(raw_multiline_arg, location)) end |
#steps(steps_text) ⇒ Object
Run a snippet of Gherkin
50 51 52 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 50 def steps(steps_text) @__cucumber_runtime.invoke_dynamic_steps(steps_text, @__natural_language, caller[0]) end |
#table(text_or_table, file = nil, line_offset = 0) ⇒ Object
Parse Gherkin into a Ast::Table object.
Useful in conjunction with the #step method.
64 65 66 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 64 def table(text_or_table, file=nil, line_offset=0) @__cucumber_runtime.table(text_or_table, file, line_offset) end |
#to_s ⇒ Object
see #inspect
137 138 139 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 137 def to_s inspect end |
#Transform(arg) ⇒ Object
Call a Transform with a string from another Transform definition
15 16 17 18 |
# File 'lib/cucumber/rb_support/rb_world.rb', line 15 def Transform(arg) rb = @__cucumber_runtime.load_programming_language('rb') rb.execute_transforms([arg]).first end |