Sha256: 78a09b5a61322ecac9c29a66b1f49990ecc8b3cad43f747d91bc26cf7bfeb753

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper.rb'

module Spec
  module Mocks

    describe "an expectation set on nil" do
      
      it "should issue a warning with file and line number information" do
        expected_warning = "An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}. Use allow_message_expectations_on_nil to disable warnings."
        Kernel.should_receive(:warn).with(expected_warning)

        nil.should_receive(:foo)
        nil.foo
      end
      
      it "should issue a warning when the expectation is negative" do
        Kernel.should_receive(:warn)

        nil.should_not_receive(:foo)
      end
      
      it "should not issue a warning when expectations are set to be allowed" do
        allow_message_expectations_on_nil
        Kernel.should_not_receive(:warn)
        
        nil.should_receive(:foo)
        nil.should_not_receive(:bar)
        nil.foo
      end

    end
    
    describe "#allow_message_expectations_on_nil" do
      include SandboxedOptions
      
      it "should not effect subsequent examples" do
        example_group = Class.new(ExampleGroup)
        example_group.it("when called in one example that doesn't end up setting an expectation on nil") do
                        allow_message_expectations_on_nil
                      end
        example_group.it("should not effect the next exapmle ran") do
                        Kernel.should_receive(:warn)
                        nil.should_receive(:foo)
                        nil.foo
                      end
                              
        example_group.run.should be_true
                  
      end

    end
    
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
pictrails-0.5.0 vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.5 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.6 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.7 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.8 spec/spec/mocks/nil_expectation_warning_spec.rb