]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/expectations/fail_with_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / expectations / fail_with_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 describe Spec::Expectations, "#fail_with with no diff" do
4   before(:each) do
5     @old_differ = Spec::Expectations.differ
6     Spec::Expectations.differ = nil
7   end
8   
9   it "should handle just a message" do
10     lambda {
11       Spec::Expectations.fail_with "the message"
12     }.should fail_with("the message")
13   end
14   
15   it "should handle an Array" do
16     lambda {
17       Spec::Expectations.fail_with ["the message","expected","actual"]
18     }.should fail_with("the message")
19   end
20
21   after(:each) do
22     Spec::Expectations.differ = @old_differ
23   end
24 end
25
26 describe Spec::Expectations, "#fail_with with diff" do
27   before(:each) do
28     @old_differ = Spec::Expectations.differ
29     @differ = mock("differ")
30     Spec::Expectations.differ = @differ
31   end
32   
33   it "should not call differ if no expected/actual" do
34     lambda {
35       Spec::Expectations.fail_with "the message"
36     }.should fail_with("the message")
37   end
38   
39   it "should call differ if expected/actual are presented separately" do
40     @differ.should_receive(:diff_as_string).and_return("diff")
41     lambda {
42       Spec::Expectations.fail_with "the message", "expected", "actual"
43     }.should fail_with("the message\nDiff:diff")
44   end
45   
46   it "should call differ if expected/actual are not strings" do
47     @differ.should_receive(:diff_as_object).and_return("diff")
48     lambda {
49       Spec::Expectations.fail_with "the message", :expected, :actual
50     }.should fail_with("the message\nDiff:diff")
51   end
52   
53   it "should not call differ if expected or actual are procs" do
54     @differ.should_not_receive(:diff_as_string)
55     @differ.should_not_receive(:diff_as_object)
56     lambda {
57       Spec::Expectations.fail_with "the message", lambda {}, lambda {}
58     }.should fail_with("the message")
59   end
60   
61   it "should call differ if expected/actual are presented in an Array with message" do
62     @differ.should_receive(:diff_as_string).with("actual","expected").and_return("diff")
63     lambda {
64       Spec::Expectations.fail_with(["the message", "expected", "actual"])
65     }.should fail_with(/the message\nDiff:diff/)
66   end
67   
68   after(:each) do
69     Spec::Expectations.differ = @old_differ
70   end
71 end