From feba881729ec4edd9b9bd9b4716df36b34760efc Mon Sep 17 00:00:00 2001 From: "Peter M. Goldstein" Date: Tue, 22 Jan 2013 15:03:42 -0800 Subject: [PATCH] Add support for diff-lcs 1.2.x while maintaining backwards compatibility with diff-lcs 1.1.3. Updated gemspec to support either as a runtime dependency. --- lib/rspec/expectations/differ.rb | 8 +++++++- rspec-expectations.gemspec | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rspec/expectations/differ.rb b/lib/rspec/expectations/differ.rb index 38bd47d46..8aeb23dc1 100644 --- a/lib/rspec/expectations/differ.rb +++ b/lib/rspec/expectations/differ.rb @@ -25,7 +25,13 @@ def diff_as_string(data_new, data_old) # diff includes lines of context. Otherwise, we might print # redundant lines. if (context_lines > 0) and hunk.overlaps?(oldhunk) - hunk.unshift(oldhunk) + if hunk.respond_to?(:merge) + # diff-lcs 1.2.x + hunk.merge(oldhunk) + else + # diff-lcs 1.1.3 + hunk.unshift(oldhunk) + end else output << oldhunk.diff(format) end diff --git a/rspec-expectations.gemspec b/rspec-expectations.gemspec index f66d3d2d2..859a6f9a0 100644 --- a/rspec-expectations.gemspec +++ b/rspec-expectations.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.rdoc_options = ["--charset=UTF-8"] s.require_path = "lib" - s.add_runtime_dependency 'diff-lcs', '~> 1.1.3' + s.add_runtime_dependency 'diff-lcs', '>= 1.1.3' s.add_development_dependency 'rake', '~> 10.0.0' s.add_development_dependency 'cucumber', '~> 1.1.9'