X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/ddd5b4cf19a92582fd114914be5bd5a04d3522a7..3f607d565bc0e2c7b1b738301c11c16d069913d5:/vendor/gems/rspec-1.1.2/spec/spec/expectations/fail_with_spec.rb diff --git a/vendor/gems/rspec-1.1.2/spec/spec/expectations/fail_with_spec.rb b/vendor/gems/rspec-1.1.2/spec/spec/expectations/fail_with_spec.rb new file mode 100644 index 000000000..4c369ce3a --- /dev/null +++ b/vendor/gems/rspec-1.1.2/spec/spec/expectations/fail_with_spec.rb @@ -0,0 +1,71 @@ +require File.dirname(__FILE__) + '/../../spec_helper.rb' + +describe Spec::Expectations, "#fail_with with no diff" do + before(:each) do + @old_differ = Spec::Expectations.differ + Spec::Expectations.differ = nil + end + + it "should handle just a message" do + lambda { + Spec::Expectations.fail_with "the message" + }.should fail_with("the message") + end + + it "should handle an Array" do + lambda { + Spec::Expectations.fail_with ["the message","expected","actual"] + }.should fail_with("the message") + end + + after(:each) do + Spec::Expectations.differ = @old_differ + end +end + +describe Spec::Expectations, "#fail_with with diff" do + before(:each) do + @old_differ = Spec::Expectations.differ + @differ = mock("differ") + Spec::Expectations.differ = @differ + end + + it "should not call differ if no expected/actual" do + lambda { + Spec::Expectations.fail_with "the message" + }.should fail_with("the message") + end + + it "should call differ if expected/actual are presented separately" do + @differ.should_receive(:diff_as_string).and_return("diff") + lambda { + Spec::Expectations.fail_with "the message", "expected", "actual" + }.should fail_with("the message\nDiff:diff") + end + + it "should call differ if expected/actual are not strings" do + @differ.should_receive(:diff_as_object).and_return("diff") + lambda { + Spec::Expectations.fail_with "the message", :expected, :actual + }.should fail_with("the message\nDiff:diff") + end + + it "should not call differ if expected or actual are procs" do + @differ.should_not_receive(:diff_as_string) + @differ.should_not_receive(:diff_as_object) + lambda { + Spec::Expectations.fail_with "the message", lambda {}, lambda {} + }.should fail_with("the message") + end + + it "should call differ if expected/actual are presented in an Array with message" do + @differ.should_receive(:diff_as_string).with("actual","expected").and_return("diff") + lambda { + Spec::Expectations.fail_with(["the message", "expected", "actual"]) + }.should fail_with(/the message\nDiff:diff/) + end + + after(:each) do + Spec::Expectations.differ = @old_differ + end +end