1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
|
require 'rspec'
require 'diffy'
describe Diffy::Diff do
describe "diffing two files" do
def tempfile(string, fn = 'diffy-spec')
t = Tempfile.new(fn)
# ensure tempfiles aren't unlinked when GC runs by maintaining a
# reference to them.
@tempfiles ||=[]
@tempfiles.push(t)
t.print(string)
t.flush
t.close
t.path
end
it "should accept file paths as arguments" do
string1 = "foo\nbar\nbang\n"
string2 = "foo\nbang\n"
path1, path2 = tempfile(string1), tempfile(string2)
expect(Diffy::Diff.new(path1, path2, :source => 'files').to_s).to eq <<-DIFF
foo
-bar
bang
DIFF
end
it "should accept file paths with spaces as arguments" do
string1 = "foo\nbar\nbang\n"
string2 = "foo\nbang\n"
path1, path2 = tempfile(string1, 'path with spaces'), tempfile(string2, 'path with spaces')
expect(Diffy::Diff.new(path1, path2, :source => 'files').to_s).to eq <<-DIFF
foo
-bar
bang
DIFF
end
it "should accept file paths with spaces as arguments on windows" do
begin
orig_verbose, $VERBOSE = $VERBOSE, nil #silence redefine constant warnings
orig_windows, Diffy::WINDOWS = Diffy::WINDOWS, true
string1 = "foo\nbar\nbang\n"
string2 = "foo\nbang\n"
path1, path2 = tempfile(string1, 'path with spaces'), tempfile(string2, 'path with spaces')
expect(Diffy::Diff.new(path1, path2, :source => 'files').to_s).to eq <<-DIFF
foo
-bar
bang
DIFF
ensure
Diffy::WINDOWS, $VERBOSE = orig_windows, orig_verbose
end
end
describe "with no line different" do
before do
string1 = "foo\nbar\nbang\n"
string2 = "foo\nbar\nbang\n"
@path1, @path2 = tempfile(string1), tempfile(string2)
end
it "should show everything" do
expect(Diffy::Diff.new(@path1, @path2, :source => 'files', :allow_empty_diff => false).
to_s).to eq <<-DIFF
foo
bar
bang
DIFF
end
it "should not show everything if the :allow_empty_diff option is set" do
expect(Diffy::Diff.new(@path1, @path2, :source => 'files', :allow_empty_diff => true).to_s).to eq('')
end
end
describe "with lines that start with backslashes" do
before do
string1 = "foo\n\\\\bag\nbang\n"
string2 = "foo\n\\\\bar\nbang\n"
@path1, @path2 = tempfile(string1), tempfile(string2)
end
it "should not leave lines out" do
expect(Diffy::Diff.new(@path1, @path2, :source => 'files').to_s).to eq <<-DIFF
foo
-\\\\bag
+\\\\bar
bang
DIFF
end
end
describe "with non valid UTF bytes" do
before do
string1 = "Foo ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n"
string2 = "Bar ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000\n"
@path1, @path2 = tempfile(string1), tempfile(string2)
end
it "should not raise invalid encoding issues" do
desired = <<-DIFF
-Foo ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000
+Bar ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000
DIFF
desired.force_encoding("ASCII-8BIT") if desired.respond_to?(:force_encoding)
expect(Diffy::Diff.new(@path1, @path2, :source => 'files').to_s).to eq(desired)
end
end
end
describe "handling temp files" do
it "should unlink tempfiles after generating the diff" do
before_tmpfiles = Dir.entries(Dir.tmpdir)
::Diffy::Diff.new("a", "b").to_s
after_tmpfiles = Dir.entries(Dir.tmpdir)
expect(before_tmpfiles).to match_array(after_tmpfiles)
end
it "should still be able to generate multiple diffs" do
d = ::Diffy::Diff.new("a", "b")
expect(d.to_s).to be_a String
expect(d.to_s(:html)).to be_a String
end
end
describe "options[:context]" do
it "should limit context lines to 1" do
diff = Diffy::Diff.new("foo\nfoo\nBAR\nbang\nbaz", "foo\nfoo\nbar\nbang\nbaz", :context => 1)
expect(diff.to_s).to eq <<-DIFF
foo
-BAR
+bar
bang
DIFF
end
end
describe "options[:include_plus_and_minus_in_html]" do
it "defaults to false" do
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
expect(@diffy.options[:include_plus_and_minus_in_html]).to eq(false)
end
it "can be set to true" do
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :include_plus_and_minus_in_html=> true )
expect(@diffy.options[:include_plus_and_minus_in_html]).to eq(true)
end
describe "formats" do
it "includes symbols in html_simple" do
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_plus_and_minus_in_html => true ).
to_s(:html_simple)
expect(output).to eq <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span><span class="symbol"> </span>foo</span></li>
<li class="del"><del><span class="symbol">-</span>bar</del></li>
<li class="unchanged"><span><span class="symbol"> </span>bang</span></li>
</ul>
</div>
HTML
end
it "includes symbols in html" do
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\naba\nbang\n", :include_plus_and_minus_in_html => true ).
to_s(:html)
expect(output).to eq <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span><span class="symbol"> </span>foo</span></li>
<li class="del"><del><span class="symbol">-</span>ba<strong>r</strong></del></li>
<li class="ins"><ins><span class="symbol">+</span><strong>a</strong>ba</ins></li>
<li class="unchanged"><span><span class="symbol"> </span>bang</span></li>
</ul>
</div>
HTML
end
end
end
describe "options[:include_diff_info]" do
it "defaults to false" do
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
expect(@diffy.options[:include_diff_info]).to eq(false)
end
it "can be set to true" do
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :include_diff_info => true )
expect(@diffy.options[:include_diff_info]).to eq(true)
end
it "includes all diff output" do
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s
expect(output.to_s).to match( /@@/)
expect(output).to match( /---/)
expect(output).to match( /\+\+\+/)
end
describe "formats" do
it "works for :color" do
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:color)
expect(output).to match( /\e\[0m\n\e\[36m\@\@/ )
expect(output.to_s).to match( /\e\[90m---/)
expect(output.to_s).to match( /\e\[0m\n\e\[90m\+\+\+/)
end
it "works for :html_simple" do
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:html_simple)
expect(output.split("\n")).to include( " <li class=\"diff-block-info\"><span>@@ -1,3 +1,2 @@</span></li>" )
expect(output).to include( "<li class=\"diff-comment\"><span>---")
expect(output).to include( "<li class=\"diff-comment\"><span>+++")
end
end
end
describe "options[:diff]" do
it "should accept an option to diff" do
@diff = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w", :allow_empty_diff => false)
expect(@diff.to_s).to eq <<-DIFF
foo
bar
DIFF
end
it "should accept multiple arguments to diff" do
@diff = Diffy::Diff.new(" foo\nbar\n", "foo\nbaz\n", :diff => ["-w", "-U 3"])
expect(@diff.to_s).to eq <<-DIFF
foo
-bar
+baz
DIFF
end
end
describe "#to_s" do
describe "with no line different" do
before do
@string1 = "foo\nbar\nbang\n"
@string2 = "foo\nbar\nbang\n"
end
it "should show everything" do
expect(Diffy::Diff.new(@string1, @string2, :allow_empty_diff => false).to_s).to eq <<-DIFF
foo
bar
bang
DIFF
end
end
describe "with one line different" do
before do
@string1 = "foo\nbar\nbang\n"
@string2 = "foo\nbang\n"
end
it "should show one line removed" do
expect(Diffy::Diff.new(@string1, @string2).to_s).to eq <<-DIFF
foo
-bar
bang
DIFF
end
it "to_s should accept a format key" do
expect(Diffy::Diff.new(@string1, @string2).to_s(:color)).
to eq(" foo\n\e[31m-bar\e[0m\n bang\n")
end
it "should accept a default format option" do
old_format = Diffy::Diff.default_format
Diffy::Diff.default_format = :color
expect(Diffy::Diff.new(@string1, @string2).to_s).
to eq(" foo\n\e[31m-bar\e[0m\n bang\n")
Diffy::Diff.default_format = old_format
end
it "should accept a default options" do
old_options = Diffy::Diff.default_options
Diffy::Diff.default_options = old_options.merge(:include_diff_info => true)
expect(Diffy::Diff.new(@string1, @string2).to_s).
to include('@@ -1,3 +1,2 @@')
Diffy::Diff.default_options = old_options
end
it "should show one line added" do
expect(Diffy::Diff.new(@string2, @string1).to_s).
to eq <<-DIFF
foo
+bar
bang
DIFF
end
end
describe "with one line changed" do
before do
@string1 = "foo\nbar\nbang\n"
@string2 = "foo\nbong\nbang\n"
end
it "should show one line added and one removed" do
expect(Diffy::Diff.new(@string1, @string2).to_s).to eq <<-DIFF
foo
-bar
+bong
bang
DIFF
end
end
describe "with totally different strings" do
before do
@string1 = "foo\nbar\nbang\n"
@string2 = "one\ntwo\nthree\n"
end
it "should show one line added and one removed" do
expect(Diffy::Diff.new(@string1, @string2).to_s).to eq <<-DIFF
-foo
-bar
-bang
+one
+two
+three
DIFF
end
end
describe "with a somewhat complicated diff" do
before do
@string1 = "foo\nbar\nbang\nwoot\n"
@string2 = "one\ntwo\nthree\nbar\nbang\nbaz\n"
@diff = Diffy::Diff.new(@string1, @string2)
end
it "should show one line added and one removed" do
expect(@diff.to_s).to eq <<-DIFF
-foo
+one
+two
+three
bar
bang
-woot
+baz
DIFF
end
it "should make an awesome simple html diff" do
expect(@diff.to_s(:html_simple)).to eq <<-HTML
<div class="diff">
<ul>
<li class="del"><del>foo</del></li>
<li class="ins"><ins>one</ins></li>
<li class="ins"><ins>two</ins></li>
<li class="ins"><ins>three</ins></li>
<li class="unchanged"><span>bar</span></li>
<li class="unchanged"><span>bang</span></li>
<li class="del"><del>woot</del></li>
<li class="ins"><ins>baz</ins></li>
</ul>
</div>
HTML
end
it "should accept overrides to diff's options" do
@diff = Diffy::Diff.new(@string1, @string2, :diff => "--rcs")
expect(@diff.to_s).to eq <<-DIFF
d1 1
a1 3
one
two
three
d4 1
a4 1
baz
DIFF
end
end
describe "html" do
it "should not allow html injection on the last line" do
@string1 = "hahaha\ntime flies like an arrow\nfoo bar\nbang baz\n<script>\n"
@string2 = "hahaha\nfruit flies like a banana\nbang baz\n<script>\n"
@diff = Diffy::Diff.new(@string1, @string2)
html = <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>hahaha</span></li>
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
<li class="del"><del><strong>foo bar</strong></del></li>
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
<li class="unchanged"><span>bang baz</span></li>
<li class="unchanged"><span><script></span></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should highlight the changes within the line" do
@string1 = "hahaha\ntime flies like an arrow\nfoo bar\nbang baz\n"
@string2 = "hahaha\nfruit flies like a banana\nbang baz\n"
@diff = Diffy::Diff.new(@string1, @string2)
html = <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>hahaha</span></li>
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
<li class="del"><del><strong>foo bar</strong></del></li>
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
<li class="unchanged"><span>bang baz</span></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should not duplicate some lines" do
@string1 = "hahaha\ntime flies like an arrow\n"
@string2 = "hahaha\nfruit flies like a banana\nbang baz"
@diff = Diffy::Diff.new(@string1, @string2)
html = <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>hahaha</span></li>
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
<li class="ins"><ins><strong>bang baz</strong></ins></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should escape html" do
@string1 = "ha<br>haha\ntime flies like an arrow\n"
@string2 = "ha<br>haha\nfruit flies like a banana\nbang baz"
@diff = Diffy::Diff.new(@string1, @string2)
html = <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>ha<br>haha</span></li>
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
<li class="ins"><ins><strong>bang baz</strong></ins></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should not double escape html in wierd edge cases" do
@string1 = "preface = (! title .)+ title &{YYACCEPT}\n"
@string2 = "preface = << (! title .)+ title >> &{YYACCEPT}\n"
@diff = Diffy::Diff.new @string1, @string2
html = <<-HTML
<div class="diff">
<ul>
<li class="del"><del>preface = (! title .)+ title &{YYACCEPT}</del></li>
<li class="ins"><ins>preface = <strong><< </strong>(! title .)+ title <strong>>> </strong>&{YYACCEPT}</ins></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should highlight the changes within the line with windows style line breaks" do
@string1 = "hahaha\r\ntime flies like an arrow\r\nfoo bar\r\nbang baz\n"
@string2 = "hahaha\r\nfruit flies like a banana\r\nbang baz\n"
@diff = Diffy::Diff.new(@string1, @string2)
html = <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>hahaha</span></li>
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
<li class="del"><del><strong>foo bar</strong></del></li>
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
<li class="unchanged"><span>bang baz</span></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should treat unix vs windows newlines as differences" do
@diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n")
html = <<-HTML
<div class="diff">
<ul>
<li class="del"><del>one</del></li>
<li class="del"><del>two</del></li>
<li class="del"><del>three</del></li>
<li class="ins"><ins>one<strong></strong></ins></li>
<li class="ins"><ins>two<strong></strong></ins></li>
<li class="ins"><ins>three<strong></strong></ins></li>
</ul>
</div>
HTML
expect(@diff.to_s(:html)).to eq(html)
end
it "should treat unix vs windows newlines as same if option :ignore_crlf" do
@diff = Diffy::Diff.new("one\ntwo\nthree\n", "one\r\ntwo\r\nthree\r\n",
ignore_crlf: true)
empty_diff = "<div class=\"diff\"></div>"
expect(@diff.to_s(:html)).to eq(empty_diff)
end
describe 'with lines that include \n' do
before do
string1 = 'a\nb'"\n"
string2 = 'acb'"\n"
@string1, @string2 = string1, string2
end
it "should not leave lines out" do
expect(Diffy::Diff.new(@string1, @string2 ).to_s(:html)).to eq <<-DIFF
<div class="diff">
<ul>
<li class="del"><del>a<strong>\\n</strong>b</del></li>
<li class="ins"><ins>a<strong>c</strong>b</ins></li>
</ul>
</div>
DIFF
end
end
it "should do highlighting on the last line when there's no trailing newlines" do
s1 = "foo\nbar\nbang"
s2 = "foo\nbar\nbangleize"
expect(Diffy::Diff.new(s1,s2).to_s(:html)).to eq <<-DIFF
<div class="diff">
<ul>
<li class="unchanged"><span>foo</span></li>
<li class="unchanged"><span>bar</span></li>
<li class="del"><del>bang</del></li>
<li class="ins"><ins>bang<strong>leize</strong></ins></li>
</ul>
</div>
DIFF
end
it "should correctly do inline hightlighting when default diff options are changed" do
original_options = ::Diffy::Diff.default_options
begin
::Diffy::Diff.default_options.merge!(:diff => '-U0')
s1 = "foo\nbar\nbang"
s2 = "foo\nbar\nbangleize"
expect(Diffy::Diff.new(s1,s2).to_s(:html)).to eq <<-DIFF
<div class="diff">
<ul>
<li class="del"><del>bang</del></li>
<li class="ins"><ins>bang<strong>leize</strong></ins></li>
</ul>
</div>
DIFF
ensure
::Diffy::Diff.default_options = original_options
end
end
end
it "should escape diffed html in html output" do
diff = Diffy::Diff.new("<script>alert('bar')</script>", "<script>alert('foo')</script>").to_s(:html)
expect(diff).to include('<script>')
expect(diff).not_to include('<script>')
end
it "should be easy to generate custom format" do
expect(Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").map do |line|
case line
when /^\+/ then "line #{line.chomp} added"
when /^-/ then "line #{line.chomp} removed"
end
end.compact.join).to eq("line +baz added")
end
it "should let you iterate over chunks instead of lines" do
expect(Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each_chunk.map do |chunk|
chunk
end).to eq([" foo\n bar\n", "+baz\n"])
end
it "should allow chaining enumerable methods" do
expect(Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each.map do |line|
line
end).to eq([" foo\n", " bar\n", "+baz\n"])
end
it "should handle lines that begin with --" do
string1 = "a a\n-- b\nc c\n"
string2 = "a a\nb b\nc c\n"
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
a a
--- b
+b b
c c
DIFF
end
it "should handle lines that begin with ++" do
string1 = "a a\nb b\nc c\n"
string2 = "a a\n++ b\nc c\n"
expect(Diffy::Diff.new(string1, string2).to_s).to eq <<-DIFF
a a
-b b
+++ b
c c
DIFF
end
end
end
describe Diffy::SplitDiff do
before do
::Diffy::Diff.default_options.merge!(:diff => '-U10000')
end
it "should fail with invalid format" do
expected_fail = expect do
Diffy::SplitDiff.new("lorem\n", "ipsum\n", :format => :fail)
end
expected_fail.to raise_error(ArgumentError)
end
describe "#left" do
it "should only highlight deletions" do
string1 = "lorem\nipsum\ndolor\nsit amet\n"
string2 = "lorem\nipsumdolor\nsit amet\n"
expect(Diffy::SplitDiff.new(string1, string2).left).to eq <<-TEXT
lorem
-ipsum
-dolor
sit amet
TEXT
end
it "should also format left diff as html" do
string1 = "lorem\nipsum\ndolor\nsit amet\n"
string2 = "lorem\nipsumdolor\nsit amet\n"
expect(Diffy::SplitDiff.new(string1, string2, :format => :html).left).to eq <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>lorem</span></li>
<li class="del"><del>ipsum<strong></strong></del></li>
<li class="del"><del><strong></strong>dolor</del></li>
<li class="unchanged"><span>sit amet</span></li>
</ul>
</div>
HTML
end
end
describe "#right" do
it "should only highlight insertions" do
string1 = "lorem\nipsum\ndolor\nsit amet\n"
string2 = "lorem\nipsumdolor\nsit amet\n"
expect(Diffy::SplitDiff.new(string1, string2).right).to eq <<-TEXT
lorem
+ipsumdolor
sit amet
TEXT
end
it "should also format right diff as html" do
string1 = "lorem\nipsum\ndolor\nsit amet\n"
string2 = "lorem\nipsumdolor\nsit amet\n"
expect(Diffy::SplitDiff.new(string1, string2, :format => :html).right).to eq <<-HTML
<div class="diff">
<ul>
<li class="unchanged"><span>lorem</span></li>
<li class="ins"><ins>ipsumdolor</ins></li>
<li class="unchanged"><span>sit amet</span></li>
</ul>
</div>
HTML
end
end
end
describe 'Diffy::CSS' do
it "should be some css" do
expect(Diffy::CSS).to include 'diff{overflow:auto;}'
end
end
|