rspec-expectations 2.0.0.a1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/License.txt +22 -0
  4. data/README.markdown +8 -0
  5. data/Rakefile +43 -0
  6. data/VERSION +1 -0
  7. data/VERSION.yml +5 -0
  8. data/lib/rspec/expectations.rb +36 -0
  9. data/lib/rspec/expectations/differs/default.rb +62 -0
  10. data/lib/rspec/expectations/differs/load-diff-lcs.rb +12 -0
  11. data/lib/rspec/expectations/errors.rb +12 -0
  12. data/lib/rspec/expectations/extensions.rb +1 -0
  13. data/lib/rspec/expectations/extensions/kernel.rb +52 -0
  14. data/lib/rspec/expectations/fail_with.rb +43 -0
  15. data/lib/rspec/expectations/handler.rb +50 -0
  16. data/lib/rspec/matchers.rb +195 -0
  17. data/lib/rspec/matchers/be.rb +210 -0
  18. data/lib/rspec/matchers/be_close.rb +32 -0
  19. data/lib/rspec/matchers/be_instance_of.rb +26 -0
  20. data/lib/rspec/matchers/be_kind_of.rb +26 -0
  21. data/lib/rspec/matchers/change.rb +151 -0
  22. data/lib/rspec/matchers/compatibility.rb +14 -0
  23. data/lib/rspec/matchers/dsl.rb +14 -0
  24. data/lib/rspec/matchers/eql.rb +42 -0
  25. data/lib/rspec/matchers/equal.rb +53 -0
  26. data/lib/rspec/matchers/errors.rb +5 -0
  27. data/lib/rspec/matchers/exist.rb +16 -0
  28. data/lib/rspec/matchers/extensions/instance_exec.rb +23 -0
  29. data/lib/rspec/matchers/generated_descriptions.rb +36 -0
  30. data/lib/rspec/matchers/has.rb +35 -0
  31. data/lib/rspec/matchers/have.rb +151 -0
  32. data/lib/rspec/matchers/include.rb +44 -0
  33. data/lib/rspec/matchers/match.rb +21 -0
  34. data/lib/rspec/matchers/match_array.rb +71 -0
  35. data/lib/rspec/matchers/matcher.rb +86 -0
  36. data/lib/rspec/matchers/method_missing.rb +9 -0
  37. data/lib/rspec/matchers/operator_matcher.rb +78 -0
  38. data/lib/rspec/matchers/pretty.rb +37 -0
  39. data/lib/rspec/matchers/raise_error.rb +129 -0
  40. data/lib/rspec/matchers/respond_to.rb +71 -0
  41. data/lib/rspec/matchers/satisfy.rb +47 -0
  42. data/lib/rspec/matchers/simple_matcher.rb +133 -0
  43. data/lib/rspec/matchers/throw_symbol.rb +104 -0
  44. data/lib/rspec/matchers/wrap_expectation.rb +55 -0
  45. data/rspec-expectations.gemspec +104 -0
  46. data/spec/rspec/expectations/differs/default_spec.rb +128 -0
  47. data/spec/rspec/expectations/extensions/kernel_spec.rb +45 -0
  48. data/spec/rspec/expectations/fail_with_spec.rb +88 -0
  49. data/spec/rspec/expectations/handler_spec.rb +206 -0
  50. data/spec/rspec/expectations/wrap_expectation_spec.rb +30 -0
  51. data/spec/spec.opts +6 -0
  52. data/spec/spec_helper.rb +31 -0
  53. data/spec/suite.rb +1 -0
  54. data/spec/support/macros.rb +29 -0
  55. metadata +135 -0
@@ -0,0 +1,47 @@
1
+ module Rspec
2
+ module Matchers
3
+
4
+ class Satisfy #:nodoc:
5
+ def initialize(&block)
6
+ @block = block
7
+ end
8
+
9
+ def matches?(actual, &block)
10
+ @block = block if block
11
+ @actual = actual
12
+ @block.call(actual)
13
+ end
14
+
15
+ def failure_message_for_should
16
+ "expected #{@actual} to satisfy block"
17
+ end
18
+
19
+ def failure_message_for_should_not
20
+ "expected #{@actual} not to satisfy block"
21
+ end
22
+ end
23
+
24
+ # :call-seq:
25
+ # should satisfy {}
26
+ # should_not satisfy {}
27
+ #
28
+ # Passes if the submitted block returns true. Yields target to the
29
+ # block.
30
+ #
31
+ # Generally speaking, this should be thought of as a last resort when
32
+ # you can't find any other way to specify the behaviour you wish to
33
+ # specify.
34
+ #
35
+ # If you do find yourself in such a situation, you could always write
36
+ # a custom matcher, which would likely make your specs more expressive.
37
+ #
38
+ # == Examples
39
+ #
40
+ # 5.should satisfy { |n|
41
+ # n > 3
42
+ # }
43
+ def satisfy(&block)
44
+ Matchers::Satisfy.new(&block)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,133 @@
1
+ module Rspec
2
+ module Matchers
3
+ class SimpleMatcher
4
+ attr_writer :failure_message, :negative_failure_message, :description
5
+
6
+ def initialize(description, &match_block)
7
+ @description = description
8
+ @match_block = match_block
9
+ @failure_message = @negative_failure_message = nil
10
+ end
11
+
12
+ def matches?(given)
13
+ @given = given
14
+ case @match_block.arity
15
+ when 2
16
+ @match_block.call(@given, self)
17
+ else
18
+ @match_block.call(@given)
19
+ end
20
+ end
21
+
22
+ def description
23
+ @description || explanation
24
+ end
25
+
26
+ def failure_message_for_should
27
+ @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
28
+ end
29
+
30
+ def failure_message_for_should_not
31
+ @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
32
+ end
33
+
34
+ def explanation
35
+ "No description provided. See RDoc for simple_matcher()"
36
+ end
37
+ end
38
+
39
+ # simple_matcher makes it easy for you to create your own custom matchers
40
+ # in just a few lines of code when you don't need all the power of a
41
+ # completely custom matcher object.
42
+ #
43
+ # The <tt>description</tt> argument will appear as part of any failure
44
+ # message, and is also the source for auto-generated descriptions.
45
+ #
46
+ # The <tt>match_block</tt> can have an arity of 1 or 2. The first block
47
+ # argument will be the given value. The second, if the block accepts it
48
+ # will be the matcher itself, giving you access to set custom failure
49
+ # messages in favor of the defaults.
50
+ #
51
+ # The <tt>match_block</tt> should return a boolean: <tt>true</tt>
52
+ # indicates a match, which will pass if you use <tt>should</tt> and fail
53
+ # if you use <tt>should_not</tt>. false (or nil) indicates no match,
54
+ # which will do the reverse: fail if you use <tt>should</tt> and pass if
55
+ # you use <tt>should_not</tt>.
56
+ #
57
+ # An error in the <tt>match_block</tt> will bubble up, resulting in a
58
+ # failure.
59
+ #
60
+ # == Example with default messages
61
+ #
62
+ # def be_even
63
+ # simple_matcher("an even number") { |given| given % 2 == 0 }
64
+ # end
65
+ #
66
+ # describe 2 do
67
+ # it "should be even" do
68
+ # 2.should be_even
69
+ # end
70
+ # end
71
+ #
72
+ # Given an odd number, this example would produce an error message stating:
73
+ # expected "an even number", got 3.
74
+ #
75
+ # Unfortunately, if you're a fan of auto-generated descriptions, this will
76
+ # produce "should an even number." Not the most desirable result. You can
77
+ # control that using custom messages:
78
+ #
79
+ # == Example with custom messages
80
+ #
81
+ # def rhyme_with(expected)
82
+ # simple_matcher("rhyme with #{expected.inspect}") do |given, matcher|
83
+ # matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
84
+ # matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
85
+ # given.rhymes_with? expected
86
+ # end
87
+ # end
88
+ #
89
+ # # OR
90
+ #
91
+ # def rhyme_with(expected)
92
+ # simple_matcher do |given, matcher|
93
+ # matcher.description = "rhyme with #{expected.inspect}"
94
+ # matcher.failure_message = "expected #{given.inspect} to rhyme with #{expected.inspect}"
95
+ # matcher.negative_failure_message = "expected #{given.inspect} not to rhyme with #{expected.inspect}"
96
+ # given.rhymes_with? expected
97
+ # end
98
+ # end
99
+ #
100
+ # describe "pecan" do
101
+ # it "should rhyme with 'be gone'" do
102
+ # nut = "pecan"
103
+ # nut.extend Rhymer
104
+ # nut.should rhyme_with("be gone")
105
+ # end
106
+ # end
107
+ #
108
+ # The resulting messages would be:
109
+ # description: rhyme with "be gone"
110
+ # failure_message: expected "pecan" to rhyme with "be gone"
111
+ # negative failure_message: expected "pecan" not to rhyme with "be gone"
112
+ #
113
+ # == Wrapped Expectations
114
+ #
115
+ # Because errors will bubble up, it is possible to wrap other expectations
116
+ # in a SimpleMatcher.
117
+ #
118
+ # def be_even
119
+ # simple_matcher("an even number") { |given| (given % 2).should == 0 }
120
+ # end
121
+ #
122
+ # BE VERY CAREFUL when you do this. Only use wrapped expectations for
123
+ # matchers that will always be used in only the positive
124
+ # (<tt>should</tt>) or negative (<tt>should_not</tt>), but not both.
125
+ # The reason is that is you wrap a <tt>should</tt> and call the wrapper
126
+ # with <tt>should_not</tt>, the correct result (the <tt>should</tt>
127
+ # failing), will fail when you want it to pass.
128
+ #
129
+ def simple_matcher(description=nil, &match_block)
130
+ SimpleMatcher.new(description, &match_block)
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,104 @@
1
+ module Rspec
2
+ module Matchers
3
+
4
+ class ThrowSymbol #:nodoc:
5
+ def initialize(expected_symbol = nil, expected_arg=nil)
6
+ @expected_symbol = expected_symbol
7
+ @expected_arg = expected_arg
8
+ @caught_symbol = @caught_arg = nil
9
+ end
10
+
11
+ def matches?(given_proc)
12
+ begin
13
+ if @expected_symbol.nil?
14
+ given_proc.call
15
+ else
16
+ @caught_arg = catch :proc_did_not_throw_anything do
17
+ catch @expected_symbol do
18
+ given_proc.call
19
+ throw :proc_did_not_throw_anything, :nothing_thrown
20
+ end
21
+ end
22
+ @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
23
+ end
24
+
25
+ # Ruby 1.8 uses NameError with `symbol'
26
+ # Ruby 1.9 uses ArgumentError with :symbol
27
+ rescue NameError, ArgumentError => e
28
+ raise e unless e.message =~ /uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/
29
+ @caught_symbol = $2.to_sym
30
+
31
+ ensure
32
+ if @expected_symbol.nil?
33
+ return !@caught_symbol.nil?
34
+ else
35
+ if @expected_arg.nil?
36
+ return @caught_symbol == @expected_symbol
37
+ else
38
+ return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def failure_message_for_should
45
+ if @caught_symbol
46
+ "expected #{expected}, got #{@caught_symbol.inspect}"
47
+ else
48
+ "expected #{expected} but nothing was thrown"
49
+ end
50
+ end
51
+
52
+ def failure_message_for_should_not
53
+ if @expected_symbol
54
+ "expected #{expected} not to be thrown"
55
+ else
56
+ "expected no Symbol, got :#{@caught_symbol}"
57
+ end
58
+ end
59
+
60
+ def description
61
+ "throw #{expected}"
62
+ end
63
+
64
+ private
65
+
66
+ def expected
67
+ @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
68
+ end
69
+
70
+ def args
71
+ @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
72
+ end
73
+
74
+ end
75
+
76
+ # :call-seq:
77
+ # should throw_symbol()
78
+ # should throw_symbol(:sym)
79
+ # should throw_symbol(:sym, arg)
80
+ # should_not throw_symbol()
81
+ # should_not throw_symbol(:sym)
82
+ # should_not throw_symbol(:sym, arg)
83
+ #
84
+ # Given no argument, matches if a proc throws any Symbol.
85
+ #
86
+ # Given a Symbol, matches if the given proc throws the specified Symbol.
87
+ #
88
+ # Given a Symbol and an arg, matches if the given proc throws the
89
+ # specified Symbol with the specified arg.
90
+ #
91
+ # == Examples
92
+ #
93
+ # lambda { do_something_risky }.should throw_symbol
94
+ # lambda { do_something_risky }.should throw_symbol(:that_was_risky)
95
+ # lambda { do_something_risky }.should throw_symbol(:that_was_risky, culprit)
96
+ #
97
+ # lambda { do_something_risky }.should_not throw_symbol
98
+ # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky)
99
+ # lambda { do_something_risky }.should_not throw_symbol(:that_was_risky, culprit)
100
+ def throw_symbol(sym=nil)
101
+ Matchers::ThrowSymbol.new(sym)
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,55 @@
1
+ module Rspec
2
+ module Matchers
3
+ # wraps an expectation in a block that will return true if the
4
+ # expectation passes and false if it fails (without bubbling up
5
+ # the failure).
6
+ #
7
+ # This is intended to be used in the context of a simple matcher,
8
+ # and is especially useful for wrapping multiple expectations or
9
+ # one or more assertions from test/unit extensions when running
10
+ # with test/unit.
11
+ #
12
+ # == Examples
13
+ #
14
+ # def eat_cheese(cheese)
15
+ # simple_matcher do |mouse, matcher|
16
+ # matcher.failure_message = "expected #{mouse} to eat cheese"
17
+ # wrap_expectation do |matcher|
18
+ # assert_eats_cheese(mouse)
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # describe Mouse do
24
+ # it "eats cheese" do
25
+ # Mouse.new.should eat_cheese
26
+ # end
27
+ # end
28
+ #
29
+ # You might be wondering "why would I do this if I could just say"
30
+ # assert_eats_cheese?", a fair question, indeed. You might prefer
31
+ # to replace the word assert with something more aligned with the
32
+ # rest of your code examples. You are using rspec, after all.
33
+ #
34
+ # The other benefit you get is that you can use the negative version
35
+ # of the matcher:
36
+ #
37
+ # describe Cat do
38
+ # it "does not eat cheese" do
39
+ # Cat.new.should_not eat_cheese
40
+ # end
41
+ # end
42
+ #
43
+ # So in the event there is no assert_does_not_eat_cheese available,
44
+ # you're all set!
45
+ def wrap_expectation(matcher, &block)
46
+ begin
47
+ block.call(matcher)
48
+ return true
49
+ rescue Exception => e
50
+ matcher.failure_message = e.message
51
+ return false
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,104 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rspec-expectations}
8
+ s.version = "2.0.0.a1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Chelimsky", "Chad Humphries"]
12
+ s.date = %q{2009-09-16}
13
+ s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README.markdown"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "License.txt",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "VERSION.yml",
25
+ "lib/rspec/expectations.rb",
26
+ "lib/rspec/expectations/differs/default.rb",
27
+ "lib/rspec/expectations/differs/load-diff-lcs.rb",
28
+ "lib/rspec/expectations/errors.rb",
29
+ "lib/rspec/expectations/extensions.rb",
30
+ "lib/rspec/expectations/extensions/kernel.rb",
31
+ "lib/rspec/expectations/fail_with.rb",
32
+ "lib/rspec/expectations/handler.rb",
33
+ "lib/rspec/matchers.rb",
34
+ "lib/rspec/matchers/be.rb",
35
+ "lib/rspec/matchers/be_close.rb",
36
+ "lib/rspec/matchers/be_instance_of.rb",
37
+ "lib/rspec/matchers/be_kind_of.rb",
38
+ "lib/rspec/matchers/change.rb",
39
+ "lib/rspec/matchers/compatibility.rb",
40
+ "lib/rspec/matchers/dsl.rb",
41
+ "lib/rspec/matchers/eql.rb",
42
+ "lib/rspec/matchers/equal.rb",
43
+ "lib/rspec/matchers/errors.rb",
44
+ "lib/rspec/matchers/exist.rb",
45
+ "lib/rspec/matchers/extensions/instance_exec.rb",
46
+ "lib/rspec/matchers/generated_descriptions.rb",
47
+ "lib/rspec/matchers/has.rb",
48
+ "lib/rspec/matchers/have.rb",
49
+ "lib/rspec/matchers/include.rb",
50
+ "lib/rspec/matchers/match.rb",
51
+ "lib/rspec/matchers/match_array.rb",
52
+ "lib/rspec/matchers/matcher.rb",
53
+ "lib/rspec/matchers/method_missing.rb",
54
+ "lib/rspec/matchers/operator_matcher.rb",
55
+ "lib/rspec/matchers/pretty.rb",
56
+ "lib/rspec/matchers/raise_error.rb",
57
+ "lib/rspec/matchers/respond_to.rb",
58
+ "lib/rspec/matchers/satisfy.rb",
59
+ "lib/rspec/matchers/simple_matcher.rb",
60
+ "lib/rspec/matchers/throw_symbol.rb",
61
+ "lib/rspec/matchers/wrap_expectation.rb",
62
+ "rspec-expectations.gemspec",
63
+ "spec/rspec/expectations/differs/default_spec.rb",
64
+ "spec/rspec/expectations/extensions/kernel_spec.rb",
65
+ "spec/rspec/expectations/fail_with_spec.rb",
66
+ "spec/rspec/expectations/handler_spec.rb",
67
+ "spec/rspec/expectations/wrap_expectation_spec.rb",
68
+ "spec/spec.opts",
69
+ "spec/spec_helper.rb",
70
+ "spec/suite.rb",
71
+ "spec/support/macros.rb"
72
+ ]
73
+ s.homepage = %q{http://github.com/rspec/expectations}
74
+ s.rdoc_options = ["--charset=UTF-8"]
75
+ s.require_paths = ["lib"]
76
+ s.rubygems_version = %q{1.3.5}
77
+ s.summary = %q{rspec expectations (should[_not] and matchers)}
78
+ s.test_files = [
79
+ "spec/rspec/expectations/differs/default_spec.rb",
80
+ "spec/rspec/expectations/extensions/kernel_spec.rb",
81
+ "spec/rspec/expectations/fail_with_spec.rb",
82
+ "spec/rspec/expectations/handler_spec.rb",
83
+ "spec/rspec/expectations/wrap_expectation_spec.rb",
84
+ "spec/spec_helper.rb",
85
+ "spec/suite.rb",
86
+ "spec/support/macros.rb"
87
+ ]
88
+
89
+ if s.respond_to? :specification_version then
90
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
91
+ s.specification_version = 3
92
+
93
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
94
+ s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.a1"])
95
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a1"])
96
+ else
97
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.a1"])
98
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a1"])
99
+ end
100
+ else
101
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.a1"])
102
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a1"])
103
+ end
104
+ end
@@ -0,0 +1,128 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
+ require 'ostruct'
3
+
4
+ module Rspec
5
+ module Fixtures
6
+ class Animal
7
+ def initialize(name,species)
8
+ @name,@species = name,species
9
+ end
10
+
11
+ def inspect
12
+ <<-EOA
13
+ <Animal
14
+ name=#{@name},
15
+ species=#{@species}
16
+ >
17
+ EOA
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "Diff" do
24
+ before(:each) do
25
+ @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
26
+ @differ = Rspec::Expectations::Differs::Default.new(@options)
27
+ end
28
+
29
+ it "should output unified diff of two strings" do
30
+ expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
31
+ actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
32
+ expected_diff= <<'EOD'
33
+
34
+
35
+ @@ -1,6 +1,6 @@
36
+ foo
37
+ -zap
38
+ bar
39
+ +zap
40
+ this
41
+ is
42
+ soo
43
+ @@ -9,6 +9,5 @@
44
+ equal
45
+ insert
46
+ a
47
+ -another
48
+ line
49
+ EOD
50
+
51
+ diff = @differ.diff_as_string(expected, actual)
52
+ diff.should eql(expected_diff)
53
+ end
54
+
55
+ it "should output unified diff message of two arrays" do
56
+ expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
57
+ actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
58
+
59
+ expected_diff = <<'EOD'
60
+
61
+
62
+ @@ -5,7 +5,7 @@
63
+ :metasyntactic,
64
+ "variable",
65
+ :delta,
66
+ - "tango",
67
+ + "charlie",
68
+ :width,
69
+ - "very wide"]
70
+ + "quite wide"]
71
+ EOD
72
+
73
+
74
+ diff = @differ.diff_as_object(expected,actual)
75
+ diff.should == expected_diff
76
+ end
77
+
78
+ it "should output unified diff message of two objects" do
79
+ expected = Rspec::Fixtures::Animal.new "bob", "giraffe"
80
+ actual = Rspec::Fixtures::Animal.new "bob", "tortoise"
81
+
82
+ expected_diff = <<'EOD'
83
+
84
+ @@ -1,5 +1,5 @@
85
+ <Animal
86
+ name=bob,
87
+ - species=tortoise
88
+ + species=giraffe
89
+ >
90
+ EOD
91
+
92
+ diff = @differ.diff_as_object(expected,actual)
93
+ diff.should == expected_diff
94
+ end
95
+
96
+ end
97
+
98
+
99
+ describe "Diff in context format" do
100
+ before(:each) do
101
+ @options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
102
+ @options.diff_format = :context
103
+ @differ = Rspec::Expectations::Differs::Default.new(@options)
104
+ end
105
+
106
+ it "should output unified diff message of two objects" do
107
+ expected = Rspec::Fixtures::Animal.new "bob", "giraffe"
108
+ actual = Rspec::Fixtures::Animal.new "bob", "tortoise"
109
+
110
+ expected_diff = <<'EOD'
111
+
112
+ ***************
113
+ *** 1,5 ****
114
+ <Animal
115
+ name=bob,
116
+ ! species=tortoise
117
+ >
118
+ --- 1,5 ----
119
+ <Animal
120
+ name=bob,
121
+ ! species=giraffe
122
+ >
123
+ EOD
124
+
125
+ diff = @differ.diff_as_object(expected,actual)
126
+ diff.should == expected_diff
127
+ end
128
+ end