Sha256: 529b9b043dc7d68b79fa873cfed844dc677f282b570b6334af00f9d484396f54
Contents?: true
Size: 902 Bytes
Versions: 17
Compression:
Stored size: 902 Bytes
Contents
require 'diff/lcs' RSpec::Matchers.define :have_different_contents do |x| match 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 failure_message_for_should do |actual| "expected a difference, but got none" end failure_message_for_should_not do |actual| "expected no difference, but got:\n#{@diff}" end end
Version data entries
17 entries across 17 versions & 1 rubygems