Module: RBehave::World

Defined in:
lib/rbehave/world.rb

Overview

A World represents the actual instance a scenario will run in.

RBehave ensures any instance variables and methods defined anywhere
in a story block are available to all the scenarios. This includes
variables that are created or referenced inside Given, When and Then
blocks.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_listener(listener) ⇒ Object



34
35
36
# File 'lib/rbehave/world.rb', line 34

def add_listener(listener)
  listeners << listener
end

.create(cls = Object) ⇒ Object



15
16
17
# File 'lib/rbehave/world.rb', line 15

def create(cls = Object)
  cls.new.extend(World)
end

.listenersObject



30
31
32
# File 'lib/rbehave/world.rb', line 30

def listeners
  @listeners ||= []
end

.store_and_call(instance, type, name, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/rbehave/world.rb', line 19

def store_and_call(instance, type, name, &block)
  @step_mother ||= Hash.new {|hsh,key| hsh[key] = Hash.new }
  if block_given?
    @step_mother[type][name] = block
  else
    block = @step_mother[type][name]
  end
  listeners.each { |l| l.found_step(type, name) }
  instance.instance_eval(&block) unless RBehave::Runner.dry_run?
end

Instance Method Details

#Given(name, &block) ⇒ Object



39
40
41
# File 'lib/rbehave/world.rb', line 39

def Given(name, &block)
  World.store_and_call self, :given, name, &block
end

#pending(message = 'todo') ⇒ Object

Raises:



51
52
53
# File 'lib/rbehave/world.rb', line 51

def pending(message = 'todo')
  raise PendingException, message
end

#Then(name, &block) ⇒ Object



47
48
49
# File 'lib/rbehave/world.rb', line 47

def Then(name, &block)
  World.store_and_call self, :then, name, &block
end

#When(name, &block) ⇒ Object



43
44
45
# File 'lib/rbehave/world.rb', line 43

def When(name, &block)
  World.store_and_call self, :when, name, &block
end