Skip to content

Commit

Permalink
Account for trailing newlines
Browse files Browse the repository at this point in the history
*Backfills hunk_generator with extra newline to account for 'true'
trailing newlines that should be included in diff calculation.
  Example:

  "cat\n".split("\n") => []
  "cat\n\n".split("\n") => ["cat"]

  "cat\n".split("\n", -1) => ["cat", ""]
  "cat\n\n".split("\n", -1) => ["cat", "", ""]

*Removes extra newline representation from hunk_generator when crafting differ
output message.
  • Loading branch information
ChaeOkay committed Jul 4, 2016
1 parent 5a332b7 commit 3a0af72
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def diff_as_string(actual, expected)
end
end

finalize_output(output, hunks.last.diff(format_type).to_s) if hunks.last
if hunks.last
last_hunk_diff = hunks.last.diff(format_type).to_s.strip
finalize_output(output, last_hunk_diff)
end

color_diff output
rescue Encoding::CompatibilityError
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/support/hunk_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def diffs
end

def expected_lines
@expected.split("\n").map! { |e| e.chomp }
@expected.to_s.split("\n", -1).map! { |e| e.chomp }
end

def actual_lines
@actual.split("\n").map! { |e| e.chomp }
@actual.to_s.split("\n", -1).map! { |e| e.chomp }
end

def build_hunk(piece)
Expand Down

0 comments on commit 3a0af72

Please sign in to comment.