No commit activity in last 3 years
No release in over 3 years
Easily test asynchronous eventmachine code. Inspired by jasmine.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
~> 3.0

Runtime

 Project Readme

Build Status

EventMachine::Test

Small library for testing asynchronous eventmachine code. It is inspired by jasmine.

Each example spins up it's own reactor, you make your expectations/assertions, and you call a done callback when you've finished. If your example takes too long, it throws an error.

Installation

Add this line to your application's Gemfile:

gem 'event_machine-test'

And then execute:

$ bundle

Or install it yourself as:

$ gem install event_machine-test

Usage

describe YourLib do

  include EventMachine::Test.new(5) # Pass timeout in seconds

  it 'does something' do
    em_test do |done|

      # Do some actual useful asynchronous stuff, then call done when you've finished
      EventMachine.add_timer(1) do
        expect(true).to eq(true)
        done.call
      end

    end
  end

end

How it works

  1. Spins up eventmachine inside a block
  2. Sets a timer to throw a TimeoutError
  3. Runs the block passed to em_test, passing a done callback which throws a symbol when called.
  4. Symbol is caught outside eventmachine reactor, and the block terminates (with no error).

TODO

  • Write better tests. I tried using rspec-eventmachine for controlling the clock, but it just froze
  • Write integration for rspec (in a separate gem), to avoid having an extra level of indentation for each code block.

Contributing

  1. Fork it ( https://github.com/cameron-martin/event_machine-test/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request