Sha256: 5dbdd1042f3d570095ab855fae69a81f06923df8a2040a88a4e2cdb165532d87

Contents?: true

Size: 877 Bytes

Versions: 6

Compression:

Stored size: 877 Bytes

Contents

require "warp/model_matchers/matcher"

module Warp
  module ModelMatchers
    class AttributeMatcher < Warp::ModelMatchers::Matcher
      attr_reader :attr_name

      def initialize(attr_name)
        @attr_name = attr_name.to_sym
      end

      def matches?(model_or_instance)
        @model_or_instance = model_or_instance

        attributes.any? {|actual| values_match?(attr_name, actual) }
      end

      def description
        "have attribute #{description_of(attr_name)}"
      end

      def failure_message
        "expected #{model_name} to #{description}"
      end

      def failure_message_when_negated
        "expected #{model_name} to not #{description}"
      end

      private

      def attributes
        model.attribute_names.map(&:to_sym)
      end
    end

    def have_attribute(attr_name)
      AttributeMatcher.new(attr_name)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
warp-1.5.0 lib/warp/model_matchers/attribute_matcher.rb
warp-1.4.0 lib/warp/model_matchers/attribute_matcher.rb
warp-1.3.3 lib/warp/model_matchers/attribute_matcher.rb
warp-1.3.2 lib/warp/model_matchers/attribute_matcher.rb
warp-1.3.1 lib/warp/model_matchers/attribute_matcher.rb
warp-1.3.0 lib/warp/model_matchers/attribute_matcher.rb