Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (56 sloc) 1.611 kB
be39188 @danielwellman Fixing the first integration test
authored
1 require File.dirname(__FILE__) + '/../test_helper'
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
2 require 'net/telnet'
0aa0a5e @danielwellman Adding the HttpRefuseAllCredentials behavior which always returns 401…
authored
3 require 'open-uri'
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
4
5 class BaneIntegrationTest < Test::Unit::TestCase
6
be39188 @danielwellman Fixing the first integration test
authored
7 TEST_PORT = 4000
8
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
9 def test_uses_specified_port_and_server
1cc54de @danielwellman Parsing configurations with default option overrides
authored
10 run_server_with(TEST_PORT, "FixedResponse") do
11 telnet_to TEST_PORT do |response|
12 assert !response.empty?, "Should have had a non-empty response"
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
13 end
14 end
be39188 @danielwellman Fixing the first integration test
authored
15 end
16
1cc54de @danielwellman Parsing configurations with default option overrides
authored
17 def test_uses_behavior_options
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
18 expected_message = "Expected test message"
19 options = {TEST_PORT => {:behavior => Bane::Behaviors::FixedResponse,
20 :message => expected_message}}
21
22 run_server_with(options) do
1cc54de @danielwellman Parsing configurations with default option overrides
authored
23 telnet_to TEST_PORT do |response|
24 assert_equal expected_message, response, "Wrong response from server"
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
25 end
26 end
be39188 @danielwellman Fixing the first integration test
authored
27 end
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
28
0aa0a5e @danielwellman Adding the HttpRefuseAllCredentials behavior which always returns 401…
authored
29 def test_serves_http_requests
30 run_server_with(TEST_PORT, "HttpRefuseAllCredentials") do
31 begin
32 open("http://localhost:#{TEST_PORT}/some/url").read
33 flunk "Should have refused access"
34 rescue OpenURI::HTTPError => e
35 assert_match /401/, e.message
36 end
37 end
38
39 end
40
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
41 private
42
3e3c315 @danielwellman Requiring 'stringio' in test helper, which is used in many tests and …
authored
43 def run_server_with(*options)
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
44 begin
4e3fbc1 @danielwellman Launcher can now be configured with a Logger instance. Deleting the …
authored
45 launcher = Bane::Launcher.new(Configuration(*options), quiet_logger)
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
46 launcher.start
47 yield
48 ensure
0aa0a5e @danielwellman Adding the HttpRefuseAllCredentials behavior which always returns 401…
authored
49 launcher.stop if launcher
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
50 end
51 end
be39188 @danielwellman Fixing the first integration test
authored
52
4e3fbc1 @danielwellman Launcher can now be configured with a Logger instance. Deleting the …
authored
53 def quiet_logger
54 StringIO.new
55 end
56
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
57 def telnet_to(port)
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
58 begin
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
59 telnet = Net::Telnet::new("Host" => "localhost",
6863aee fixed the private 'telnet_to' method in integration_test (it used TES…
Aldric Giacomoni authored
60 "Port" => port,
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
61 "Timeout" => 5)
1cc54de @danielwellman Parsing configurations with default option overrides
authored
62 yield telnet.read
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
63 ensure
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
64 telnet.close
da4963e Starting to write an integration test, though it's failing right now
Daniel Wellman authored
65 end
66 end
7ae0d06 @danielwellman Extracting Configuration bits into a ConfigurationParser, so now Conf…
authored
67 end
Something went wrong with that request. Please try again.