diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/adapters/http_test.rb | 41 |
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 |