Skip to content

Commit

Permalink
Group tests by feature
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwellman committed Nov 17, 2013
1 parent cedd960 commit dad9028
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions test/bane/command_line_configuration_test.rb
Expand Up @@ -33,6 +33,25 @@ def test_creates_specified_service_on_given_port



def create_configuration_for(array)
CommandLineConfiguration.new(mock('system adapter')).process(array)
end

def expect_behavior_created_with(arguments)
arguments = {port: anything(), host: anything()}.merge(arguments)
behavior_matcher = arguments[:behavior] ? instance_of(arguments[:behavior]) : anything()
Services::BehaviorServer.expects(:new).with(arguments[:port], behavior_matcher, arguments[:host]).returns(Object.new)
end

def expect_service_created_with(arguments)
service_class = arguments.fetch(:service)
port = arguments.fetch(:port)
service_class.expects(:new).with(port, anything()).returns(Object.new)
end


# Parsing the host option

def test_dash_l_option_sets_listen_host_to_localhost
assert_parses_host(Services::DEFAULT_HOST, ['-l', IRRELEVANT_PORT, IRRELEVANT_BEHAVIOR])
end
Expand All @@ -57,14 +76,14 @@ def assert_parses_host(expected_host, arguments)
end


# Failure tests

def test_no_arguments_exits_with_success_and_usage
failure_handler = mock()
failure_handler.expects(:exit_success).with(regexp_matches(/usage/i))
CommandLineConfiguration.new(failure_handler).process([])
end



def test_non_integer_port_fails_with_error_message
assert_invalid_arguments_fail_matching_message(['text_instead_of_an_integer'], /Invalid Port Number/i)
end
Expand All @@ -78,24 +97,6 @@ def test_invalid_option_fails_with_error_message
end


private

def create_configuration_for(array)
CommandLineConfiguration.new(mock('system adapter')).process(array)
end

def expect_behavior_created_with(arguments)
arguments = {port: anything(), host: anything()}.merge(arguments)
behavior_matcher = arguments[:behavior] ? instance_of(arguments[:behavior]) : anything()
Services::BehaviorServer.expects(:new).with(arguments[:port], behavior_matcher, arguments[:host]).returns(Object.new)
end

def expect_service_created_with(arguments)
service_class = arguments.fetch(:service)
port = arguments.fetch(:port)
service_class.expects(:new).with(port, anything()).returns(Object.new)
end

def assert_invalid_arguments_fail_matching_message(arguments, message_matcher)
system = mock('system adapter')
system.expects(:incorrect_usage).with(regexp_matches(message_matcher))
Expand Down

0 comments on commit dad9028

Please sign in to comment.