Sha256: ca47949a1eca81c032c7914442c66dc06ae3a2ee7c1af4e430351388dc3ad0af
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
# encoding: utf-8 require 'spec_helper' describe Server do context '#initialize' do it 'requires a command' do command = double('Command') expect { Server.new(command) }.not_to raise_error end it 'uses rackup by default' do expect { Server.new }.not_to raise_error end end context '#start' do it 'starts the server' do create_file 'app.rb', <<-EOS.strip_heredoc require 'sinatra' trap 'USR1' do $stderr.puts "Exit" Kernel.exit! end class App < Sinatra::Base get '/' do 'Hello World' end end EOS config_file = create_file 'config.ru', <<-EOS.strip_heredoc $LOAD_PATH << File.expand_path('..', __FILE__) #$stderr = StringIO.new #$stdout = StringIO.new require 'app' run App EOS command = double('Command') allow(command).to receive(:to_s).and_return("rackup -E development -o 127.0.0.1 -p 9999 #{config_file} 2>/dev/null >&1") server = Server.new(command) unless child_pid = Kernel.fork server.start end begin tries ||= 3 response = with_environment({}, clear: true) do Excon.get('http://127.0.0.1:9999') end rescue Excon::Errors::SocketError sleep 1 retry unless (tries -= 1).zero? end Process.kill :USR1, child_pid expect(response.body).to eq('Hello World') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
local_pac-0.3.0 | spec/server_spec.rb |