Skip to content
This repository
Newer
Older
100644 67 lines (56 sloc) 1.611 kb
be391882 »
2010-03-07 Fixing the first integration test
1 require File.dirname(__FILE__) + '/../test_helper'
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
2 require 'net/telnet'
0aa0a5ed »
2010-05-15 Adding the HttpRefuseAllCredentials behavior which always returns 401…
3 require 'open-uri'
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
4
5 class BaneIntegrationTest < Test::Unit::TestCase
6
be391882 »
2010-03-07 Fixing the first integration test
7 TEST_PORT = 4000
8
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
9 def test_uses_specified_port_and_server
1cc54de3 »
2010-05-04 Parsing configurations with default option overrides
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"
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
13 end
14 end
be391882 »
2010-03-07 Fixing the first integration test
15 end
16
1cc54de3 »
2010-05-04 Parsing configurations with default option overrides
17 def test_uses_behavior_options
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
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
1cc54de3 »
2010-05-04 Parsing configurations with default option overrides
23 telnet_to TEST_PORT do |response|
24 assert_equal expected_message, response, "Wrong response from server"
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
25 end
26 end
be391882 »
2010-03-07 Fixing the first integration test
27 end
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
28
0aa0a5ed »
2010-05-15 Adding the HttpRefuseAllCredentials behavior which always returns 401…
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
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
41 private
42
3e3c315d »
2010-05-12 Requiring 'stringio' in test helper, which is used in many tests and …
43 def run_server_with(*options)
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
44 begin
4e3fbc19 »
2010-05-04 Launcher can now be configured with a Logger instance. Deleting the U…
45 launcher = Bane::Launcher.new(Configuration(*options), quiet_logger)
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
46 launcher.start
47 yield
48 ensure
0aa0a5ed »
2010-05-15 Adding the HttpRefuseAllCredentials behavior which always returns 401…
49 launcher.stop if launcher
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
50 end
51 end
be391882 »
2010-03-07 Fixing the first integration test
52
4e3fbc19 »
2010-05-04 Launcher can now be configured with a Logger instance. Deleting the U…
53 def quiet_logger
54 StringIO.new
55 end
56
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
57 def telnet_to(port)
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
58 begin
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
59 telnet = Net::Telnet::new("Host" => "localhost",
6863aee2 » Aldric Giacomoni
2010-05-11 fixed the private 'telnet_to' method in integration_test (it used TES…
60 "Port" => port,
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
61 "Timeout" => 5)
1cc54de3 »
2010-05-04 Parsing configurations with default option overrides
62 yield telnet.read
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
63 ensure
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
64 telnet.close
da4963e0 » Daniel Wellman
2010-03-02 Starting to write an integration test, though it's failing right now
65 end
66 end
7ae0d064 »
2010-05-02 Extracting Configuration bits into a ConfigurationParser, so now Conf…
67 end
Something went wrong with that request. Please try again.