Sha256: a4766baee453c735f00017ee289437eb3746ecc15cbaff1a0a8839eb1cf4d1da

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

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

class TestPeddlerErrorsHandler < MiniTest::Test
  def setup
    @error = Peddler::Errors::Handler.call(@cause)
  rescue => @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

6 entries across 6 versions & 1 rubygems

Version Path
peddler-1.6.2 test/unit/peddler/errors/test_handler.rb
peddler-1.6.1 test/unit/peddler/errors/test_handler.rb
peddler-1.6.0 test/unit/peddler/errors/test_handler.rb
peddler-1.5.0 test/unit/peddler/errors/test_handler.rb
peddler-1.4.1 test/unit/peddler/errors/test_handler.rb
peddler-1.4.0 test/unit/peddler/errors/test_handler.rb