Sha256: bec29fc883ca50cbfcb153fea8b5e4ff557b88a97dadf40df9543603c0a6fc1b

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'test/unit'
require 'external/test_support'
IWATestSupport.set_src_dir
require 'rbconfig'
require 'net/http'

class TC_Webrick < Test::Unit::TestCase

	@@testdir = IWATestSupport.test_dir(__FILE__)
	def setup
		Dir.chdir(@@testdir)
		IWATestSupport.announce(:webrickmode,"Webrick Run Mode")

		ruby = File.join(::Config::CONFIG['bindir'],::Config::CONFIG['ruby_install_name'])
		ruby << ::Config::CONFIG['EXEEXT']

		assert_nothing_raised("setup failed") do
			@iowa_pid = IWATestSupport::create_process(:dir => 'TC_Webrick/iowa',
				:cmd => ["#{ruby} -I../../../src app.rb -r webrick"])
			sleep 1
		end
	end

	def teardown
		Process.kill "SIGKILL",@iowa_pid
		Process.wait @iowa_pid
		sleep 1
	end

	def get_url(hostname,port,url)
		Net::HTTP.start(hostname,port) {|http| http.get(url)}
	end

	def test_webrick
		r = nil
		assert_nothing_raised("Error trying to send request to iowa app.") do
			response = get_url('127.0.0.1','47990','/')
			r = response.body
		end

		r =~ /<a href="([^"]+)">dynamic link/
		dlink = $1
		assert_match(/<a href="[^"]+">dynamic link/,r,"Failed to find expected dynamic link url.")
			
		dresponse = get_url('127.0.0.1','47990',dlink).body
		assert_match(/The time is now: /,dresponse,"Failed to get expected dynamic link result.")

		r =~ /<a href="([^"]+)">static link/
		slink = $1
		assert_match(/<a href="[^"]+">static link/,r,"Failed to find expected static link url.")

		sresponse = get_url('127.0.0.1','47990',slink).body
		assert_match(/This is a static thing./,sresponse,"Failed to get the expected static link result.")
	end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
IOWA-1.0.3 test/TC_Webrick.rb
IOWA-1.0.2 test/TC_Webrick.rb
IOWA-1.0.0 test/TC_Webrick.rb