summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-06-21 11:54:32 +0200
committerGitHub <noreply@github.com>2016-06-21 11:54:32 +0200
commit27196b87e8d0ce5325381ea96ccd68ced8ee2e4d (patch)
tree331cfb3d07f49f1e12e5cbf50f63e80692e0868f /test
parent3c6dc3d7b902b46b82a3d8cd38bd3fa896024beb (diff)
parentb185742d959a0a3854c5e628354a538a15bdea15 (diff)
Merge pull request #4 from azul/refactor/separate-em-server
refactor: separate em specifics from generic server
Diffstat (limited to 'test')
-rw-r--r--test/unit/request_handler_test.rb41
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