Sha256: a3015a0591b116c02b5be71c02fc4f94684a0877a22beab78075c7f49bf99cbf

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'helper'
require 'peddler/errors/handler'

class TestPeddlerErrorsHandler < MiniTest::Test
  def setup
    @error = Peddler::Errors::Handler.call(@cause)
  rescue StandardError => @error
  end

  class CausedByHTTPStatusError < TestPeddlerErrorsHandler
    def setup
      @code = 'FeedProcessingResultNotReady'
      @message = 'Feed Submission Result is not ready for Feed 123'
      @cause = Excon::Error::NotFound.new(
        'Expected(200) <=> Actual(404 Not Found)',
        nil,
        OpenStruct.new(code: @code, message: @message)
      )
      super
    end

    def test_generates_custom_error
      assert_includes @error.class.name, @code
    end

    def test_provides_message
      assert_equal @message, @error.message
    end

    def test_provides_cause
      assert_equal @cause, @error.cause
    end
  end

  class CausedByAnotherError < TestPeddlerErrorsHandler
    def setup
      @cause = StandardError.new
      super
    end

    def test_returns_original_error
      assert_equal @cause, @error
    end
  end

  class CausedByInternalServerError < TestPeddlerErrorsHandler
    def setup
      @cause = Excon::Error::InternalServerError.new(
        nil,
        nil,
        OpenStruct.new(code: '500', message: nil)
      )
      super
    end

    def test_returns_original_error
      assert_equal @cause, @error
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
peddler-1.6.7 test/unit/peddler/errors/test_handler.rb
peddler-1.6.6 test/unit/peddler/errors/test_handler.rb
peddler-1.6.5 test/unit/peddler/errors/test_handler.rb
peddler-1.6.4 test/unit/peddler/errors/test_handler.rb