Sha256: 0bae17366c99b575d0392cbdddfcc8bcd911ea2aae581731f6bef0fec462ff81

Contents?: true

Size: 1.44 KB

Versions: 54

Compression:

Stored size: 1.44 KB

Contents

require File.expand_path('../helper', __FILE__)
require 'rbconfig'
require 'open-uri'
require 'timeout'

class IntegrationTest < Test::Unit::TestCase
  def app_file
    File.expand_path('../integration/app.rb', __FILE__)
  end

  def port
    5000 + (Process.pid % 1000)
  end

  def command
    cmd = ['exec']
    if RbConfig.respond_to? :ruby
      cmd << RbConfig.ruby.inspect
    else
      file, dir = RbConfig::CONFIG.values_at('ruby_install_name', 'bindir')
      cmd << File.expand_path(file, dir).inspect
    end
    cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
    cmd << app_file.inspect << '-p' << port << '2>&1'
    cmd.join(" ")
  end

  def display_output(pipe)
    out = ""
    loop { out <<  pipe.read_nonblock(1) }
  rescue
    $stderr.puts command, out unless out.empty?
  end

  def kill(pid, signal = "TERM")
    Process.kill(signal, pid)
  rescue NotImplementedError
    system "kill -s #{signal} #{pid}"
  end

  def with_server
    pipe = IO.popen(command)
    error = nil
    Timeout.timeout(120) do
      begin
        yield
      rescue Errno::ECONNREFUSED => e
        error = e
        sleep 0.1
        retry
      end
    end
    kill(pipe.pid) if pipe
  rescue Timeout::Error => e
    display_output pipe
    kill(pipe.pid, "KILL") if pipe
    raise error || e
  end

  it 'starts a top level application' do
    with_server do
      assert_equal open("http://127.0.0.1:#{port}/app_file").read, app_file
    end
  end
end

Version data entries

54 entries across 54 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.7.4 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.7.3 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.7.2 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.7.1 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.7.0 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.9 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.8 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.7 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.6 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.5 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.4 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.3 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.2 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.1 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.6.0 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.5.17 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.5.16 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.5.15 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb
classiccms-0.5.14 vendor/bundle/gems/sinatra-1.3.2/test/integration_test.rb