Sha256: 8cbc42761b7f4b2bc821c557328f1acccf8488e8526ec0c715daff28b15b14b5
Contents?: true
Size: 842 Bytes
Versions: 2
Compression:
Stored size: 842 Bytes
Contents
# # A Custom Matcher for RSpec that shows the difference between two multi-line strings. # # Usage: # actual_text.should_not differ_from(expected_text) # require 'spec/helpers/diff_matcher' require 'spec/helpers/array_matcher' require 'spec/helpers/file_matcher' require 'spec/helpers/string_matcher' class String def strip_comments() c_comment = %r{/\*((?!\*/).)*\*/}m gsub(c_comment, '').gsub(%r{\n\n+},"\n") end end class Array def diff_strings(a2) d = Diff::LCS::diff(self, a2) d.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" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activefacts-0.8.9 | spec/spec_helper.rb |
activefacts-0.8.8 | spec/spec_helper.rb |