diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/request_handler_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/unit/request_handler_test.rb b/test/unit/request_handler_test.rb new file mode 100644 index 0000000..c9d316f --- /dev/null +++ b/test/unit/request_handler_test.rb @@ -0,0 +1,41 @@ +require 'test_helper' +require 'nickserver/request_handler' + +class Nickserver::RequestHandlerTest < Minitest::Test + + def test_empty_query + handle + assert_response status: 404, content: "404 Not Found\n" + end + + def test_invalid_query + handle address: ['asdf'] + assert_response status: 500, content: "500 Not a valid address\n" + end + + protected + + def handle(params = {}, headers = {}) + @params = Hash[ params.map{ |k,v| [k.to_s, v] } ] + @headers = headers + end + + def assert_response(args) + args[:content_type] ||= 'text/plain' + responder.expect :send_response, nil, [args] + handler.respond_to @params, @headers + responder.verify + end + + def handler + Nickserver::RequestHandler.new responder, adapter + end + + def responder + @responder ||= Minitest::Mock.new + end + + def adapter + @adapter ||= Minitest::Mock.new + end +end |