I have this app:
require 'sinatra/base'
require 'thin'
class WebService < Sinatra::Base
get '/' do
'hello'
end
end
EM.run do
EventMachine.add_periodic_timer(1) do
puts 'hello'
end
Thin::Server.start(WebService)
end
which I need to write a testing script for. the usual approach does not work because the tests never get executed:
class WebServiceTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
WebService
end
def test
get '/'
assert last_response.ok?
end
end
You need to separate your web app from your Event Machine code, so that you can require it with out EM blocking the thread:
webservice.rb:
app.rb:
Then in your test file you can require
webservice.rbin order to test it: