Sha256: c678db98e01b8c5841f570cf9e33dd4e19e01d66fe55baf71210bc4f788f7fd6

Contents?: true

Size: 903 Bytes

Versions: 6

Compression:

Stored size: 903 Bytes

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.5.1 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.5.0 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.4.0 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.3.0 spec/support/matchers/type/attribute_matcher.rb
fortnox-api-0.2.0 spec/support/matchers/type/attribute_matcher.rb