Module: RBehave::World
- Includes:
- Spec::Matchers
- 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
-
.run_with_suspended_listeners(instance, type, name, step) ⇒ Object
TODO: lots of duplication between #run_with_suspended_listeners and #store_and_call.
- .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
28 29 30 |
# File 'lib/rbehave/world.rb', line 28 def add_listener(listener) listeners() << listener end |
.create(cls = Object, *args) ⇒ Object
20 21 22 |
# File 'lib/rbehave/world.rb', line 20 def create(cls = Object, *args) cls.new(*args).extend(World) end |
.listeners ⇒ Object
24 25 26 |
# File 'lib/rbehave/world.rb', line 24 def listeners @listeners ||= [] end |
.run_with_suspended_listeners(instance, type, name, step) ⇒ Object
TODO: lots of duplication between #run_with_suspended_listeners and #store_and_call
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rbehave/world.rb', line 38 def run_with_suspended_listeners(instance, type, name, step) current_listeners = Array.new(@listeners) begin listeners.each { |l| l.found_step(type, name) } @listeners.clear step.perform(instance) unless RBehave::Runner.dry_run ensure @listeners.replace(current_listeners) end end |
.step_mother ⇒ Object
32 33 34 |
# File 'lib/rbehave/world.rb', line 32 def step_mother @step_mother ||= StepMother.new end |
.store_and_call(instance, type, name, *args, &block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rbehave/world.rb', line 49 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
63 64 65 |
# File 'lib/rbehave/world.rb', line 63 def Given(name, *args, &block) World.store_and_call self, :given, name, *args, &block end |
#GivenScenario(name) ⇒ Object
59 60 61 |
# File 'lib/rbehave/world.rb', line 59 def GivenScenario(name) World.run_with_suspended_listeners(self, :'given scenario', name, GivenScenario.new(name)) end |
#pending(message = 'todo') ⇒ Object
75 76 77 |
# File 'lib/rbehave/world.rb', line 75 def pending( = 'todo') raise PendingException, unless RBehave::Runner.dry_run end |
#Then(name, *args, &block) ⇒ Object
71 72 73 |
# File 'lib/rbehave/world.rb', line 71 def Then(name, *args, &block) World.store_and_call self, :then, name, *args, &block end |
#When(name, *args, &block) ⇒ Object
67 68 69 |
# File 'lib/rbehave/world.rb', line 67 def When(name, *args, &block) World.store_and_call self, :when, name, *args, &block end |