Class: EventedSpec::SpecHelper::EventedExample Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/evented-spec/evented_example.rb

Overview

This class is abstract.

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

CoolioExample, EMExample

Constant Summary collapse

DEFAULT_OPTIONS =

Default options to use with the examples

{
  :spec_timeout => 5
}

Instance Method Summary collapse

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

This method is abstract.
Note:

block should be evaluated in EventedExample descendant instance context (e.g. in EMExample instance)

Note:

delay may be nil, implying you need to execute the block immediately.

Override this method in your descendants

Raises:

  • (NotImplementedError)


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

This method is abstract.

Breaks the event loop and finishes the spec.

Raises:

  • (NotImplementedError)


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_exampleObject

This method is abstract.

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.

Raises:

  • (@spec_exception)


33
34
35
# File 'lib/evented-spec/evented_example.rb', line 33

def finish_example
  raise @spec_exception if @spec_exception
end

#runObject

This method is abstract.

Run the example.

Raises:

  • (NotImplementedError)


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)

Parameters:

  • hook

    type



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

This method is abstract.

Sets timeout for currently running example

Raises:

  • (NotImplementedError)


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