require 'spec_helper' require 'ostruct' module Rspec module Fixtures class Animal def initialize(name,species) @name,@species = name,species end def inspect <<-EOA EOA end end end end describe "Diff" do before(:each) do @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3) @differ = Rspec::Expectations::Differs::Default.new(@options) end it "should output unified diff of two strings" do expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n" actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n" expected_diff= <<'EOD' @@ -1,6 +1,6 @@ foo -zap bar +zap this is soo @@ -9,6 +9,5 @@ equal insert a -another line EOD diff = @differ.diff_as_string(expected, actual) diff.should eql(expected_diff) end it "should output unified diff message of two arrays" do expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ] actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ] expected_diff = <<'EOD' @@ -5,7 +5,7 @@ :metasyntactic, "variable", :delta, - "tango", + "charlie", :width, - "very wide"] + "quite wide"] EOD diff = @differ.diff_as_object(expected,actual) diff.should == expected_diff end it "should output unified diff message of two objects" do expected = Rspec::Fixtures::Animal.new "bob", "giraffe" actual = Rspec::Fixtures::Animal.new "bob", "tortoise" expected_diff = <<'EOD' @@ -1,5 +1,5 @@ EOD diff = @differ.diff_as_object(expected,actual) diff.should == expected_diff end end describe "Diff in context format" do before(:each) do @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3) @options.diff_format = :context @differ = Rspec::Expectations::Differs::Default.new(@options) end it "should output unified diff message of two objects" do expected = Rspec::Fixtures::Animal.new "bob", "giraffe" actual = Rspec::Fixtures::Animal.new "bob", "tortoise" expected_diff = <<'EOD' *************** *** 1,5 **** --- 1,5 ---- EOD diff = @differ.diff_as_object(expected,actual) diff.should == expected_diff end end