bane 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
- require 'bane'
3
-
4
- include Bane
5
-
6
- launcher = Launcher.new(Configuration(3000, Behaviors::CloseImmediately, Behaviors::CloseAfterPause))
7
- launcher.start
8
- launcher.join
9
- # runs until interrupt...
@@ -1,7 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
- require 'bane'
3
-
4
- launcher = Bane::Launcher.new(Configuration(3000, "CloseImmediately"))
5
- launcher.start
6
- launcher.join
7
- # runs until interrupt...
@@ -1,16 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
- require 'bane'
3
-
4
- include Bane
5
- include Behaviors
6
-
7
- launcher = Launcher.new(Configuration(
8
- 10256 => {:behavior => CloseAfterPause, :duration => 3},
9
- 10593 => {:behavior => FixedResponse, :message => "Hey!"},
10
- 10689 => {:behavior => SlowResponse, :message => "Custom message", :pause_duration => 15},
11
- 11239 => CloseAfterPause # Use the defaults for this behavior, don't need a Hash
12
- )
13
- )
14
- launcher.start
15
- launcher.join
16
- # runs until interrupt...
@@ -1,15 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
- require 'bane'
3
-
4
- include Bane
5
- include Behaviors
6
-
7
- launcher = Launcher.new(Configuration(
8
- 10256 => CloseAfterPause,
9
- 10689 => CloseAfterPause, # severs may be repeated
10
- 11999 => CloseImmediately
11
- )
12
- )
13
- launcher.start
14
- launcher.join
15
- # runs until interrupt...
@@ -1,50 +0,0 @@
1
- module Bane
2
-
3
- class Configuration
4
-
5
- def initialize(configurations)
6
- @configurations = configurations
7
- end
8
-
9
- def start(logger)
10
- @configurations.map do |config|
11
- config.start(logger)
12
- end
13
- end
14
-
15
- class ConfigurationRecord
16
-
17
- def initialize(port, behavior, options = {})
18
- @port = port
19
- @behavior = behavior
20
- @options = options
21
- end
22
-
23
- def start(logger)
24
- new_server = DelegatingGServer.new(@port, @behavior.new, @options, logger)
25
- new_server.start
26
- new_server
27
- end
28
- end
29
-
30
- end
31
-
32
- class ConfigurationError < RuntimeError; end
33
-
34
- class UnknownBehaviorError < RuntimeError
35
- def initialize(name)
36
- super "Unknown behavior: #{name}"
37
- end
38
- end
39
-
40
- end
41
-
42
- # Helper method to easily create configuration.
43
- #
44
- # This should likely take the constructor block from the Configuration class
45
- # and then we can simplify this class so it's not so big.
46
- module Kernel
47
- def Configuration(*args)
48
- Bane::Configuration.new(Bane::ConfigurationParser.new(*args).configurations)
49
- end
50
- end
@@ -1,52 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'mocha'
3
-
4
- module Bane
5
- module Behaviors
6
- class FakeTestServer < BasicBehavior
7
- end
8
- end
9
- end
10
-
11
- class ConfigurationTest < Test::Unit::TestCase
12
-
13
- include Bane
14
-
15
- def test_starts_server_on_specified_port
16
- target_port = 4000
17
- DelegatingGServer.expects(:new).with(equals(target_port), anything(), anything(), anything()).returns(fake_server)
18
-
19
- start_configuration(target_port, Behaviors::FakeTestServer)
20
- end
21
-
22
- def test_starts_server_with_specified_behavior
23
- behavior_instance = stub('constructed behavior instance')
24
- Behaviors::FakeTestServer.expects(:new).returns(behavior_instance)
25
- DelegatingGServer.expects(:new).with(anything(), equals(behavior_instance), anything(), anything()).returns(fake_server)
26
-
27
- start_configuration(IRRELEVANT_PORT, Behaviors::FakeTestServer)
28
- end
29
-
30
- def test_constructs_server_with_specified_options
31
- options = { :an_option => :a_value, :another_option => :another_value }
32
- DelegatingGServer.expects(:new).with(anything(), anything, has_entries(options), anything()).returns(fake_server)
33
-
34
- start_configuration(IRRELEVANT_PORT, Behaviors::FakeTestServer, options)
35
- end
36
-
37
- private
38
-
39
- def start_configuration(target_port, behavior, options = {})
40
- configuration = configuration_with(target_port, behavior, options)
41
- configuration.start(StringIO.new)
42
- end
43
-
44
- def configuration_with(port, behavior, options)
45
- Configuration.new([Configuration::ConfigurationRecord.new(port, behavior, options)])
46
- end
47
-
48
- def fake_server
49
- stub_everything('fake_server')
50
- end
51
-
52
- end
@@ -1,16 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'mocha'
3
-
4
- class LauncherTest < Test::Unit::TestCase
5
-
6
- include Bane
7
-
8
- def test_start_delegates_to_configuration
9
- configuration = mock()
10
- logger = stub()
11
- launcher = Launcher.new(configuration, logger)
12
-
13
- configuration.expects(:start).with(equals(logger))
14
- launcher.start
15
- end
16
- end