Skip to content

Commit

Permalink
Run the functional test on Peck.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed May 15, 2013
1 parent e05218a commit bb7462e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
46 changes: 27 additions & 19 deletions test/functional_test.rb
@@ -1,34 +1,42 @@
TEST_ROOT = File.expand_path('../', __FILE__)
TEST_ROOT = File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../lib', TEST_ROOT)

begin
require 'rubygems'
rescue
end

require 'test/spec'
require 'mocha'

$:.unshift File.expand_path('lib', TEST_ROOT)

pid = Process.fork
if pid.nil? then
if pid.nil?
exec "/usr/bin/env ruby #{File.expand_path('lib/http_server.rb', TEST_ROOT)}"
else
require 'rest'


require 'peck'
require 'peck/delegates'
require 'peck/counter'
require 'peck/context'
require 'peck/specification'
require 'peck/expectations'
require 'peck/notifiers/default'

class FunctionalNotifier < Peck::Notifiers::Default
def finished_specification(spec)
end
end

notifier = FunctionalNotifier.new
Peck.delegates << notifier

at_exit do
Peck.run
Process.kill('SIGKILL', pid)
notifier.write_stats
end

describe "A remote REST Request" do
BASE_URL = 'http://localhost:32776'

after(:all) do
Process.kill('SIGKILL', pid)
end


it "returns the body of the response" do
response = REST.get(BASE_URL + '/')
response.body.should == "OK!\n"
end

it "does stuff when the server disconnects" do
begin
REST.get(BASE_URL + '/disconnect')
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Expand Up @@ -17,7 +17,7 @@
require 'file_fixtures'

require 'peck/flavors/vanilla'

# The once block is ran once when the context is initialized
Peck::Context.once do |context|
include Test::FileFixtures
Expand Down
3 changes: 2 additions & 1 deletion test/lib/http_server.rb
Expand Up @@ -26,8 +26,8 @@ def response(client, status, body)

def run
server = TCPServer.new(PORT)
puts "Webserver running on #{PORT}"
loop do
puts "Webserver running on #{PORT}"
Thread.start(server.accept) do |client|
begin
request_line = client.gets
Expand All @@ -54,6 +54,7 @@ def run
client.close
end
end
puts "Webserver shutting down"
end

def log(message)
Expand Down

0 comments on commit bb7462e

Please sign in to comment.