Sha256: 08fc4301e4c61b5db4b24b7c0cae2ea0feea28cb5e6056bd960bd4a76c7b47ea
Contents?: true
Size: 1.59 KB
Versions: 3
Compression:
Stored size: 1.59 KB
Contents
require 'rest-core/test' describe RC::ErrorHandler do client = RC::Builder.client do use RC::ErrorHandler run RC::Dry end exp = Class.new(Exception) describe 'there is an exception' do would 'raise an error with future' do lambda{ client.new.get('/', {}, RC::FAIL => [exp.new('fail')]) }.should.raise(exp) end would 'give an error with callback' do client.new.get('/', {}, RC::FAIL => [exp.new('fail')]){ |res| res.should.kind_of?(exp) } end end describe 'error_handler gives an exception' do would 'raise an error with future' do lambda{ client.new(:error_handler => lambda{ |res| exp.new }). get('/', {}, RC::FAIL => [true]) }.should.raise(exp) end would 'give an error with callback' do client.new(:error_handler => lambda{ |res| exp.new }). get('/', {}, RC::FAIL => [true]){ |res| res.should.kind_of?(exp) } end end would 'no exception but errors' do client.new(:error_handler => lambda{ |res| 1 }). request(RC::FAIL => [0], RC::RESPONSE_KEY => RC::FAIL).should.eq [0, 1] end would 'set full backtrace' do url = 'http://example.com/' client = RC::Builder.client do use RC::ErrorHandler, lambda{ |env| RuntimeError.new(env[RC::RESPONSE_BODY]) } use RC::ErrorDetectorHttp end.new stub_request(:get, url).to_return(:status => 404, :body => 'nnf') client.get(url) do |error| error.message.should.eq 'nnf' error.backtrace.grep(/^#{__FILE__}/).should.not.empty? end client.wait end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rest-core-3.4.1 | test/test_error_handler.rb |
rest-core-3.4.0 | test/test_error_handler.rb |
rest-core-3.3.3 | test/test_error_handler.rb |