Re-enable spec/library for full CI runs.
[rbx.git] / mspec / spec / expectations / should_spec.rb
blob55cd5ce196d6505647319fe65bc860f31d551d42
1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/expectations/expectations'
3 require 'mspec/matchers/base'
4 require 'mspec/runner/mspec'
6 class Object
7   alias_method :rspec_should,     :should
8   alias_method :rspec_should_not, :should_not
9 end
10 require 'mspec/expectations/should'
11 class Object
12   alias_method :mspec_should,     :should
13   alias_method :mspec_should_not, :should_not
14   alias_method :should,           :rspec_should
15   alias_method :should_not,       :rspec_should_not
16 end
18 # Adapted from RSpec 1.0.8
19 describe Object, "#should" do
20   before :each do
21     class Object; alias_method :should, :mspec_should; end
23     @state = mock("example state", :null_object => true)
24     context = mock("context state", :null_object => true)
25     context.stub!(:state).and_return(@state)
26     MSpec.stub!(:current).and_return(context)
27     MSpec.stub!(:actions)
29     @target = "target"
30     @matcher = mock("matcher", :null_object => true)
31   end
33   after :each do
34     class Object; alias_method :should, :rspec_should; end
35   end
37   it "accepts and interacts with a matcher" do
38     @matcher.should_receive(:matches?).with(@target).and_return(true)
39     @target.should @matcher
40   end
42   it "calls #failure_message when matcher #matches? returns false" do
43     @matcher.should_receive(:matches?).with(@target).and_return(false)
44     @matcher.should_receive(:failure_message).and_return(["expected", "actual"])
45     @target.should @matcher rescue nil
46   end
48   it "raises an ExpectationNotMetError when matcher #matches? returns false" do
49     @matcher.should_receive(:matches?).with(@target).and_return(false)
50     @matcher.should_receive(:failure_message).and_return(["expected", "actual"])
51     lambda {
52       @target.should @matcher
53     }.should raise_error(ExpectationNotMetError, "expected actual")
54   end
56   it "returns a PostiveOperatorMatcher instance when not passed a matcher" do
57     matcher = should
58     class Object; alias_method :should, :rspec_should; end
59     matcher.should be_instance_of(PositiveOperatorMatcher)
60   end
62   it "invokes the MSpec :expectation actions" do
63     MSpec.should_receive(:actions).with(:expectation, @state)
64     @target.should @matcher
65   end
67   it "registers that an expectation has been encountered" do
68     MSpec.should_receive(:expectation)
69     @target.should @matcher
70   end
71 end
73 describe Object, "#should_not" do
74   before :each do
75     class Object; alias_method :should,     :mspec_should; end
76     class Object; alias_method :should_not, :mspec_should_not; end
78     @state = mock("example state", :null_object => true)
79     context = mock("context state", :null_object => true)
80     context.stub!(:state).and_return(@state)
81     MSpec.stub!(:current).and_return(context)
82     MSpec.stub!(:actions)
84     @target = "target"
85     @matcher = mock("matcher", :null_object => true)
86   end
88   after :each do
89     class Object; alias_method :should,     :rspec_should; end
90     class Object; alias_method :should_not, :rspec_should_not; end
91   end
93   it "accepts and interacts with a matcher" do
94     @matcher.should_receive(:matches?).with(@target).and_return(false)
95     @target.should_not @matcher
96   end
98   it "calls #negative_failure_message when matcher.matches? returns true" do
99     @matcher.should_receive(:matches?).with(@target).and_return(true)
100     @matcher.should_receive(:negative_failure_message).and_return(["expected", "actual"])
101     @target.should_not @matcher rescue nil
102   end
104   it "raises an ExpectationNotMetError when matcher.matches? returns true" do
105     @matcher.should_receive(:matches?).with(@target).and_return(true)
106     @matcher.should_receive(:negative_failure_message).and_return(["expected", "actual"])
107     lambda {
108       @target.should_not @matcher
109     }.should raise_error(ExpectationNotMetError, "expected actual")
110   end
112   it "returns a NegativeOperatorMatcher instance when not passed a matcher" do
113     matcher = should_not
114     class Object; alias_method :should, :rspec_should; end
115     matcher.should be_instance_of(NegativeOperatorMatcher)
116   end
118   it "invokes the MSpec :expectation actions" do
119     MSpec.should_receive(:actions).with(:expectation, @state)
120     @matcher.should_receive(:negative_failure_message).and_return(["expected", "actual"])
121     @target.should_not @matcher rescue nil
122   end
124   it "registers that an expectation has been encountered" do
125     MSpec.should_receive(:expectation)
126     @matcher.should_receive(:negative_failure_message).and_return(["expected", "actual"])
127     @target.should_not @matcher rescue nil
128   end