changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/expectations/differs/default_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
3module Spec
4 module Fixtures
5 class Animal
6 def initialize(name,species)
7 @name,@species = name,species
8 end
9
10 def inspect
11 <<-EOA
12<Animal
13 name=#{@name},
14 species=#{@species}
15>
16 EOA
17 end
18 end
19 end
20end
21
22describe "Diff" do
23 before(:each) do
24 @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
25 @differ = Spec::Expectations::Differs::Default.new(@options)
26 end
27
28 it "should output unified diff of two strings" do
29 expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
30 actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
31 expected_diff="\n\n@@ -1,6 +1,6 @@\n foo\n-bar\n zap\n+bar\n this\n is\n soo\n@@ -9,5 +9,6 @@\n equal\n insert\n a\n+another\n line\n"
32 diff = @differ.diff_as_string(expected, actual)
33 diff.should eql(expected_diff)
34 end
35
36 it "should output unified diff message of two arrays" do
37 expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
38 actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
39
40 expected_diff = <<'EOD'
41
42
43@@ -5,7 +5,7 @@
44 :metasyntactic,
45 "variable",
46 :delta,
47- "charlie",
48+ "tango",
49 :width,
50- "quite wide"]
51+ "very wide"]
52EOD
53
54
55 diff = @differ.diff_as_object(expected,actual)
56 diff.should == expected_diff
57 end
58
59 it "should output unified diff message of two objects" do
60 expected = Spec::Fixtures::Animal.new "bob", "giraffe"
61 actual = Spec::Fixtures::Animal.new "bob", "tortoise"
62
63 expected_diff = <<'EOD'
64
65@@ -1,5 +1,5 @@
66 <Animal
67 name=bob,
68- species=giraffe
69+ species=tortoise
70 >
71EOD
72
73 diff = @differ.diff_as_object(expected,actual)
74 diff.should == expected_diff
75 end
76
77end
78
79
80describe "Diff in context format" do
81 before(:each) do
82 @options = Spec::Runner::Options.new(StringIO.new, StringIO.new)
83 @options.diff_format = :context
84 @differ = Spec::Expectations::Differs::Default.new(@options)
85 end
86
87 it "should output unified diff message of two objects" do
88 expected = Spec::Fixtures::Animal.new "bob", "giraffe"
89 actual = Spec::Fixtures::Animal.new "bob", "tortoise"
90
91 expected_diff = <<'EOD'
92
93***************
94*** 1,5 ****
95 <Animal
96 name=bob,
97! species=giraffe
98 >
99--- 1,5 ----
100 <Animal
101 name=bob,
102! species=tortoise
103 >
104EOD
105
106 diff = @differ.diff_as_object(expected,actual)
107 diff.should == expected_diff
108 end
109end