server runner updated
This commit is contained in:
parent
d3c3e7bd7d
commit
47b8d10d56
2
config/cucumber.yml
Normal file
2
config/cucumber.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
default: -r features
|
||||||
|
|
@ -7,7 +7,9 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include "Page.h"
|
#include "Page.h"
|
||||||
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
######################################################################
|
|
||||||
# Automatically generated by qmake (2.01a) Tue Aug 2 10:37:48 2011
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
TEMPLATE = app
|
|
||||||
TARGET =
|
|
||||||
DEPENDPATH += . HeadlessSpecRunner Test
|
|
||||||
INCLUDEPATH += . HeadlessSpecRunner Test
|
|
||||||
|
|
||||||
# Input
|
|
||||||
HEADERS += HeadlessSpecRunner/ConsoleOutput.h \
|
|
||||||
HeadlessSpecRunner/Page.h \
|
|
||||||
HeadlessSpecRunner/Runner.h \
|
|
||||||
Test/Page_test.h
|
|
||||||
SOURCES += specrunner.cpp \
|
|
||||||
HeadlessSpecRunner/ConsoleOutput.cpp \
|
|
||||||
HeadlessSpecRunner/Page.cpp \
|
|
||||||
HeadlessSpecRunner/Runner.cpp \
|
|
||||||
Test/Page_test.cpp
|
|
@ -25,9 +25,81 @@ module Jasmine
|
|||||||
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
class << self
|
def self.run(options = {})
|
||||||
def run(options = {})
|
new(options).run
|
||||||
new(options).run
|
end
|
||||||
|
|
||||||
|
def self.server_port
|
||||||
|
return @server_port if @server_port
|
||||||
|
|
||||||
|
count = 100
|
||||||
|
begin
|
||||||
|
port = select_server_port
|
||||||
|
|
||||||
|
socket = TCPSocket.new(server_interface, port)
|
||||||
|
socket.close
|
||||||
|
|
||||||
|
count -= 1
|
||||||
|
|
||||||
|
raise "Could not create server port after 100 attempts!" if count == 0
|
||||||
|
rescue Errno::ECONNREFUSED
|
||||||
|
@server_port = port
|
||||||
|
|
||||||
|
break
|
||||||
|
ensure
|
||||||
|
begin
|
||||||
|
socket.close if socket
|
||||||
|
rescue IOError
|
||||||
|
end
|
||||||
|
end while true
|
||||||
|
|
||||||
|
@server_port
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.select_server_port
|
||||||
|
21000 + rand(10000)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.server_interface
|
||||||
|
'127.0.0.1'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.server_uri
|
||||||
|
"http://#{server_interface}:#{server_port}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ensure_server
|
||||||
|
return if @server
|
||||||
|
|
||||||
|
require 'webrick'
|
||||||
|
require 'thread'
|
||||||
|
require 'rack'
|
||||||
|
require 'net/http'
|
||||||
|
|
||||||
|
port = server_port
|
||||||
|
|
||||||
|
@server = Thread.new do
|
||||||
|
Jasmine::Headless.warn "Powering up!"
|
||||||
|
|
||||||
|
Rack::Handler::WEBrick.run(
|
||||||
|
Rack::File.new('/'),
|
||||||
|
:Port => port,
|
||||||
|
:Logger => Logger.new(StringIO.new),
|
||||||
|
:AccessLog => [
|
||||||
|
[ StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
||||||
|
[ StringIO.new, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
begin
|
||||||
|
Net::HTTP.get(URI(server_uri))
|
||||||
|
break
|
||||||
|
rescue Errno::ECONNREFUSED => e
|
||||||
|
end
|
||||||
|
|
||||||
|
sleep 0.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,7 +137,7 @@ module Jasmine
|
|||||||
command += targets.flatten.collect do |target|
|
command += targets.flatten.collect do |target|
|
||||||
target = File.expand_path(target)
|
target = File.expand_path(target)
|
||||||
if options[:use_server]
|
if options[:use_server]
|
||||||
target = server_uri + target
|
target = self.class.server_uri + target
|
||||||
else
|
else
|
||||||
target = "file://" + target
|
target = "file://" + target
|
||||||
end
|
end
|
||||||
@ -125,53 +197,14 @@ module Jasmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def wrap_in_server
|
def wrap_in_server
|
||||||
require 'webrick'
|
self.class.ensure_server
|
||||||
require 'thread'
|
|
||||||
require 'rack'
|
|
||||||
require 'net/http'
|
|
||||||
|
|
||||||
server = Thread.new do
|
Jasmine::Headless.warn "HTTP powered specs! Located at #{self.class.server_uri}"
|
||||||
Rack::Handler::WEBrick.run(
|
|
||||||
Rack::File.new('/'),
|
|
||||||
:Port => server_port,
|
|
||||||
:Logger => Logger.new(StringIO.new),
|
|
||||||
:AccessLog => [
|
|
||||||
[ StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
|
||||||
[ StringIO.new, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
while true do
|
|
||||||
begin
|
|
||||||
Net::HTTP.get(URI(server_uri))
|
|
||||||
break
|
|
||||||
rescue Errno::ECONNREFUSED => e
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep 0.1
|
|
||||||
end
|
|
||||||
|
|
||||||
Jasmine::Headless.warn "HTTP powered specs!"
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
Thread.kill(server)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def server_port
|
|
||||||
@server_port ||= 21000 + rand(1000)
|
|
||||||
end
|
|
||||||
|
|
||||||
def server_interface
|
|
||||||
'127.0.0.1'
|
|
||||||
end
|
|
||||||
|
|
||||||
def server_uri
|
|
||||||
"http://#{server_interface}:#{server_port}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def jasmine_config_data
|
def jasmine_config_data
|
||||||
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ describe Jasmine::Headless::Runner do
|
|||||||
before do
|
before do
|
||||||
options[:use_server] = true
|
options[:use_server] = true
|
||||||
|
|
||||||
runner.stubs(:server_uri).returns(server_uri)
|
described_class.stubs(:server_uri).returns(server_uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should include(server_uri + File.expand_path(target)) }
|
it { should include(server_uri + File.expand_path(target)) }
|
||||||
@ -206,4 +206,24 @@ describe Jasmine::Headless::Runner do
|
|||||||
subject.options[:reporters].should == reporters
|
subject.options[:reporters].should == reporters
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.server_port' do
|
||||||
|
before do
|
||||||
|
described_class.instance_variable_set(:@server_port, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'port in use' do
|
||||||
|
require 'socket'
|
||||||
|
|
||||||
|
before do
|
||||||
|
described_class.stubs(:select_server_port).returns(5000, 5001)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should try another port' do
|
||||||
|
server = TCPServer.new(described_class.server_interface, 5000)
|
||||||
|
|
||||||
|
described_class.server_port.should == 5001
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user