Skip to content

Commit

Permalink
The Differ no longer catches CompatibilityErrors
Browse files Browse the repository at this point in the history
This was introduced in
https://github.com/rspec/rspec-expectations/pull/220/files#diff-9533f5f156a38a3307ecfc610d2282d7R47

but is no longer raised either by the the current test code, the
original test code
      @expected="Tu avec carté {count} itém has".encode('UTF-16LE')
      @Actual="Tu avec carte {count} item has".encode('UTF-16LE')
or any other variations I've tried

Since I'm moving all the encoding logic into EncodedString, and this
doesn't appear to do anything any more, I am proposing to remove it.

Next commits will also move over #pick_encoding
  • Loading branch information
bf4 committed Dec 26, 2014
1 parent 322d738 commit 96584ba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
13 changes: 0 additions & 13 deletions lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def diff_as_string(actual, expected)
finalize_output(output, hunks.last.diff(format_type).to_s) if hunks.last

color_diff output
rescue Encoding::CompatibilityError
handle_encoding_errors
end
# rubocop:enable MethodLength

Expand Down Expand Up @@ -197,17 +195,6 @@ def pick_encoding(source_a, source_b)
def pick_encoding(_source_a, _source_b)
end
end

def handle_encoding_errors
if @actual.source_encoding != @expected.source_encoding
"Could not produce a diff because the encoding of the actual string " \
"(#{@actual.source_encoding}) differs from the encoding of the expected " \
"string (#{@expected.source_encoding})"
else
"Could not produce a diff because of the encoding of the string " \
"(#{@expected.source_encoding})"
end
end
end
# rubocop:enable ClassLength
end
Expand Down
11 changes: 0 additions & 11 deletions spec/rspec/support/differ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ module Support
expect(differ.diff(actual, expected)).to eq("\n@@ -1,2 +1,2 @@\n-Tu avec carte {count} item has\n+Tu avec carté {count} itém has\n")
expect(differ.diff(actual, expected).encoding).to eq(Encoding.default_external)
end

it 'handles any encoding error that occurs with a helpful error message' do
expect(RSpec::Support::HunkGenerator).to receive(:new).
and_raise(Encoding::CompatibilityError)
expected = "Tu avec carte {count} item has\n".encode('us-ascii')
actual = "Tu avec carté {count} itém has\n"
diff = differ.diff(actual, expected)
expect(diff).to match(/Could not produce a diff/)
expect(diff).to match(/actual string \(UTF-8\)/)
expect(diff).to match(/expected string \(US-ASCII\)/)
end
end

it "outputs unified diff message of two objects" do
Expand Down

0 comments on commit 96584ba

Please sign in to comment.