splitwise/super_diff

If a trailing newline is missing from actual vs. expected, it is not shown in the diff

Closed this issue · 3 comments

Here's some example output from RSpec:

  1) Albatross::Cli given --help prints the help screen
     Failure/Error:
             expect(stdout.string).to eq(<<-OUTPUT)
       Commands for working with the development environment.

       #{colorize(:bold, "USAGE")}

       executable COMMAND [OPTIONS]

       #{colorize(:bold, "COMMANDS")}

       init - Initialize development environment

       Expected "Commands for working with the development environment.\n\n\e[1mUSAGE\e[0m\n\nexecutable COMMAND [OPTIONS]\n\n\e[1mCOMMANDS\e[0m\n\ninit - Initialize development environment\n run - Run a command within a Ruby version\n\n\e[1mOPTIONS\e[0m\n\n    -h, --help                       You're looking at it ;)\n\n"
          to eq "Commands for working with the development environment.\n\n\e[1mUSAGE\e[0m\n\nexecutable COMMAND [OPTIONS]\n\n\e[1mCOMMANDS\e[0m\n\ninit - Initialize development environment\n run - Run a command within a Ruby version\n\n\e[1mOPTIONS\e[0m\n\n    -h, --help                       You're looking at it ;)\n"

       Diff:

       ┌ (Key) ──────────────────────────┐
       │ ‹-› in expected, not in actual  │
       │ ‹+› in actual, not in expected  │
       │ ‹ › in both expected and actual │
       └─────────────────────────────────┘

         Commands for working with the development environment.\n
         \e[1mUSAGE\e[0m\n
         executable COMMAND [OPTIONS]\n
         \e[1mCOMMANDS\e[0m\n
         init - Initialize development environment\n
          run - Run a command within a Ruby version\n
         \e[1mOPTIONS\e[0m\n
             -h, --help                       You're looking at it ;)\n

Here, actual has an extra newline, whereas expected does not. However, this isn't obvious, because the diff doesn't have any - or + lines whatsoever.

I believe this is because the following regex doesn't capture blank lines:

That also means that differing blank lines in the middle of the strings will be omitted from the diff.

We should change the .+ to a .* to capture lines that have no characters other than the end-of-line or EOF.

I'm running into this now. Any chance we can get a release that includes this?

@jason-o-matic I'm planning to cut a release tomorrow. If you want to get on the "bleeding edge" and adopt improvements before a release, you can always point your Gemfile to the latest commit 🙂