Sha256: 47f9562bcaab176ece3adfda2a4e010c76f717d913d04b935cf0948f04d580b5

Contents?: true

Size: 1.08 KB

Versions: 101

Compression:

Stored size: 1.08 KB

Contents

require 'rails_helper'

describe LHS::Record do
  let(:handler) { spy('handler') }

  before(:each) do
    class Record < LHS::Record
      endpoint 'http://local.ch/v2/records'
    end
    stub_request(:get, "http://local.ch/v2/records?color=blue")
      .to_return(status: 400)
  end

  it 'allows to chain error handling' do
    expect {
      Record.where(color: 'blue').handle(LHC::Error, ->(_error) { handler.handle }).first
    }.not_to raise_error
    expect(handler).to have_received(:handle)
  end

  it 'reraises in case chained error is not matched' do
    expect {
      Record.where(color: 'blue').handle(LHC::Conflict, ->(_error) { handler.handle }).first
    }.to raise_error(LHC::Error)
    expect(handler).not_to have_received(:handle)
  end

  it 'calls all the handlers' do
    expect {
      Record.where(color: 'blue')
        .handle(LHC::Error, ->(_error) { handler.handle_1 })
        .handle(LHC::Error, ->(_error) { handler.handle_2 })
        .first
    }.not_to raise_error
    expect(handler).to have_received(:handle_1)
    expect(handler).to have_received(:handle_2)
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
lhs-15.3.1 spec/record/chain_error_handling_spec.rb
lhs-15.3.1.pre.fixlhc.1 spec/record/chain_error_handling_spec.rb
lhs-15.3.0 spec/record/chain_error_handling_spec.rb
lhs-15.2.5 spec/record/chain_error_handling_spec.rb
lhs-15.2.4 spec/record/chain_error_handling_spec.rb
lhs-15.2.3 spec/record/chain_error_handling_spec.rb
lhs-15.2.3.pre.favorites.1 spec/record/chain_error_handling_spec.rb
lhs-15.2.2.pre.favorites.1 spec/record/chain_error_handling_spec.rb
lhs-15.2.2 spec/record/chain_error_handling_spec.rb
lhs-15.2.1 spec/record/chain_error_handling_spec.rb
lhs-15.2.0 spec/record/chain_error_handling_spec.rb
lhs-15.1.1 spec/record/chain_error_handling_spec.rb
lhs-15.1.0 spec/record/chain_error_handling_spec.rb
lhs-15.0.2 spec/record/chain_error_handling_spec.rb
lhs-15.0.1 spec/record/chain_error_handling_spec.rb
lhs-15.0.0 spec/record/chain_error_handling_spec.rb
lhs-14.6.5 spec/record/chain_error_handling_spec.rb
lhs-14.6.4 spec/record/chain_error_handling_spec.rb
lhs-14.6.3 spec/record/chain_error_handling_spec.rb
lhs-14.6.2 spec/record/chain_error_handling_spec.rb