Sha256: 25be335dc30bda66d7265ddffe4d2abbd241b89c5434450715c2c958fcb0a0b3
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
require 'diff/lcs' module RSpec module Matchers def have_different_contents(expected) Matcher.new :have_different_contents, expected do |*_expected| match_for_should do |actual| perform_match(actual, _expected) end match_for_should_not do |actual| !perform_match(actual, _expected) end def perform_match(actual, expected) expected_lines = expected.scan(/[^\n]+/) actual_lines = actual.scan(/[^\n]+/) differences = Diff::LCS::diff(expected_lines, actual_lines) @diff = differences.map do |chunk| added_at = (add = chunk.detect{|d| d.action == '+'}) && add.position+1 removed_at = (remove = chunk.detect{|d| d.action == '-'}) && remove.position+1 "Line #{added_at}/#{removed_at}:\n"+ chunk.map do |change| "#{change.action} #{change.element}" end*"\n" end*"\n" @diff != '' end def failure_message_for_should "expected a difference, but got none" end failure_message_for_should_not do |actual| "expected no difference, but got:\n#{@diff}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activefacts-0.8.10 | spec/helpers/string_matcher.rb |