Sha256: a7f51512b0528c97fb9e7ad1b8ec5c17826ff695fbe5d7a87b3443dcb5b810b3

Contents?: true

Size: 861 Bytes

Versions: 5

Compression:

Stored size: 861 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 'helpers/diff_matcher'
require 'helpers/array_matcher'
require 'helpers/file_matcher'
require 'helpers/string_matcher'
require 'helpers/parse_to_ast_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

5 entries across 5 versions & 1 rubygems

Version Path
activefacts-0.8.16 spec/spec_helper.rb
activefacts-0.8.15 spec/spec_helper.rb
activefacts-0.8.13 spec/spec_helper.rb
activefacts-0.8.12 spec/spec_helper.rb
activefacts-0.8.10 spec/spec_helper.rb