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::Differ.new(@options) end it "outputs 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 "outputs 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 diff = @differ.diff_as_object(expected,actual) diff.should == expected_diff end it "outputs unified diff message of two hashes" do expected = { :foo => 'bar', :baz => 'quux', :metasyntactic => 'variable', :delta => 'charlie', :width =>'quite wide' } actual = { :foo => 'bar', :metasyntactic => 'variable', :delta => 'charlotte', :width =>'quite wide' } expected_diff = <<'EOD' @@ -1,4 +1,5 @@ -:delta => "charlotte", +:baz => "quux", +:delta => "charlie", :foo => "bar", :metasyntactic => "variable", :width => "quite wide" EOD diff = @differ.diff_as_object(expected,actual) diff.should == expected_diff end it "outputs unified diff of single line strings" do expected = "this is one string" actual = "this is another string" expected_diff = <