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
- .add_listener(listener) ⇒ Object
- .create(cls = Object, *args) ⇒ Object
- .listeners ⇒ Object
- .step_mother ⇒ Object
- .store_and_call(instance, type, name, *args, &block) ⇒ Object
Instance Method Summary collapse
- #Given(name, *args, &block) ⇒ Object
- #GivenScenario(name) ⇒ Object
- #pending(message = 'todo') ⇒ Object
- #Then(name, *args, &block) ⇒ Object
- #When(name, *args, &block) ⇒ Object
Class Method Details
.add_listener(listener) ⇒ Object
23 24 25 |
# File 'lib/rbehave/world.rb', line 23 def add_listener(listener) listeners() << listener end |
.create(cls = Object, *args) ⇒ Object
15 16 17 |
# File 'lib/rbehave/world.rb', line 15 def create(cls = Object, *args) cls.new(*args).extend(World) end |
.listeners ⇒ Object
19 20 21 |
# File 'lib/rbehave/world.rb', line 19 def listeners @listeners ||= [] end |
.step_mother ⇒ Object
27 28 29 |
# File 'lib/rbehave/world.rb', line 27 def step_mother @step_mother ||= StepMother.new end |
.store_and_call(instance, type, name, *args, &block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rbehave/world.rb', line 31 def store_and_call(instance, type, name, *args, &block) if block_given? step_mother.store(type, name, SimpleStep.new(name, &block)) end step = step_mother.find(type, name) listeners.each { |l| l.found_step(type, name, *args) } step.perform(instance, *args) unless RBehave::Runner.dry_run? end |
Instance Method Details
#Given(name, *args, &block) ⇒ Object
47 48 49 |
# File 'lib/rbehave/world.rb', line 47 def Given(name, *args, &block) World.store_and_call self, :given, name, *args, &block end |
#GivenScenario(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/rbehave/world.rb', line 41 def GivenScenario(name) step = GivenScenario.new name World.step_mother.store(:given_scenario, name, step) World.store_and_call self, :given_scenario, name end |
#pending(message = 'todo') ⇒ Object
59 60 61 |
# File 'lib/rbehave/world.rb', line 59 def pending( = 'todo') raise PendingException, unless RBehave::Runner.dry_run? end |
#Then(name, *args, &block) ⇒ Object
55 56 57 |
# File 'lib/rbehave/world.rb', line 55 def Then(name, *args, &block) World.store_and_call self, :then, name, *args, &block end |
#When(name, *args, &block) ⇒ Object
51 52 53 |
# File 'lib/rbehave/world.rb', line 51 def When(name, *args, &block) World.store_and_call self, :when, name, *args, &block end |