module Cucumber::RbSupport::RbWorld

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}

Constants

AnsiEscapes

Defines aliases for ANSI coloured output. Default colours can be overridden by defining a GHERKIN_COLORS variable in your shell, very much like how you can tweak the familiar POSIX command ls with $LSCOLORS: linux-sxs.org/housekeeping/lscolors.html

The colours that you can change are:

undefined

defaults to yellow

pending

defaults to yellow

pending_arg

defaults to yellow,bold

executing

defaults to grey

executing_arg

defaults to grey,bold

failed

defaults to red

failed_arg

defaults to red,bold

passed

defaults to green

passed_arg

defaults to green,bold

outline

defaults to cyan

outline_arg

defaults to cyan,bold

skipped

defaults to cyan

skipped_arg

defaults to cyan,bold

comment

defaults to grey

tag

defaults to cyan

For instance, if your shell has a black background and a green font (like the “Homebrew” settings for OS X' Terminal.app), you may want to override passed steps to be white instead of green. Examples:

export GHERKIN_COLORS="passed=white"
export GHERKIN_COLORS="passed=white,bold:passed_arg=white,bold,underline"

(If you're on Windows, use SET instead of export). To see what colours and effects are available, just run this in your shell:

ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"

Although not listed, you can also use grey

Attributes

__cucumber_runtime[W]

@private

__natural_language[W]

@private

Public Instance Methods

Transform(arg) click to toggle source

Call a #Transform with a string from another #Transform definition

# File lib/cucumber/rb_support/rb_world.rb, line 15
def Transform(arg)
  rb = @__cucumber_runtime.support_code.ruby
  rb.execute_transforms([arg]).first
end
announce(*messages) click to toggle source

@deprecated Use {#puts} instead.

# File lib/cucumber/rb_support/rb_world.rb, line 84
def announce(*messages)
  STDERR.puts AnsiEscapes.failed + "WARNING: #announce is deprecated. Use #puts instead:" + caller[0] + AnsiEscapes.reset
  puts(*messages)
end
ask(question, timeout_seconds=60) click to toggle source

Pause the tests and ask the operator for input

# File lib/cucumber/rb_support/rb_world.rb, line 106
def ask(question, timeout_seconds=60)
  @__cucumber_runtime.ask(question, timeout_seconds)
end
doc_string(string_without_triple_quotes, content_type='', line_offset=0) click to toggle source

Create an {Cucumber::Ast::DocString} object

Useful in conjunction with the step method, when want to specify a content type. @example Create a multiline string

code = multiline_string(%{
  puts "this is ruby code"
%}, 'ruby')
# File lib/cucumber/rb_support/rb_world.rb, line 77
def doc_string(string_without_triple_quotes, content_type='', line_offset=0)
  STDERR.puts AnsiEscapes.failed + "WARNING: #doc_string is deprecated. Just pass a regular String instead:" + caller[0] + AnsiEscapes.reset
  # 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') click to toggle source

Embed an image in the output

# File lib/cucumber/rb_support/rb_world.rb, line 111
def embed(file, mime_type, label='Screenshot')
  @__cucumber_runtime.embed(file, mime_type, label)
end
inspect() click to toggle source

Prints the list of modules that are included in the World

# File lib/cucumber/rb_support/rb_world.rb, line 135
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") { || ... } click to toggle source

Mark the matched step as pending.

# File lib/cucumber/rb_support/rb_world.rb, line 116
def pending(message = "TODO")
  if block_given?
    begin
      yield
    rescue Exception
      raise Pending, message
    end
    raise Pending, "Expected pending '#{message}' to fail. No Error was raised. No longer pending?"
  else
    raise Pending, message
  end
end
puts(*messages) click to toggle source

Print a message to the output.

@note 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.
# File lib/cucumber/rb_support/rb_world.rb, line 96
def puts(*messages)
  # Even though they won't be output until later, converting the messages to
  # strings right away will protect them from modifications to their original
  # objects in the mean time
  messages.collect! { |message| "#{message}" }

  @__cucumber_runtime.puts(*messages)
end
skip_this_scenario(message = "Scenario skipped") click to toggle source

Skips this step and the remaining steps in the scenario

# File lib/cucumber/rb_support/rb_world.rb, line 130
def skip_this_scenario(message = "Scenario skipped")
  raise Core::Test::Result::Skipped, message
end
step(name, raw_multiline_arg=nil) click to toggle source

Run a single Gherkin step @example Call another step

step "I am logged in"

@example Call a step with quotes in the name

step %{the user "Dave" is logged in}

@example Passing a table

step "the following users exist:", table(%{
  | name  | email           |
  | Matt  | matt@matt.com   |
  | Aslak | aslak@aslak.com |
})

@example Passing a multiline string

step "the email should contain:", "Dear sir,\nYou've won a prize!\n"

@param [String] name The name of the step @param [String,Cucumber::Ast::DocString,Cucumber::Ast::Table] multiline_argument

# 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) click to toggle source

Run a snippet of Gherkin @example

steps %{
  Given the user "Susan" exists
  And I am logged in as "Susan"
}

@param [String] steps_text The Gherkin snippet to run

# File lib/cucumber/rb_support/rb_world.rb, line 50
def steps(steps_text)
  location = Core::Ast::Location.of_caller
  @__cucumber_runtime.invoke_dynamic_steps(steps_text, @__natural_language, location)
end
table(text_or_table, file=nil, line_offset=0) click to toggle source

Parse Gherkin into a {Cucumber::Ast::Table} object.

Useful in conjunction with the step method. @example Create a table

users = table(%{
  | name  | email           |
  | Matt  | matt@matt.com   |
  | Aslak | aslak@aslak.com |
})

@param [String] text_or_table The Gherkin string that represents the table

# File lib/cucumber/rb_support/rb_world.rb, line 65
def table(text_or_table, file=nil, line_offset=0)
  @__cucumber_runtime.table(text_or_table, file, line_offset)
end
to_s() click to toggle source

see {#inspect}

# File lib/cucumber/rb_support/rb_world.rb, line 144
def to_s
  inspect
end