Module: Cucumber::RbSupport::RbWorld

Defined in:
lib/cucumber/rb_support/rb_world.rb

Overview

All steps are run in the context of an object that extends this module.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__cucumber_step_mother=(value) ⇒ Object (writeonly)

Sets the attribute __cucumber_step_mother

Parameters:

  • value

    the value to set the attribute __cucumber_step_mother to.



17
18
19
# File 'lib/cucumber/rb_support/rb_world.rb', line 17

def __cucumber_step_mother=(value)
  @__cucumber_step_mother = value
end

Class Method Details

.alias_adverb(adverb) ⇒ Object



6
7
8
# File 'lib/cucumber/rb_support/rb_world.rb', line 6

def alias_adverb(adverb)
  alias_method adverb, :__cucumber_invoke
end

Instance Method Details

#__cucumber_invoke(name, multiline_argument = nil) ⇒ Object

Call a step from within a step definition. This method is aliased to the same i18n as RbDsl.



21
22
23
24
25
26
27
28
29
# File 'lib/cucumber/rb_support/rb_world.rb', line 21

def __cucumber_invoke(name, multiline_argument=nil) #:nodoc:
  begin
    step_match = @__cucumber_step_mother.step_match(name)
    step_match.invoke(multiline_argument)
  rescue Exception => e
    e.nested! if Undefined === e
    raise e
  end
end

#announce(announcement) ⇒ Object

Output announcement alongside the formatted output. This is an alternative to using Kernel#puts - it will display nicer, and in all outputs (in case you use several formatters)

Beware that the output will be printed before the corresponding step. This is because the step itself will not be printed until after it has run, so it can be coloured according to its status.



64
65
66
# File 'lib/cucumber/rb_support/rb_world.rb', line 64

def announce(announcement)
  @__cucumber_step_mother.announce(announcement)
end

#inspectObject

The default implementation of Object#inspect recursively traverses all instance variables and invokes inspect. This can be time consuming if the object graph is large.

This can cause unnecessary delays when certain exceptions occur. For example, MRI internally invokes #inspect on an object that raises a NoMethodError. (JRuby does not do this).

A World object can have many references created by the user or frameworks (Rails), so to avoid long waiting times on such errors in World we define it to just return a simple String.



94
95
96
# File 'lib/cucumber/rb_support/rb_world.rb', line 94

def inspect #:nodoc:
  sprintf("#<%s:0x%x>", self.class, self.object_id)
end

#pending(message = "TODO") ⇒ Object

Mark the matched step as pending.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cucumber/rb_support/rb_world.rb', line 69

def pending(message = "TODO")
  if block_given?
    begin
      yield
    rescue Exception => e
      raise Pending.new(message)
    end
    raise Pending.new("Expected pending '#{message}' to fail. No Error was raised. No longer pending?")
  else
    raise Pending.new(message)
  end
end

#table(text_or_table, file = nil, line_offset = 0) ⇒ Object

Returns a Cucumber::Ast::Table for text_or_table, which can either be a String:

table(%{
  | account | description | amount |
  | INT-100 | Taxi        | 114    |
  | CUC-101 | Peeler      | 22     |
})

or a 2D Array:

table([
  %w{ account description amount },
  %w{ INT-100 Taxi        114    },
  %w{ CUC-101 Peeler      22     }
])


48
49
50
51
52
53
54
55
# File 'lib/cucumber/rb_support/rb_world.rb', line 48

def table(text_or_table, file=nil, line_offset=0)
  if Array === text_or_table
    Ast::Table.new(text_or_table)
  else
    @table_parser ||= Parser::TableParser.new
    @table_parser.parse_or_fail(text_or_table.strip, file, line_offset)
  end
end

#Transform(arg) ⇒ Object

Call a Transform with a string from another Transform definition



12
13
14
15
# File 'lib/cucumber/rb_support/rb_world.rb', line 12

def Transform(arg)
  rb = @__cucumber_step_mother.load_programming_language('rb')
  rb.execute_transforms([arg]).first
end