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
- DEFAULT_OPTIONS =
Default options to use with the examples
{ :spec_timeout => 5 }
Instance Method Summary (collapse)
-
- (Object) delayed(delay = nil, &block)
abstract
Override this method in your descendants.
-
- (Object) done(delay = nil, &block)
abstract
Breaks the event loop and finishes the spec.
-
- (Object) finish_example
abstract
Called from #run_event_loop when event loop is stopped, but before the example returns.
-
- (EventedExample) initialize(opts, example_group_instance, &block)
constructor
Create new evented example.
-
- (Object) run
abstract
Run the example.
-
- (Object) run_hooks(type)
Runs hooks of specified type (hopefully, inside event loop).
-
- (Object) timeout(spec_timeout)
abstract
Sets timeout for currently running example.
Constructor Details
- (EventedExample) initialize(opts, example_group_instance, &block)
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
- (Object) delayed(delay = nil, &block)
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 |
- (Object) done(delay = nil, &block)
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 |
- (Object) finish_example
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 |
- (Object) run
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 |
- (Object) run_hooks(type)
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 |
- (Object) timeout(spec_timeout)
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 |