Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Stop using DiffHelpers #477

Merged
merged 2 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- 2.3
env:
-
DIFF_LCS_VERSION: "> 1.4.3"
BOGUS: ""
include:
- ruby: ruby-head
env:
Expand Down
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp
end
end

if ENV['DIFF_LCS_VERSION']
gem 'diff-lcs', ENV['DIFF_LCS_VERSION']
else
gem 'diff-lcs', '~> 1.4', '>= 1.4.3'
end

gem "childprocess", ">= 3.0.0"
gem 'ffi', '~> 1.12.0'

Expand Down
1 change: 0 additions & 1 deletion lib/rspec/support/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'rspec/support/spec/in_sub_process'

RSpec::Support.require_rspec_support "spec/deprecation_helpers"
RSpec::Support.require_rspec_support "spec/diff_helpers"
RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
RSpec::Support.require_rspec_support "spec/stderr_splitter"
RSpec::Support.require_rspec_support "spec/formatting_support"
Expand Down
1 change: 1 addition & 0 deletions script/run_build
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fi

if supports_cross_build_checks; then
fold "one-by-one specs" run_specs_one_by_one
export NO_COVERAGE=true
run_all_spec_suites
else
echo "Skipping the rest of the build on non-MRI rubies"
Expand Down
153 changes: 55 additions & 98 deletions spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,32 @@
module RSpec
module Support
RSpec.describe Differ do
include Spec::DiffHelpers

describe '#diff' do
let(:differ) { RSpec::Support::Differ.new }

it "outputs unified diff of two strings" do
expected = "foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
actual = "foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"

if Diff::LCS::VERSION.to_f < 1.4 || Diff::LCS::VERSION >= "1.4.4"
expected_diff = dedent(<<-'EOD')
|
|
|@@ -1,6 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
| is
| soo
|@@ -9,6 +9,5 @@
| equal
| insert
| a
|-another
| line
|
EOD
else
expected_diff = dedent(<<-'EOD')
|
|
|@@ -1,4 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
|@@ -9,6 +11,7 @@
| equal
| insert
| a
|-another
| line
|
EOD
end

expected_diff = dedent(<<-'EOD')
|
|
|@@ -1,6 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
| is
| soo
|@@ -9,6 +9,5 @@
| equal
| insert
| a
|-another
| line
|
EOD

diff = differ.diff(actual, expected)
expect(diff).to be_diffed_as(expected_diff)
Expand All @@ -63,45 +40,25 @@ module Support
expected = "foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
actual = "foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"

if Diff::LCS::VERSION.to_f < 1.4 || Diff::LCS::VERSION >= "1.4.4"
expected_diff = dedent(<<-'EOS')
|
|
|@@ -1,6 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
| is
| soo
|@@ -9,6 +9,5 @@
| equal
| insert
| a
|-another
| line
|
EOS
else
expected_diff = dedent(<<-'EOS')
|
|
|@@ -1,4 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
|@@ -9,6 +11,7 @@
| equal
| insert
| a
|-another
| line
|
EOS
end
expected_diff = dedent(<<-'EOS')
|
|
|@@ -1,6 +1,6 @@
| foo
|-zap
| bar
|+zap
| this
| is
| soo
|@@ -9,6 +9,5 @@
| equal
| insert
| a
|-another
| line
|
EOS

diff = differ.diff(actual, expected)
expect(diff).to be_diffed_as(expected_diff)
Expand Down Expand Up @@ -133,7 +90,7 @@ def differ_ivars
actual = "Tu avec carté {count} itém has\n".encode('UTF-16LE')
expected_diff = dedent(<<-EOD).encode('UTF-16LE')
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-Tu avec carte {count} item has
|+Tu avec carté {count} itém has
|
Expand All @@ -146,15 +103,15 @@ def differ_ivars
it 'handles differently encoded strings that are compatible' do
expected = "abc\n".encode('us-ascii')
actual = "강인철\n".encode('UTF-8')
expected_diff = "\n@@ #{one_line_header} @@\n-abc\n+강인철\n"
expected_diff = "\n@@ -1 +1 @@\n-abc\n+강인철\n"
diff = differ.diff(actual, expected)
expect(diff).to be_diffed_as(expected_diff)
end

it 'uses the default external encoding when the two strings have incompatible encodings' do
expected = "Tu avec carte {count} item has\n"
actual = "Tu avec carté {count} itém has\n".encode('UTF-16LE')
expected_diff = "\n@@ #{one_line_header} @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n"
expected_diff = "\n@@ -1 +1 @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n"

diff = differ.diff(actual, expected)
expect(diff).to be_diffed_as(expected_diff)
Expand Down Expand Up @@ -245,7 +202,7 @@ def inspect; "<BrokenObject>"; end

expected_diff = dedent(<<-EOD)
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-[]
|+[<BrokenObject>]
|
Expand All @@ -257,7 +214,7 @@ def inspect; "<BrokenObject>"; end
diff = differ.diff(["a\r\nb"], ["a\r\nc"])
expected_diff = dedent(<<-EOD)
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-a\\r\\nc
|+a\\r\\nb
|
Expand Down Expand Up @@ -308,7 +265,7 @@ def inspect; "<BrokenObject>"; end
it 'outputs unified diff message of two hashes with differing encoding' do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-"a" => "a",
|+"ö" => "ö",
|
Expand All @@ -321,7 +278,7 @@ def inspect; "<BrokenObject>"; end
it 'outputs unified diff message of two hashes with encoding different to key encoding' do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-:a => "a",
|+\"한글\" => \"한글2\",
|
Expand All @@ -334,7 +291,7 @@ def inspect; "<BrokenObject>"; end
it "outputs unified diff message of two hashes with object keys" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-["a", "c"] => "b",
|+["d", "c"] => "b",
|
Expand All @@ -351,7 +308,7 @@ def inspect; "<BrokenObject>"; end
it "outputs unified diff message of two hashes with Time object keys" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-#{formatted_time} => "b",
|+#{formatted_time} => "c",
|
Expand All @@ -364,7 +321,7 @@ def inspect; "<BrokenObject>"; end
it "outputs unified diff message of two hashes with hashes inside them" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-"b" => {"key_1"=>#{formatted_time}},
|+"c" => {"key_1"=>#{formatted_time}},
|
Expand All @@ -384,7 +341,7 @@ def inspect; "<BrokenObject>"; end
it "outputs unified diff message of two arrays with Time object keys" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-[#{formatted_time}, "b"]
|+[#{formatted_time}, "c"]
|
Expand All @@ -397,7 +354,7 @@ def inspect; "<BrokenObject>"; end
it "outputs unified diff message of two arrays with hashes inside them" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-[{"b"=>#{formatted_time}}, "c"]
|+[{"a"=>#{formatted_time}}, "c"]
|
Expand Down Expand Up @@ -430,7 +387,7 @@ def inspect; "<BrokenObject>"; end
it "splits items with newlines" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{removing_two_line_header} @@
|@@ -1,3 +1 @@
|-a\\nb
|-c\\nd
|
Expand All @@ -443,7 +400,7 @@ def inspect; "<BrokenObject>"; end
it "shows inner arrays on a single line" do
expected_diff = dedent(<<-"EOD")
|
|@@ #{removing_two_line_header} @@
|@@ -1,3 +1 @@
|-a\\nb
|-["c\\nd"]
|
Expand Down Expand Up @@ -496,7 +453,7 @@ def inspect; "<BrokenObject>"; end

expected_diff = dedent(<<-EOS)
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-[#<SimpleDelegator(#{object.inspect})>]
|+[#{object.inspect}]
|
Expand All @@ -518,7 +475,7 @@ def inspect; "<BrokenObject>"; end

expected_diff = dedent(<<-EOS)
|
|@@ #{one_line_header} @@
|@@ -1 +1 @@
|-"oop"
|+"oof"
|
Expand All @@ -535,7 +492,7 @@ def inspect; "<BrokenObject>"; end
it "outputs colored diffs" do
expected = "foo bar baz\n"
actual = "foo bang baz\n"
expected_diff = "\e[0m\n\e[0m\e[34m@@ #{one_line_header} @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"
expected_diff = "\e[0m\n\e[0m\e[34m@@ -1 +1 @@\n\e[0m\e[31m-foo bang baz\n\e[0m\e[32m+foo bar baz\n\e[0m"

diff = differ.diff(expected,actual)
expect(diff).to be_diffed_as(expected_diff)
Expand Down