Module: EM::MiniTest::Spec

Defined in:
lib/em/minitest/spec.rb

Overview

:nodoc

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =

:nodoc:

'1.1.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



81
82
83
# File 'lib/em/minitest/spec.rb', line 81

def self.included base # :nodoc:
  base.extend(ClassMethods)
end

Instance Method Details

#doneObject Also known as: done!

Indicates that an async spec is finished. See wait for example usage.



40
41
42
43
# File 'lib/em/minitest/spec.rb', line 40

def done
  EM.cancel_timer(@timeout)
  EM.stop
end

#timeout_intervalObject

The amount of time to wait for a test to finish before raising an exception. Override this in your class to allow tests more time to run.



77
78
79
# File 'lib/em/minitest/spec.rb', line 77

def timeout_interval
  0.1
end

#waitObject Also known as: wait!

wait indicates that the spec is not expected to be completed when the block is finished running. A call to done is required when using wait.

# setup my spec to use EM::MiniTest::Spec
describe MyClass do
  include EM::MiniTest::Spec

  # The call to defer will return immediately, so the spec code
  # needs to keep running until callback is called.
  it "does some async things" do
    defer_me = lambda do
      # some async stuff
    end

    callback = lambda do
      done!
    end

    EM.defer defer_me, callback

    wait!
  end


33
34
35
# File 'lib/em/minitest/spec.rb', line 33

def wait
  @wait = true
end

#wait_forObject

A helper method for the use case of waiting for some operation to complete that is not necessarily under the control of the spec code.

# These are exactly equivalent
it "waits with the helper" do
  wait_for do
    assert true
  end
end

it "waits manually" do
  EM.next_tick do
    assert true
    done!
  end

  wait!
end


65
66
67
68
69
70
71
72
# File 'lib/em/minitest/spec.rb', line 65

def wait_for
  EM.next_tick do
    yield
    done!
  end

  wait!
end