Sha256: 0eab185a72dbc4157433ee3e3be741fc65e836619b3fa1af8093b7dd71a87bd3

Contents?: true

Size: 785 Bytes

Versions: 2

Compression:

Stored size: 785 Bytes

Contents

# frozen_string_literal: true

class BCDD::Result::Expectations
  class TypeChecker
    attr_reader :result_type, :expectations

    def initialize(result_type, expectations:)
      @result_type = result_type

      @expectations = expectations
    end

    def allow?(types)
      validate(types, expected: expectations, allow_empty: false)
    end

    def allow_success?(types)
      validate(types, expected: expectations.success, allow_empty: true)
    end

    def allow_failure?(types)
      validate(types, expected: expectations.failure, allow_empty: true)
    end

    private

    def validate(types, expected:, allow_empty:)
      (allow_empty && types.empty?) || types.any? { |type| expected.type!(type) == result_type }
    end
  end

  private_constant :TypeChecker
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bcdd-result-0.6.0 lib/bcdd/result/expectations/type_checker.rb
bcdd-result-0.5.0 lib/bcdd/result/expectations/type_checker.rb