diff options
author | Azul <azul@riseup.net> | 2016-06-20 12:16:27 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-06-20 13:29:43 +0200 |
commit | b185742d959a0a3854c5e628354a538a15bdea15 (patch) | |
tree | 331cfb3d07f49f1e12e5cbf50f63e80692e0868f /test | |
parent | 6925fc2fe17d7e22e22af664171cd98956c62cf1 (diff) |
seperate generic RequestHandler from EmServer
The request handler takes a responder (the EmServer) and an adapter as initialization arguments.
It will then respond to requests by querying the sources using the adapter and calling send_response on the responder.
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 |