Skip to content

Commit

Permalink
Switch from test to spec, add internal test server
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Ball committed Aug 20, 2009
1 parent 58a3bd3 commit cf077f7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
32 changes: 26 additions & 6 deletions test/test_curl-multi.rb → spec/curl-multi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,41 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

require File.dirname(__FILE__) + '/test_helper.rb'
require File.dirname(__FILE__) + '/spec_helper.rb'

class TestCurlMulti < Test::Unit::TestCase
def setup
describe 'Curl::Multi' do
before(:all) do
puts "setting up server\n"
@port = 9192
@server_process = Process.fork do
$stdout.reopen('log/test_server.stdout', 'w')
$stderr.reopen('log/test_server.stderr', 'w')
CurlTestServer.run! :host => 'localhost', :port => @port
end
@server = "http://localhost:#{@port}"
sleep(1) #give server time to boot
end

before(:each) do
@curl_multi = Curl::Multi.new
end

after(:all) do
puts "\nTearing down server"
@curl_multi.post("#{@server}/flush", {}, lambda {}, lambda {})
@curl_multi.select([], []) while @curl_multi.size > 0
Process.kill('KILL', @server_process)
end

def test_get
it "Should be able to get one ok" do
c = Curl::Multi.new()
success = lambda do |body|
assert body.include? 'html'
body.should eql('ok')
end
failure = lambda do |ex|
fail ex
end
c.get('http://www.google.com/', success, failure)
c.get("#{@server}/ok", success, failure)
c.select([], []) while c.size > 0
end
end
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require File.dirname(__FILE__) + '/../lib/curl-multi'
require File.dirname(__FILE__) + '/test_server.rb'
require 'spec/autorun'
require 'spork'

Spork.prefork do
Spec::Runner.configure do |config|
config.mock_with :mocha
end
end

Spork.each_run do
end
26 changes: 26 additions & 0 deletions spec/test_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'rubygems'
require 'sinatra/base'

class CurlTestServer < Sinatra::Base
get '/sleep/:time' do
sleep(params[:time].to_f)
"ok"
end

get '/ok' do
"ok"
end

get '/error' do
raise
end

get '/redirect/:dest' do
redirect params[:dest]
end
post '/flush' do
$stdout.flush
$stderr.flush
'ok'
end
end
2 changes: 0 additions & 2 deletions test/test_helper.rb

This file was deleted.

0 comments on commit cf077f7

Please sign in to comment.