X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/ddd5b4cf19a92582fd114914be5bd5a04d3522a7..3f607d565bc0e2c7b1b738301c11c16d069913d5:/vendor/gems/rspec-1.1.2/spec/spec/expectations/extensions/object_spec.rb diff --git a/vendor/gems/rspec-1.1.2/spec/spec/expectations/extensions/object_spec.rb b/vendor/gems/rspec-1.1.2/spec/spec/expectations/extensions/object_spec.rb new file mode 100644 index 000000000..0d9335bdb --- /dev/null +++ b/vendor/gems/rspec-1.1.2/spec/spec/expectations/extensions/object_spec.rb @@ -0,0 +1,107 @@ +require File.dirname(__FILE__) + '/../../../spec_helper.rb' + +describe Object, "#should" do + before(:each) do + @target = "target" + @matcher = mock("matcher") + @matcher.stub!(:matches?).and_return(true) + @matcher.stub!(:failure_message) + end + + it "should accept and interact with a matcher" do + @matcher.should_receive(:matches?).with(@target).and_return(true) + @target.should @matcher + end + + it "should ask for a failure_message when matches? returns false" do + @matcher.should_receive(:matches?).with(@target).and_return(false) + @matcher.should_receive(:failure_message).and_return("the failure message") + lambda { + @target.should @matcher + }.should fail_with("the failure message") + end + + it "should raise error if it receives false directly" do + lambda { + @target.should false + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives false (evaluated)" do + lambda { + @target.should eql?("foo") + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives true" do + lambda { + @target.should true + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives nil" do + lambda { + @target.should nil + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives no argument and it is not used as a left side of an operator" do + pending "Is it even possible to catch this?" + lambda { + @target.should + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end +end + +describe Object, "#should_not" do + before(:each) do + @target = "target" + @matcher = mock("matcher") + end + + it "should accept and interact with a matcher" do + @matcher.should_receive(:matches?).with(@target).and_return(false) + @matcher.stub!(:negative_failure_message) + + @target.should_not @matcher + end + + it "should ask for a negative_failure_message when matches? returns true" do + @matcher.should_receive(:matches?).with(@target).and_return(true) + @matcher.should_receive(:negative_failure_message).and_return("the negative failure message") + lambda { + @target.should_not @matcher + }.should fail_with("the negative failure message") + end + + it "should raise error if it receives false directly" do + lambda { + @target.should_not false + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives false (evaluated)" do + lambda { + @target.should_not eql?("foo") + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives true" do + lambda { + @target.should_not true + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives nil" do + lambda { + @target.should_not nil + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end + + it "should raise error if it receives no argument and it is not used as a left side of an operator" do + pending "Is it even possible to catch this?" + lambda { + @target.should_not + }.should raise_error(Spec::Expectations::InvalidMatcherError) + end +end