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

#__natural_language=(value) ⇒ Object (writeonly)

Sets the attribute __natural_language

Parameters:

  • value

    the value to set the attribute __natural_language to.



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

def __natural_language=(value)
  @__natural_language = 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
# File 'lib/cucumber/rb_support/rb_world.rb', line 21

def __cucumber_invoke(name, multiline_argument=nil) #:nodoc:
  @__cucumber_step_mother.invoke(name, multiline_argument)
end

#announce(announcement) ⇒ Object

See StepMother#announce



41
42
43
# File 'lib/cucumber/rb_support/rb_world.rb', line 41

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

#announce_worldObject

Prints out the world class, followed by all included modules.



56
57
58
59
60
61
62
# File 'lib/cucumber/rb_support/rb_world.rb', line 56

def announce_world
  announce "WORLD:\n  #{self.class}"
  world = self
  (class << self; self; end).instance_eval do
    world.announce "  #{included_modules.join("\n  ")}"
  end
end

#ask(question, timeout_seconds = 60) ⇒ Object

See StepMother#ask



46
47
48
# File 'lib/cucumber/rb_support/rb_world.rb', line 46

def ask(question, timeout_seconds=60)
  @__cucumber_step_mother.ask(question, timeout_seconds)
end

#embed(file, mime_type) ⇒ Object

See StepMother#embed



51
52
53
# File 'lib/cucumber/rb_support/rb_world.rb', line 51

def embed(file, mime_type)
  @__cucumber_step_mother.embed(file, mime_type)
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.



90
91
92
# File 'lib/cucumber/rb_support/rb_world.rb', line 90

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

#pending(message = "TODO") ⇒ Object

Mark the matched step as pending.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cucumber/rb_support/rb_world.rb', line 65

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

#py_string(string_with_triple_quotes, file = nil, line_offset = 0) ⇒ Object

See StepMother#py_string



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

def py_string(string_with_triple_quotes, file=nil, line_offset=0)
  @__cucumber_step_mother.py_string(string_with_triple_quotes, file, line_offset)
end

#steps(steps_text) ⇒ Object

See StepMother#invoke_steps



26
27
28
# File 'lib/cucumber/rb_support/rb_world.rb', line 26

def steps(steps_text)
  @__cucumber_step_mother.invoke_steps(steps_text, @__natural_language, caller[0])
end

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

See StepMother#table



31
32
33
# File 'lib/cucumber/rb_support/rb_world.rb', line 31

def table(text_or_table, file=nil, line_offset=0)
  @__cucumber_step_mother.table(text_or_table, file, line_offset)
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