Sha256: 48d0837147c6597df3db36134c51c0d1fe3f13f0a7e8e2d162fbd469722f66cf

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

module Rspec
  module Mocks
    module ExampleMethods
      include Rspec::Mocks::ArgumentMatchers

      # Shortcut for creating an instance of Rspec::Mocks::Mock.
      #
      # +name+ is used for failure reporting, so you should use the
      # role that the mock is playing in the example.
      #
      # +stubs_and_options+ lets you assign options and stub values
      # at the same time. The only option available is :null_object.
      # Anything else is treated as a stub value.
      #
      # == Examples
      #
      #   stub_thing = double("thing", :a => "A")
      #   stub_thing.a == "A" => true
      #
      #   stub_person = stub("thing", :name => "Joe", :email => "joe@domain.com")
      #   stub_person.name => "Joe"
      #   stub_person.email => "joe@domain.com"
      def double(*args)
        declare_double('Double', *args)
      end

      # Just like double, but use double
      def mock(*args)
        declare_double('Mock', *args)
      end

      # Just like double, but use double
      def stub(*args)
        declare_double('Stub', *args)
      end

      # Disables warning messages about expectations being set on nil.
      #
      # By default warning messages are issued when expectations are set on nil.  This is to
      # prevent false-positives and to catch potential bugs early on.
      def allow_message_expectations_on_nil
        Proxy.allow_message_expectations_on_nil
      end

    private
      
      def declare_double(declared_as, *args) # :nodoc:
        args << {} unless Hash === args.last
        args.last[:__declared_as] = declared_as
        Rspec::Mocks::Mock.new(*args)
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-mocks-2.0.0.beta.8 lib/rspec/mocks/spec_methods.rb
rspec-mocks-2.0.0.beta.7 lib/rspec/mocks/spec_methods.rb
rspec-mocks-2.0.0.beta.6 lib/rspec/mocks/spec_methods.rb
rspec-mocks-2.0.0.beta.5 lib/rspec/mocks/spec_methods.rb