Sha256: c76bc09206e913642f7d71761b955b23490175a2afda2d6853f6c243695e17c0

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 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
      
      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

15 entries across 15 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.10 spec/spec/mocks/nil_expectation_warning_spec.rb
dchelimsky-rspec-1.1.11.1 spec/spec/mocks/nil_expectation_warning_spec.rb
dchelimsky-rspec-1.1.11 spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
mack-0.8.2 lib/gems/rspec-1.1.11/spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.10 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.11 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.1.9 spec/spec/mocks/nil_expectation_warning_spec.rb
typo-5.1.98 vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
typo-5.2 vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb