|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +RSpec.describe SuperDiff, type: :unit do |
| 4 | + describe ".diff" do |
| 5 | + subject(:diff) { SuperDiff.diff(expected, actual) } |
| 6 | + |
| 7 | + let(:expected) { <<~STRING } |
| 8 | + This here is a string. |
| 9 | + It contains separate lines. |
| 10 | + What else can I say? |
| 11 | + STRING |
| 12 | + let(:actual) { <<~STRING } |
| 13 | + This here is a string. |
| 14 | + It contains separate lines. |
| 15 | + What else can I say? |
| 16 | + STRING |
| 17 | + |
| 18 | + context "with extra blank lines in the middle of expected" do |
| 19 | + let(:expected) { <<~STRING } |
| 20 | + This here is a string. |
| 21 | +
|
| 22 | + It contains separate lines. |
| 23 | +
|
| 24 | +
|
| 25 | + What else can I say? |
| 26 | + STRING |
| 27 | + |
| 28 | + it "removes the extra blank lines" do |
| 29 | + expected_output = |
| 30 | + SuperDiff::Core::Helpers |
| 31 | + .style(color_enabled: true) do |
| 32 | + plain_line " This here is a string.\\n" |
| 33 | + expected_line "- \\n" |
| 34 | + plain_line " It contains separate lines.\\n" |
| 35 | + expected_line "- \\n" |
| 36 | + expected_line "- \\n" |
| 37 | + plain_line " What else can I say?\\n" |
| 38 | + end |
| 39 | + .to_s |
| 40 | + .chomp |
| 41 | + expect(diff).to eq(expected_output) |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + context "with extra blank lines in the middle of actual" do |
| 46 | + let(:actual) { <<~STRING } |
| 47 | + This here is a string. |
| 48 | +
|
| 49 | + It contains separate lines. |
| 50 | +
|
| 51 | +
|
| 52 | + What else can I say? |
| 53 | + STRING |
| 54 | + |
| 55 | + it "adds the extra blank lines" do |
| 56 | + expected_output = |
| 57 | + SuperDiff::Core::Helpers |
| 58 | + .style(color_enabled: true) do |
| 59 | + plain_line " This here is a string.\\n" |
| 60 | + actual_line "+ \\n" |
| 61 | + plain_line " It contains separate lines.\\n" |
| 62 | + actual_line "+ \\n" |
| 63 | + actual_line "+ \\n" |
| 64 | + plain_line " What else can I say?\\n" |
| 65 | + end |
| 66 | + .to_s |
| 67 | + .chomp |
| 68 | + expect(diff).to eq(expected_output) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context "with two trailing newlines in expected but only one in actual" do |
| 73 | + let(:expected) { <<~STRING } |
| 74 | + This here is a string. |
| 75 | + It contains separate lines. |
| 76 | + What else can I say? |
| 77 | +
|
| 78 | + STRING |
| 79 | + |
| 80 | + it "removes the trailing newline" do |
| 81 | + expected_output = |
| 82 | + SuperDiff::Core::Helpers |
| 83 | + .style(color_enabled: true) do |
| 84 | + plain_line " This here is a string.\\n" |
| 85 | + plain_line " It contains separate lines.\\n" |
| 86 | + plain_line " What else can I say?\\n" |
| 87 | + expected_line "- \\n" |
| 88 | + end |
| 89 | + .to_s |
| 90 | + .chomp |
| 91 | + expect(diff).to eq(expected_output) |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + context "with one trailing newline in expected but none in actual" do |
| 96 | + let(:actual) { <<~STRING.chomp } |
| 97 | + This here is a string. |
| 98 | + It contains separate lines. |
| 99 | + What else can I say? |
| 100 | + STRING |
| 101 | + |
| 102 | + it "removes the trailing newline" do |
| 103 | + expected_output = |
| 104 | + SuperDiff::Core::Helpers |
| 105 | + .style(color_enabled: true) do |
| 106 | + plain_line " This here is a string.\\n" |
| 107 | + plain_line " It contains separate lines.\\n" |
| 108 | + expected_line "- What else can I say?\\n" |
| 109 | + actual_line "+ What else can I say?" |
| 110 | + end |
| 111 | + .to_s |
| 112 | + .chomp |
| 113 | + expect(diff).to eq(expected_output) |
| 114 | + end |
| 115 | + end |
| 116 | + end |
| 117 | +end |
0 commit comments