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
- Spins up eventmachine inside a block
- Sets a timer to throw a
TimeoutError
- Runs the block passed to
em_test
, passing a done callback which throws a symbol when called. - 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
- Fork it ( https://github.com/cameron-martin/event_machine-test/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request