2011-11-15 02:48:57 +04:00
|
|
|
require "rspec"
|
2011-11-29 04:11:22 +04:00
|
|
|
require "tempfile"
|
2011-11-18 07:32:38 +04:00
|
|
|
|
|
|
|
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
2011-11-15 02:48:57 +04:00
|
|
|
|
|
|
|
def em(options = {})
|
|
|
|
raise "no block given" unless block_given?
|
|
|
|
timeout = options[:timeout] ||= 1.0
|
|
|
|
|
|
|
|
::EM.run {
|
|
|
|
quantum = 0.005
|
|
|
|
::EM.set_quantum(quantum * 1000) # Lowest possible timer resolution
|
|
|
|
::EM.set_heartbeat_interval(quantum) # Timeout connections asap
|
|
|
|
::EM.add_timer(timeout) { raise "timeout" }
|
|
|
|
yield
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2011-12-06 02:30:00 +04:00
|
|
|
def em_fibered(options = {}, &blk)
|
|
|
|
em(options) do
|
|
|
|
Fiber.new do
|
|
|
|
blk.call
|
|
|
|
end.resume
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-15 02:48:57 +04:00
|
|
|
def done
|
|
|
|
raise "reactor not running" if !::EM.reactor_running?
|
|
|
|
|
|
|
|
::EM.next_tick {
|
|
|
|
# Assert something to show a spec-pass
|
|
|
|
:done.should == :done
|
|
|
|
::EM.stop_event_loop
|
|
|
|
}
|
|
|
|
end
|
2011-11-29 23:02:06 +04:00
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2012-02-09 00:18:29 +04:00
|
|
|
|
|
|
|
# Exclude specs for other platforms
|
|
|
|
config.exclusion_filter = {
|
|
|
|
:platform => lambda { |platform|
|
|
|
|
RUBY_PLATFORM !~ /#{platform}/i },
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:30:00 +04:00
|
|
|
if Process.uid != 0
|
|
|
|
config.filter_run_excluding :needs_root => true
|
|
|
|
end
|
|
|
|
|
2011-11-29 23:02:06 +04:00
|
|
|
config.before(:each) do
|
2011-12-06 02:30:00 +04:00
|
|
|
config = {
|
|
|
|
# Run every logging statement, but discard output
|
2012-03-29 05:06:50 +04:00
|
|
|
"logging" => {
|
|
|
|
"level" => "debug2",
|
|
|
|
"file" => '/dev/null',
|
2011-12-06 02:30:00 +04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
Warden::Server.setup(config)
|
2011-11-29 23:02:06 +04:00
|
|
|
end
|
|
|
|
end
|