Sha256: 57c691f92bcbfedab0622b241ea0db012e5889c8f417b999353d9c5c2eb2bd6d

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

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)
    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 Exception => ex
        false
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spade-0.0.1 spec/support/fake.rb