Class: EventedSpec::SpecHelper::AMQPExample
- Inherits:
-
EMExample
- Object
- EventedExample
- EMExample
- EventedSpec::SpecHelper::AMQPExample
- Defined in:
- lib/evented-spec/evented_example/amqp_example.rb
Overview
Represents spec running inside AMQP.start loop See EventedExample for details and method descriptions.
Constant Summary
Constants inherited from EventedExample
EventedExample::DEFAULT_OPTIONS
Instance Method Summary collapse
-
#done(delay = nil) ⇒ Object
Breaks the event loop and finishes the spec.
-
#finish_example ⇒ Object
Called from run_event_loop when event loop is finished, before any exceptions is raised or example returns.
-
#run ⇒ Object
Run @block inside the AMQP.start loop.
Methods inherited from EMExample
#delayed, #finish_em_loop, #run_em_loop, #timeout
Methods inherited from EventedExample
#delayed, #initialize, #run_hooks, #timeout
Constructor Details
This class inherits a constructor from EventedSpec::SpecHelper::EventedExample
Instance Method Details
#done(delay = nil) ⇒ Object
Breaks the event loop and finishes the spec. It yields to any given block first, then stops AMQP, EM event loop and cleans up AMQP state.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/evented-spec/evented_example/amqp_example.rb', line 22 def done(delay = nil) delayed(delay) do yield if block_given? EM.next_tick do run_hooks :amqp_after if ::AMQP.connection && !::AMQP.closing? ::AMQP.stop_connection do # Cannot call finish_em_loop before connection is marked as closed # This callback is called before that happens. EM.next_tick { finish_em_loop } end else # Need this branch because if AMQP couldn't connect, # the callback would never trigger ::AMQP.cleanup_state EM.next_tick { finish_em_loop } end end end end |
#finish_example ⇒ Object
Called from run_event_loop when event loop is finished, before any exceptions is raised or example returns. We ensure AMQP state cleanup here.
47 48 49 50 |
# File 'lib/evented-spec/evented_example/amqp_example.rb', line 47 def finish_example ::AMQP.cleanup_state super end |
#run ⇒ Object
Run @block inside the AMQP.start loop. See EventedExample#run
9 10 11 12 13 14 15 16 |
# File 'lib/evented-spec/evented_example/amqp_example.rb', line 9 def run run_em_loop do ::AMQP.start_connection(@opts) do run_hooks :amqp_before @example_group_instance.instance_eval(&@block) end end end |