summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-07-24 11:02:48 +0200
committerAzul <azul@riseup.net>2017-07-24 11:02:48 +0200
commit3250015cc6e6a14a550a83cd7d5fe6faefc5e185 (patch)
treed6035f62e49076c6999efc7b63c853169b9af7c7
parenteda9a0829b670975244f39b89b23ac2695493e75 (diff)
test: minor: add http adapter test
-rw-r--r--test/unit/adapters/http_test.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/unit/adapters/http_test.rb b/test/unit/adapters/http_test.rb
new file mode 100644
index 0000000..f6768df
--- /dev/null
+++ b/test/unit/adapters/http_test.rb
@@ -0,0 +1,41 @@
+require 'test_helper'
+require 'http'
+require 'nickserver/adapters/http'
+
+class HttpAdapterTest < Minitest::Test
+
+ def test_normal_raise
+ stub_http_to_raise do
+ assert_raises HTTP::ConnectionError do
+ adapter.get ''
+ end
+ end
+ end
+
+ def test_rescueing
+ stub_http_to_raise do
+ assert_nil adapter.get('', rescue: 'some reason')
+ end
+ end
+
+ def test_raise_not_rescued
+ stub_http_to_raise do
+ assert_raises Http::ConnectionError do
+ assert adapter.get('', rescue: 'some other reason')
+ end
+ end
+ end
+
+ protected
+
+ def stub_http_to_raise(&block)
+ raises_exception = -> (*_args) {
+ raise HTTP::ConnectionError, 'for some reason'
+ }
+ HTTP.stub :get, raises_exception, &block
+ end
+
+ def adapter
+ Nickserver::Adapters::Http.new
+ end
+end