1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/expectations/expectations'
3 require 'mspec/matchers/base'
4 require 'mspec/runner/mspec'
7 alias_method :rspec_should, :should
8 alias_method :rspec_should_not, :should_not
10 require 'mspec/expectations/should'
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
18 # Adapted from RSpec 1.0.8
19 describe Object, "#should" 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)
30 @matcher = mock("matcher", :null_object => true)
34 class Object; alias_method :should, :rspec_should; end
37 it "accepts and interacts with a matcher" do
38 @matcher.should_receive(:matches?).with(@target).and_return(true)
39 @target.should @matcher
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
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"])
52 @target.should @matcher
53 }.should raise_error(ExpectationNotMetError, "expected actual")
56 it "returns a PostiveOperatorMatcher instance when not passed a matcher" do
58 class Object; alias_method :should, :rspec_should; end
59 matcher.should be_instance_of(PositiveOperatorMatcher)
62 it "invokes the MSpec :expectation actions" do
63 MSpec.should_receive(:actions).with(:expectation, @state)
64 @target.should @matcher
67 it "registers that an expectation has been encountered" do
68 MSpec.should_receive(:expectation)
69 @target.should @matcher
73 describe Object, "#should_not" 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)
85 @matcher = mock("matcher", :null_object => true)
89 class Object; alias_method :should, :rspec_should; end
90 class Object; alias_method :should_not, :rspec_should_not; 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
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
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"])
108 @target.should_not @matcher
109 }.should raise_error(ExpectationNotMetError, "expected actual")
112 it "returns a NegativeOperatorMatcher instance when not passed a matcher" do
114 class Object; alias_method :should, :rspec_should; end
115 matcher.should be_instance_of(NegativeOperatorMatcher)
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
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