1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 describe Spec::Expectations, "#fail_with with no diff" do
5 @old_differ = Spec::Expectations.differ
6 Spec::Expectations.differ = nil
9 it "should handle just a message" do
11 Spec::Expectations.fail_with "the message"
12 }.should fail_with("the message")
15 it "should handle an Array" do
17 Spec::Expectations.fail_with ["the message","expected","actual"]
18 }.should fail_with("the message")
22 Spec::Expectations.differ = @old_differ
26 describe Spec::Expectations, "#fail_with with diff" do
28 @old_differ = Spec::Expectations.differ
29 @differ = mock("differ")
30 Spec::Expectations.differ = @differ
33 it "should not call differ if no expected/actual" do
35 Spec::Expectations.fail_with "the message"
36 }.should fail_with("the message")
39 it "should call differ if expected/actual are presented separately" do
40 @differ.should_receive(:diff_as_string).and_return("diff")
42 Spec::Expectations.fail_with "the message", "expected", "actual"
43 }.should fail_with("the message\nDiff:diff")
46 it "should call differ if expected/actual are not strings" do
47 @differ.should_receive(:diff_as_object).and_return("diff")
49 Spec::Expectations.fail_with "the message", :expected, :actual
50 }.should fail_with("the message\nDiff:diff")
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)
57 Spec::Expectations.fail_with "the message", lambda {}, lambda {}
58 }.should fail_with("the message")
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")
64 Spec::Expectations.fail_with(["the message", "expected", "actual"])
65 }.should fail_with(/the message\nDiff:diff/)
69 Spec::Expectations.differ = @old_differ