diff options
author | azul <azul@riseup.net> | 2016-09-23 06:45:18 +0000 |
---|---|---|
committer | azul <azul@riseup.net> | 2016-09-23 06:45:18 +0000 |
commit | 6721f0732facd87404eecc288357fd1bd0de48cf (patch) | |
tree | 58b0f80b545987d5fc7f3dfdd4a3c1563cbc216e /test/unit/handler_chain_test.rb | |
parent | e2aedcaade71dfe9103fdc8e705f59ece5f3a4d0 (diff) | |
parent | 68ffe9928620d3e5e3b96152ed4d37da90f6a89b (diff) |
Merge branch 'feature/deal-with-network-failures' into 'master'
Feature/deal with network failures
Also activates the new nicknym lookup.
See merge request !5
Diffstat (limited to 'test/unit/handler_chain_test.rb')
-rw-r--r-- | test/unit/handler_chain_test.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/unit/handler_chain_test.rb b/test/unit/handler_chain_test.rb new file mode 100644 index 0000000..fae0418 --- /dev/null +++ b/test/unit/handler_chain_test.rb @@ -0,0 +1,68 @@ +require 'test_helper' +require 'nickserver/handler_chain' + +class HandlerChainTest < Minitest::Test + + def test_initialization + assert chain + end + + def test_noop + assert_nil chain.handle + end + + def test_triggering_handlers + handler_mock.expect :call, nil, [:a, :b] + chain handler_mock + chain.handle :a, :b + handler_mock.verify + end + + def test_returns_handler_result + chain handler_with_nil, handler_with_result + assert_equal :result, chain.handle + end + + def test_raise_exception + chain handler_raising, handler_with_result + assert_raises RuntimeError do + chain.handle + end + end + + def test_continue_on_exception + chain handler_raising, handler_with_result + chain.continue_on(RuntimeError) + assert_equal :result, chain.handle + assert_equal [RuntimeError], chain.rescued_exceptions.map(&:class) + end + + def test_continue_on_exception_with_nil + chain handler_raising, handler_with_nil + chain.continue_on(RuntimeError) + assert_nil chain.handle + assert_equal [RuntimeError], chain.rescued_exceptions.map(&:class) + end + + protected + + def chain(*handlers) + @chain ||= Nickserver::HandlerChain.new(*handlers) + end + + def handler_mock + @handler ||= Minitest::Mock.new + end + + def handler_with_nil + Proc.new {} + end + + def handler_with_result + Proc.new { :result } + end + + def handler_raising(exception = RuntimeError) + Proc.new { raise exception } + end +end |