Sha256: c84d8b36c646889eb3f91e98493e70801bc76d094d485de6218b06cab63b36f2

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

module Rspec
  module Mocks
    describe "a mock acting as a NullObject" do
      before(:each) do
        @mock = Mock.new("null_object", :null_object => true)
      end

      it "should allow explicit expectation" do
        @mock.should_receive(:something)
        @mock.something
      end

      it "should fail verification when explicit exception not met" do
        lambda do
          @mock.should_receive(:something)
          @mock.rspec_verify
        end.should raise_error(MockExpectationError)
      end

      it "should ignore unexpected methods" do
        @mock.random_call("a", "d", "c")
        @mock.rspec_verify
      end

      it "should expected message with different args first" do
        @mock.should_receive(:message).with(:expected_arg)
        @mock.message(:unexpected_arg)
        @mock.message(:expected_arg)
      end

      it "should expected message with different args second" do
        @mock.should_receive(:message).with(:expected_arg)
        @mock.message(:expected_arg)
        @mock.message(:unexpected_arg)
      end
    end

    describe "#null_object?" do
      it "should default to false" do
        obj = mock('anything')
        obj.should_not be_null_object
      end
    end
    
    describe "#as_null_object" do
      it "should set the object to null_object" do
        obj = mock('anything').as_null_object
        obj.should be_null_object
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rspec-mocks-2.0.0.beta.1 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a10 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a9 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a8 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a7 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a6 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a5 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a4 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.a3 spec/rspec/mocks/null_object_mock_spec.rb