Sha256: 1260813134cdda61629fb6e0318e7428fb6263589644a686070b3b47815ea589
Contents?: true
Size: 987 Bytes
Versions: 2
Compression:
Stored size: 987 Bytes
Contents
require 'rack' require 'logger' require 'timeout' require 'net/http' module SpecHelpers class Fake def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello world!"]] end end def start_fake(app) uri = URI.parse("http://localhost:9292/") raise "Server already running on 9292" if uri_active?(uri) @fake_pid = Process.fork do logger = Logger.new(StringIO.new) Rack::Handler::WEBrick.run(app, :Port => 9292, :Logger => logger, :AccessLog => [[logger, WEBrick::AccessLog::COMBINED_LOG_FORMAT]]) end ready = false until ready if uri_active?(uri) ready = true else print "-" if ENV["VERBOSE"] end end end def stop_fake Process.kill(9, @fake_pid) if @fake_pid end private def uri_active?(uri) begin timeout(1) do Net::HTTP.get_response(uri) end true rescue Timeout::Error, SystemCallError false end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spade-packager-0.1.0.1 | spec/support/fake.rb |
spade-packager-0.1.0 | spec/support/fake.rb |