Sha256: 19226a1317fb565348c21027707370dbd82f7173dbf44f97b6d00ddb0ff2eac8

Contents?: true

Size: 1.44 KB

Versions: 11

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

module RSpec
  module Mocks
    describe "a mock acting as a NullObject" do
      before(:each) do
        @mock = RSpec::Mocks::Mock.new("null_object").as_null_object
      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(RSpec::Mocks::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 = double('anything')
        obj.should_not be_null_object
      end
    end
    
    describe "#as_null_object" do
      it "should set the object to null_object" do
        obj = double('anything').as_null_object
        obj.should be_null_object
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rspec-mocks-2.0.0.beta.19 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.18 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.17 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.16 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.15 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.14 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.13 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.12 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.11 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.10 spec/rspec/mocks/null_object_mock_spec.rb
rspec-mocks-2.0.0.beta.9 spec/rspec/mocks/null_object_mock_spec.rb