Class: EventedSpec::SpecHelper::EventedExample Abstract
- Inherits:
-
Object
- Object
- EventedSpec::SpecHelper::EventedExample
- Defined in:
- lib/evented-spec/evented_example.rb
Overview
Represents example running inside some type of event loop. You are not going to use or interact with this class and its descendants directly.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options to use with the examples
{ :spec_timeout => 5 }
Instance Method Summary collapse
-
#delayed(delay = nil, &block) ⇒ Object
abstract
Override this method in your descendants.
-
#done(delay = nil, &block) ⇒ Object
abstract
Breaks the event loop and finishes the spec.
-
#finish_example ⇒ Object
abstract
Called from #run_event_loop when event loop is stopped, but before the example returns.
-
#initialize(opts, example_group_instance, &block) ⇒ EventedExample
constructor
Create new evented example.
-
#run ⇒ Object
abstract
Run the example.
-
#run_hooks(type) ⇒ Object
Runs hooks of specified type (hopefully, inside event loop).
-
#timeout(spec_timeout) ⇒ Object
abstract
Sets timeout for currently running example.
Constructor Details
#initialize(opts, example_group_instance, &block) ⇒ EventedExample
Create new evented example
14 15 16 |
# File 'lib/evented-spec/evented_example.rb', line 14 def initialize(opts, example_group_instance, &block) @opts, @example_group_instance, @block = DEFAULT_OPTIONS.merge(opts), example_group_instance, block end |
Instance Method Details
#delayed(delay = nil, &block) ⇒ Object
block should be evaluated in EventedExample descendant instance context (e.g. in EMExample instance)
delay may be nil, implying you need to execute the block immediately.
Override this method in your descendants
64 65 66 |
# File 'lib/evented-spec/evented_example.rb', line 64 def delayed(delay = nil, &block) raise NotImplementedError, "you should implement #delayed method in #{self.class.name}" end |
#done(delay = nil, &block) ⇒ Object
Breaks the event loop and finishes the spec.
54 55 56 |
# File 'lib/evented-spec/evented_example.rb', line 54 def done(delay=nil, &block) raise NotImplementedError, "you should implement #done method in #{self.class.name}" end |
#finish_example ⇒ Object
Called from #run_event_loop when event loop is stopped, but before the example returns. Descendant classes may redefine to clean up type-specific state.
33 34 35 |
# File 'lib/evented-spec/evented_example.rb', line 33 def finish_example raise @spec_exception if @spec_exception end |
#run ⇒ Object
Run the example.
40 41 42 |
# File 'lib/evented-spec/evented_example.rb', line 40 def run raise NotImplementedError, "you should implement #run in #{self.class.name}" end |
#run_hooks(type) ⇒ Object
Runs hooks of specified type (hopefully, inside event loop)
21 22 23 24 25 |
# File 'lib/evented-spec/evented_example.rb', line 21 def run_hooks(type) @example_group_instance.class.evented_spec_hooks_for(type).each do |hook| @example_group_instance.instance_eval(&hook) end end |
#timeout(spec_timeout) ⇒ Object
Sets timeout for currently running example
47 48 49 |
# File 'lib/evented-spec/evented_example.rb', line 47 def timeout(spec_timeout) raise NotImplementedError, "you should implement #timeout in #{self.class.name}" end |