From ba482a558177aedd49883cbd3d4ebfa86e4c9ee7 Mon Sep 17 00:00:00 2001 From: Sam Phippen Date: Wed, 10 Apr 2013 16:15:28 +0100 Subject: [PATCH 1/7] Fixes some weird travis failures noted on master and in #236 Signed-off-by: Sam Phippen --- lib/rspec/expectations/differ.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/rspec/expectations/differ.rb b/lib/rspec/expectations/differ.rb index 4706b0fc4..ac3201b49 100644 --- a/lib/rspec/expectations/differ.rb +++ b/lib/rspec/expectations/differ.rb @@ -16,6 +16,9 @@ def diff_as_string(input_data_new, input_data_old) file_length_difference = 0 diffs.each do |piece| begin + if data_old == [] + data_old = [""] + end hunk = Diff::LCS::Hunk.new( data_old, data_new, piece, context_lines, file_length_difference ) From f2b15a3976ef74d01921771c3087fad1146f94cd Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 11 Apr 2013 15:12:18 +1000 Subject: [PATCH 2/7] force diff-lcs 122 and remove workaround --- lib/rspec/expectations/differ.rb | 8 +------- rspec-expectations.gemspec | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/rspec/expectations/differ.rb b/lib/rspec/expectations/differ.rb index ac3201b49..57813f570 100644 --- a/lib/rspec/expectations/differ.rb +++ b/lib/rspec/expectations/differ.rb @@ -28,13 +28,7 @@ def diff_as_string(input_data_new, input_data_old) # diff includes lines of context. Otherwise, we might print # redundant lines. if (context_lines > 0) and hunk.overlaps?(oldhunk) - if hunk.respond_to?(:merge) - # diff-lcs 1.2.x - hunk.merge(oldhunk) - else - # diff-lcs 1.1.3 - hunk.unshift(oldhunk) - end + hunk.merge(oldhunk) else output << matching_encoding(oldhunk.diff(format).to_s, output) end diff --git a/rspec-expectations.gemspec b/rspec-expectations.gemspec index 1f6b41fd8..8c51d4156 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', '< 2.0' + s.add_runtime_dependency 'diff-lcs', '>= 1.2.2', '< 2.0' s.add_development_dependency 'rake', '~> 10.0.0' s.add_development_dependency 'cucumber', '~> 1.1.9' From ebf6b961f8f1e7087cf7282fa4a120361e7f0c74 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 11 Apr 2013 15:12:41 +1000 Subject: [PATCH 3/7] encoding diff now works thanks to diff-lcs 122 --- spec/rspec/expectations/differ_spec.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/rspec/expectations/differ_spec.rb b/spec/rspec/expectations/differ_spec.rb index 36cf5f25f..7aede1e51 100644 --- a/spec/rspec/expectations/differ_spec.rb +++ b/spec/rspec/expectations/differ_spec.rb @@ -40,21 +40,15 @@ module Expectations end if RUBY_VERSION.to_f > 1.9 it 'copes with encoded strings' do - pending "awaiting patch on diff-lcs" @expected="Tu avec carté {count} itém has".encode('UTF-16LE') @actual="Tu avec carte {count} item has".encode('UTF-16LE') expect(subject).to eql(<<-EOD.encode('UTF-16LE')) @@ -1,2 +1,2 @@ --Tu avec carté {count} itém has -+Tu avec carte {count} item has +-Tu avec carte {count} item has ++Tu avec carté {count} itém has EOD end - it 'copes with encoded strings' do - @expected="Tu avec carté {count} itém has".encode('UTF-16LE') - @actual="Tu avec carte {count} item has".encode('UTF-16LE') - expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)' - end it 'ouputs a message when encountering differently encoded strings' do @expected="Tu avec carté {count} itém has".encode('UTF-16LE') @actual="Tu avec carte {count} item has" From 1c6b10dbc46236a27b2a76cb493ce47775a7aac7 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 11 Apr 2013 15:13:04 +1000 Subject: [PATCH 4/7] @samphippens workaround for no data being present changes the output diffs --- spec/rspec/expectations/fail_with_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/rspec/expectations/fail_with_spec.rb b/spec/rspec/expectations/fail_with_spec.rb index 82981b79d..b7545c2f4 100644 --- a/spec/rspec/expectations/fail_with_spec.rb +++ b/spec/rspec/expectations/fail_with_spec.rb @@ -6,14 +6,14 @@ before { RSpec::Matchers.configuration.stub(:color? => false) } it "splits items with newlines" do - expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n" + expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+c\\nd\n \n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"]) }.to fail_with(expected_diff) end it "shows inner arrays on a single line" do - expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n" + expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+[\"c\\nd\"]\n \n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]]) }.to fail_with(expected_diff) From 11cc97423d20aa8d99b44bc8e5fbc14c03e93aa6 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 11 Apr 2013 16:54:12 +1000 Subject: [PATCH 5/7] pend specs with older versions of diff lcs --- spec/rspec/expectations/differ_spec.rb | 7 ++++++- spec/rspec/expectations/fail_with_spec.rb | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/rspec/expectations/differ_spec.rb b/spec/rspec/expectations/differ_spec.rb index 7aede1e51..691844185 100644 --- a/spec/rspec/expectations/differ_spec.rb +++ b/spec/rspec/expectations/differ_spec.rb @@ -39,7 +39,7 @@ module Expectations end if RUBY_VERSION.to_f > 1.9 - it 'copes with encoded strings' do + it 'copes with encoded strings', :pending => (Diff::LCS::VERSION < '1.2.2') do @expected="Tu avec carté {count} itém has".encode('UTF-16LE') @actual="Tu avec carte {count} item has".encode('UTF-16LE') expect(subject).to eql(<<-EOD.encode('UTF-16LE')) @@ -49,6 +49,11 @@ module Expectations +Tu avec carté {count} itém has EOD end + it 'copes with encoded strings', :pending => (Diff::LCS::VERSION >= '1.2.2') do + @expected="Tu avec carté {count} itém has".encode('UTF-16LE') + @actual="Tu avec carte {count} item has".encode('UTF-16LE') + expect(subject).to eql 'Could not produce a diff because of the encoding of the string (UTF-16LE)' + end it 'ouputs a message when encountering differently encoded strings' do @expected="Tu avec carté {count} itém has".encode('UTF-16LE') @actual="Tu avec carte {count} item has" diff --git a/spec/rspec/expectations/fail_with_spec.rb b/spec/rspec/expectations/fail_with_spec.rb index b7545c2f4..086ee2e81 100644 --- a/spec/rspec/expectations/fail_with_spec.rb +++ b/spec/rspec/expectations/fail_with_spec.rb @@ -5,14 +5,15 @@ describe RSpec::Expectations, "#fail_with with diff of arrays" do before { RSpec::Matchers.configuration.stub(:color? => false) } - it "splits items with newlines" do + # Diff::LCS 1.2.2 required for this pattern + it "splits items with newlines", :pending => (Diff::LCS::VERSION < '1.2.2') do expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+c\\nd\n \n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"]) }.to fail_with(expected_diff) end - it "shows inner arrays on a single line" do + it "shows inner arrays on a single line", :pending => (Diff::LCS::VERSION < '1.2.2') do expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+[\"c\\nd\"]\n \n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]]) From e6c6a44125849c83e10dfc9c06cf45df5553512d Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 11 Apr 2013 16:56:43 +1000 Subject: [PATCH 6/7] Revert "force diff-lcs 122 and remove workaround" This reverts commit f2b15a3976ef74d01921771c3087fad1146f94cd. --- 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 57813f570..ac3201b49 100644 --- a/lib/rspec/expectations/differ.rb +++ b/lib/rspec/expectations/differ.rb @@ -28,7 +28,13 @@ def diff_as_string(input_data_new, input_data_old) # diff includes lines of context. Otherwise, we might print # redundant lines. if (context_lines > 0) and hunk.overlaps?(oldhunk) - hunk.merge(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 << matching_encoding(oldhunk.diff(format).to_s, output) end diff --git a/rspec-expectations.gemspec b/rspec-expectations.gemspec index 8c51d4156..1f6b41fd8 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.2.2', '< 2.0' + s.add_runtime_dependency 'diff-lcs', '>= 1.1.3', '< 2.0' s.add_development_dependency 'rake', '~> 10.0.0' s.add_development_dependency 'cucumber', '~> 1.1.9' From 2f9dea2ee38baafaab7dda21f1d0ea14f446cbd1 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 12 Apr 2013 13:00:06 +1000 Subject: [PATCH 7/7] Update to diff-lcs 1.2.3 and remove workarounds. This also corrects the previous diff's back the way they were and fixes --- lib/rspec/expectations/differ.rb | 3 --- spec/rspec/expectations/fail_with_spec.rb | 9 ++++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/rspec/expectations/differ.rb b/lib/rspec/expectations/differ.rb index ac3201b49..4706b0fc4 100644 --- a/lib/rspec/expectations/differ.rb +++ b/lib/rspec/expectations/differ.rb @@ -16,9 +16,6 @@ def diff_as_string(input_data_new, input_data_old) file_length_difference = 0 diffs.each do |piece| begin - if data_old == [] - data_old = [""] - end hunk = Diff::LCS::Hunk.new( data_old, data_new, piece, context_lines, file_length_difference ) diff --git a/spec/rspec/expectations/fail_with_spec.rb b/spec/rspec/expectations/fail_with_spec.rb index 086ee2e81..82981b79d 100644 --- a/spec/rspec/expectations/fail_with_spec.rb +++ b/spec/rspec/expectations/fail_with_spec.rb @@ -5,16 +5,15 @@ describe RSpec::Expectations, "#fail_with with diff of arrays" do before { RSpec::Matchers.configuration.stub(:color? => false) } - # Diff::LCS 1.2.2 required for this pattern - it "splits items with newlines", :pending => (Diff::LCS::VERSION < '1.2.2') do - expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+c\\nd\n \n" + it "splits items with newlines" do + expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", "c\nd"]) }.to fail_with(expected_diff) end - it "shows inner arrays on a single line", :pending => (Diff::LCS::VERSION < '1.2.2') do - expected_diff = "\nDiff:\n@@ -1,2 +1,4 @@\n+a\\nb\n+[\"c\\nd\"]\n \n" + it "shows inner arrays on a single line" do + expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+[\"c\\nd\"]\n" expect { RSpec::Expectations.fail_with("", [], ["a\nb", ["c\nd"]]) }.to fail_with(expected_diff)