Sha256: 9346b6ae4e5a247ae52b27608fbb9f939f5ef0fa8d0d138909c8e56f4f033b56

Contents?: true

Size: 902 Bytes

Versions: 10

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

module Matchers
  module Type
    class AttributeMatcher
      def initialize(attribute, valid_hash, attribute_type)
        @attribute = attribute
        @valid_hash = valid_hash.dup
        @attribute_type = attribute_type
        @errors = ''
      end

      def matches?(klass)
        @klass = klass
      end

      def description
        "have #{@attribute_type} attribute #{@attribute.inspect}"
      end

      def failure_message
        "Expected class to have attribute #{@attribute.inspect} defined as #{@attribute_type}, "\
        "but got following errors:
        #{@errors}"
      end

      protected

      def expect_error(msg)
        yield

        @errors << msg
        false # Fail test since expected error not thrown
      rescue Dry::Struct::Error
        # TODO: check if error message is correct
        true
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fortnox-api-0.8.2 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.8.1 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.8.0 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.7.2 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.7.1 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.7.0 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.6.3 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.6.2 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.6.1 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.6.0 spec/support/matchers/type/attribute_matcher.rb