summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2017-07-24 10:00:01 +0000
committerazul <azul@riseup.net>2017-07-24 10:00:01 +0000
commit96a82fbfa5f0ba7d00a0f3e8b95942f05b1211fa (patch)
treed6035f62e49076c6999efc7b63c853169b9af7c7 /test
parenteda9a0829b670975244f39b89b23ac2695493e75 (diff)
parent3250015cc6e6a14a550a83cd7d5fe6faefc5e185 (diff)
Merge branch 'test/http-adapter' into 'master'
test: minor: add http adapter test See merge request !16
Diffstat (limited to '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