Sha256: ea54a066f4abf24321cef82ca2dabee1b21376d6f63404d21dff95ff63e13444

Contents?: true

Size: 1.67 KB

Versions: 21

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

def remove_last_describe_from_world
  RSpec::world.example_groups.pop
end

def empty_example_group
  RSpec::Core::ExampleGroup.describe(Object, 'Empty Behaviour Group') { }
  remove_last_describe_from_world
end

module RSpec
  module Mocks
    describe "an expectation set on nil" do
      it "issues 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 .+)?. Use allow_message_expectations_on_nil to disable warnings.%
        Kernel.should_receive(:warn).with(expected_warning)

        nil.should_receive(:foo)
        nil.foo
      end

      it "issues a warning when the expectation is negative" do
        Kernel.should_receive(:warn)

        nil.should_not_receive(:foo)
      end

      it "does 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 "does not effect subsequent examples" do
        example_group = empty_example_group
        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
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
spy-1.0.3 spec/spy/nil_expectation_warning_spec.rb
spy-1.0.2 spec/spy/nil_expectation_warning_spec.rb
spy-1.0.1 spec/spy/nil_expectation_warning_spec.rb
spy-1.0.0 spec/spy/nil_expectation_warning_spec.rb
spy-0.4.5 spec/spy/nil_expectation_warning_spec.rb
spy-0.4.3 spec/spy/nil_expectation_warning_spec.rb
spy-0.4.2 spec/spy/nil_expectation_warning_spec.rb
spy-0.4.1 spec/spy/nil_expectation_warning_spec.rb
spy-0.4.0 spec/spy/nil_expectation_warning_spec.rb
spy-0.3.1 spec/spy/nil_expectation_warning_spec.rb
spy-0.3.0 spec/spy/nil_expectation_warning_spec.rb
spy-0.2.5 spec/spy/nil_expectation_warning_spec.rb
spy-0.2.4 spec/spy/nil_expectation_warning_spec.rb
spy-0.2.3 spec/spy/nil_expectation_warning_spec.rb
spy-0.2.2 spec/spy/nil_expectation_warning_spec.rb
spy-0.2.1 spec/spy/nil_expectation_warning_spec.rb
spy-0.1.0 spec/spy/nil_expectation_warning_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/nil_expectation_warning_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/nil_expectation_warning_spec.rb
spy-0.0.1 spec/spy/nil_expectation_warning_spec.rb