Sha256: 2bca0a7d7933b41ae34db03b29073c5f87f8d5b3f9b615fd6cd836cf3c0ae81f
Contents?: true
Size: 1.39 KB
Versions: 3
Compression:
Stored size: 1.39 KB
Contents
require File.join(File.dirname(__FILE__), 'test_helper') describe HammerCLI::ExceptionHandler do before(:each) do @log_output = Logging::Appenders['__test__'] @log_output.reset end let(:output) { HammerCLI::Output::Output.new } let(:handler) { HammerCLI::ExceptionHandler.new(:output => output)} let(:heading) { "Something went wrong" } it "should handle unauthorized" do output.expects(:print_error).with(heading, "Invalid username or password") handler.handle_exception(RestClient::Unauthorized.new, :heading => heading) end it "should handle general exception" do output.expects(:print_error).with(heading, "Error: message") handler.handle_exception(Exception.new('message'), :heading => heading) end it "should handle unknown exception" do output.expects(:print_error).with(heading, "Error: message") MyException = Class.new(Exception) handler.handle_exception(MyException.new('message'), :heading => heading) end it "should handle resource not found" do ex = RestClient::ResourceNotFound.new output.expects(:print_error).with(heading, ex.message) handler.handle_exception(ex, :heading => heading) end it "should log the error" do ex = RestClient::ResourceNotFound.new output.default_adapter = :silent handler.handle_exception(ex) @log_output.readline.strip.must_equal 'ERROR Exception : Resource Not Found' end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hammer_cli-0.0.12 | test/unit/exception_handler_test.rb |
hammer_cli-0.0.11 | test/unit/exception_handler_test.rb |
hammer_cli-0.0.10 | test/unit/exception_handler_test.rb |