Sha256: fd0859fbf5a0f5e0ebeeda3c4b31769d9e51d0cec46eff9d2f8a37f8fc2bd73c

Contents?: true

Size: 943 Bytes

Versions: 13

Compression:

Stored size: 943 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'

Dir[File.dirname(__FILE__)+"/helpers/**rb"].each do |helper| require helper; end

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

13 entries across 13 versions & 1 rubygems

Version Path
activefacts-1.6.0 spec/spec_helper.rb
activefacts-1.5.3 spec/spec_helper.rb
activefacts-1.5.2 spec/spec_helper.rb
activefacts-1.5.1 spec/spec_helper.rb
activefacts-1.5.0 spec/spec_helper.rb
activefacts-1.3.0 spec/spec_helper.rb
activefacts-1.2.1 spec/spec_helper.rb
activefacts-1.2.0 spec/spec_helper.rb
activefacts-1.1.0 spec/spec_helper.rb
activefacts-1.0.2 spec/spec_helper.rb
activefacts-1.0.1 spec/spec_helper.rb
activefacts-1.0.0 spec/spec_helper.rb
activefacts-0.8.18 spec/spec_helper.rb