1 require File.dirname(__FILE__) + '/../../../spec_helper.rb'
3 describe Object, "#should" do
6 @matcher = mock("matcher")
7 @matcher.stub!(:matches?).and_return(true)
8 @matcher.stub!(:failure_message)
11 it "should accept and interact with a matcher" do
12 @matcher.should_receive(:matches?).with(@target).and_return(true)
13 @target.should @matcher
16 it "should ask for a failure_message when matches? returns false" do
17 @matcher.should_receive(:matches?).with(@target).and_return(false)
18 @matcher.should_receive(:failure_message).and_return("the failure message")
20 @target.should @matcher
21 }.should fail_with("the failure message")
24 it "should raise error if it receives false directly" do
27 }.should raise_error(Spec::Expectations::InvalidMatcherError)
30 it "should raise error if it receives false (evaluated)" do
32 @target.should eql?("foo")
33 }.should raise_error(Spec::Expectations::InvalidMatcherError)
36 it "should raise error if it receives true" do
39 }.should raise_error(Spec::Expectations::InvalidMatcherError)
42 it "should raise error if it receives nil" do
45 }.should raise_error(Spec::Expectations::InvalidMatcherError)
48 it "should raise error if it receives no argument and it is not used as a left side of an operator" do
49 pending "Is it even possible to catch this?"
52 }.should raise_error(Spec::Expectations::InvalidMatcherError)
56 describe Object, "#should_not" do
59 @matcher = mock("matcher")
62 it "should accept and interact with a matcher" do
63 @matcher.should_receive(:matches?).with(@target).and_return(false)
64 @matcher.stub!(:negative_failure_message)
66 @target.should_not @matcher
69 it "should ask for a negative_failure_message when matches? returns true" do
70 @matcher.should_receive(:matches?).with(@target).and_return(true)
71 @matcher.should_receive(:negative_failure_message).and_return("the negative failure message")
73 @target.should_not @matcher
74 }.should fail_with("the negative failure message")
77 it "should raise error if it receives false directly" do
79 @target.should_not false
80 }.should raise_error(Spec::Expectations::InvalidMatcherError)
83 it "should raise error if it receives false (evaluated)" do
85 @target.should_not eql?("foo")
86 }.should raise_error(Spec::Expectations::InvalidMatcherError)
89 it "should raise error if it receives true" do
91 @target.should_not true
92 }.should raise_error(Spec::Expectations::InvalidMatcherError)
95 it "should raise error if it receives nil" do
97 @target.should_not nil
98 }.should raise_error(Spec::Expectations::InvalidMatcherError)
101 it "should raise error if it receives no argument and it is not used as a left side of an operator" do
102 pending "Is it even possible to catch this?"
105 }.should raise_error(Spec::Expectations::InvalidMatcherError)