Sha256: 2fddd7da837927cfe5c0aff3f4977c18c9d137812c242f5379c5c015f9fed33e

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

module BeApproximatelyTheSameColorAsMatcher
  class BeApproximatelyTheSameColorAs
    def initialize(expected)
      @expected = expected
    end

    def matches?(target)
      @target = target
      @target.value.zip(@expected.value).all?{|e,t| (e-t).abs <= 1}
    end

    def failure_message
      "expected <#{to_string(@target)}> to " +
      "be approximately the same as <#{to_string(@expected)}>"
    end

    def negative_failure_message
      "expected <#{to_string(@target)}> not to " +
      "be approximately the same as <#{to_string(@expected)}>"
    end

    # Returns string representation of an object.
    def to_string(value)
      # indicate a nil
      if value.nil?
        'nil'
      end

      # join arrays
      if value.class == Array
        return value.join(", ")
      end

      # otherwise return to_s() instead of inspect()
      return value.to_s
    end
  end

  # Actual matcher that is exposed.
  def be_approximately_the_same_color_as(expected)
    BeApproximatelyTheSameColorAs.new(expected)
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
chriseppstein-compass-colors-0.1.1 spec/approximate_color_matching.rb
chriseppstein-compass-colors-0.1.3 spec/approximate_color_matching.rb
chriseppstein-compass-colors-0.1.4 spec/approximate_color_matching.rb
chriseppstein-compass-colors-0.1.5 spec/approximate_color_matching.rb
chriseppstein-compass-colors-0.2.0 spec/approximate_color_matching.rb
compass-colors-0.3.0 spec/approximate_color_matching.rb
compass-colors-0.2.1 spec/approximate_color_matching.rb
compass-colors-0.2.0 spec/approximate_color_matching.rb