Sha256: 529822203a2ae0e388cf0500e81858dafd03ebf6d3e0b8d44fee32725402ac00

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

module EndWithMatcher
  class EndWith
    def initialize(expected)
      @expected = expected
    end

    def matches?(target)
      @target = target
      @target =~ /#{@expected}$/
    end

    def failure_message
      "expected <#{to_string(@target)}> to " +
      "end with <#{to_string(@expected)}>"
    end

    def negative_failure_message
      "expected <#{to_string(@target)}> not to " +
      "end with <#{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 end_with(expected)
    EndWith.new(expected)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
couch_blog-0.6.0 spec/support/end_with_matcher.rb