Module: Tap::Test::HttpTest

Defined in:
lib/tap/test/http_test.rb

Overview

HttpTest facilitates testing of HTTP requests by initializing a Webrick server that echos requests, and providing methods to validate echoed requests.

Defined Under Namespace

Classes: EchoServer, MockServer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



38
39
40
# File 'lib/tap/test/http_test.rb', line 38

def self.included(base)
  base.send(:include, Tap::Test::SubsetTest)
end

Instance Method Details

#default_config(log_dev = StringIO.new('')) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/tap/test/http_test.rb', line 42

def default_config(log_dev=StringIO.new(''))
  common_logger = WEBrick::Log.new(log_dev, WEBrick::Log.const_get(:WARN) )
  {
    :Port => 2000,
    :Logger => common_logger,
    :AccessLog => common_logger
  }
end

#web_test(app = EchoServer, config = default_config) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tap/test/http_test.rb', line 51

def web_test(app=EchoServer, config=default_config)
  subset_test("WEB", "w") do
    begin
      server = ::WEBrick::HTTPServer.new(config); 
      server.mount("/", Rack::Handler::WEBrick, app); 
      Thread.new { server.start }
      yield
    ensure
      server.shutdown
    end
  end
end