Sha256: 48d74e76f44c23479ab4ccd6902b052e411a32a76d266199bef35755bcc0a8ed

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

class FlexMock

  # Expectations on mocks with a base class can only be defined on
  # methods supported by the base class. Attempting to add an stub to
  # a method not defined on the base class will cause the expectation
  # to be wrapped in an ExplicitNeeded wrapper. The wrapper will throw
  # an exception unless the explicitly method is immediately called on
  # the expectation.
  #
  class ExplicitNeeded
    def initialize(expectation, method_name, base_class)
      @expectation = expectation
      @explicit = false
      @method_name = method_name
      @base_class = base_class
    end

    def explicitly
      @explicit = true
      self
    end

    def explicit?
      @explicit
    end

    def mock=(m)
      @expectation.mock = m
    end

    def method_missing(sym, *args, &block)
      if explicit?
        @expectation.send(sym, *args, &block)
      else
        fail NoMethodError, "Cannot stub methods not defined by the base class\n" +
          "   Method:     #{@method_name}\n" +
          "   Base Class: #{@base_class}\n" +
          "   (Use 'explicitly' to override)"
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
flexmock-2.3.5 lib/flexmock/explicit_needed.rb
flexmock-2.3.4 lib/flexmock/explicit_needed.rb
flexmock-2.3.3 lib/flexmock/explicit_needed.rb
flexmock-2.3.2 lib/flexmock/explicit_needed.rb
flexmock-2.3.1 lib/flexmock/explicit_needed.rb
flexmock-2.3.0 lib/flexmock/explicit_needed.rb
flexmock-2.2.1 lib/flexmock/explicit_needed.rb
flexmock-2.2.0 lib/flexmock/explicit_needed.rb
flexmock-2.1.0 lib/flexmock/explicit_needed.rb
flexmock-2.0.6 lib/flexmock/explicit_needed.rb
flexmock-2.0.5 lib/flexmock/explicit_needed.rb
flexmock-2.0.4 lib/flexmock/explicit_needed.rb
flexmock-2.0.3 lib/flexmock/explicit_needed.rb
flexmock-2.0.2 lib/flexmock/explicit_needed.rb
flexmock-2.0.1 lib/flexmock/explicit_needed.rb
flexmock-2.0.0 lib/flexmock/explicit_needed.rb
flexmock-2.0.0.rc1 lib/flexmock/explicit_needed.rb
flexmock-1.3.3 lib/flexmock/explicit_needed.rb
flexmock-1.3.2 lib/flexmock/explicit_needed.rb
flexmock-1.3.1 lib/flexmock/explicit_needed.rb