Module: Cucumber::World

Defined in:
lib/cucumber/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_current_step=(value) ⇒ Object (writeonly)

Sets the attribute __cucumber_current_step

Parameters:

  • value

    the value to set the attribute __cucumber_current_step to.



10
11
12
# File 'lib/cucumber/world.rb', line 10

def __cucumber_current_step=(value)
  @__cucumber_current_step = value
end

#__cucumber_step_mother=(value) ⇒ Object (writeonly)

Sets the attribute __cucumber_step_mother

Parameters:

  • value

    the value to set the attribute __cucumber_step_mother to.



10
11
12
# File 'lib/cucumber/world.rb', line 10

def __cucumber_step_mother=(value)
  @__cucumber_step_mother = value
end

#__cucumber_visitor=(value) ⇒ Object (writeonly)

Sets the attribute __cucumber_visitor

Parameters:

  • value

    the value to set the attribute __cucumber_visitor to.



10
11
12
# File 'lib/cucumber/world.rb', line 10

def __cucumber_visitor=(value)
  @__cucumber_visitor = value
end

Class Method Details

.alias_adverb(adverb) ⇒ Object



5
6
7
# File 'lib/cucumber/world.rb', line 5

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



13
14
15
16
17
18
19
20
21
22
# File 'lib/cucumber/world.rb', line 13

def __cucumber_invoke(name, multiline_argument=nil) #:nodoc:
  begin
    step_match = @__cucumber_step_mother.step_match(name)
    step_match.invoke(self, multiline_argument)
  rescue Exception => e
    e.nested! if Undefined === e
    @__cucumber_current_step.exception = 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.



36
37
38
# File 'lib/cucumber/world.rb', line 36

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

#pending(message = "TODO") ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cucumber/world.rb', line 40

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, file = nil, line_offset = 0) ⇒ Object



24
25
26
27
# File 'lib/cucumber/world.rb', line 24

def table(text, file=nil, line_offset=0)
  @table_parser ||= Parser::TableParser.new
  @table_parser.parse_or_fail(text.strip, file, line_offset)
end