Sha256: c1a7db8f34f7deed066c0a62a7d75ec623df6402f71b07f76a7d865dca424ad9

Contents?: true

Size: 1.67 KB

Versions: 32

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

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 = %r%An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}(:in `block \(2 levels\) in <module:Mocks>')?. 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(::Spec::Example::ExampleGroupDouble)
        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(Spec::Runner.options).should be_true
                  
      end

    end
    
  end
end

Version data entries

32 entries across 32 versions & 11 rubygems

Version Path
rspec-instructure-1.3.3 spec/spec/mocks/nil_expectation_warning_spec.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.3.2 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.3.1 spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.3.1.rc spec/spec/mocks/nil_expectation_warning_spec.rb
rspec-1.3.0 spec/spec/mocks/nil_expectation_warning_spec.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/spec/spec/mocks/nil_expectation_warning_spec.rb
media-path-0.1.2 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
simple-templater-0.0.1.3 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
pupu-0.0.2.pre vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
media-path-0.1.1.pre vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
simple-templater-0.0.1.2 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
media-path-0.1.1 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
simple-templater-0.0.1.1 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb
pupu-0.0.2 vendor/rspec/spec/spec/mocks/nil_expectation_warning_spec.rb