Class: FlexMock::ExplicitNeeded

### Home Classes Methods

### In Files

- lib/flexmock/explicit_needed.rb

### Parent

Object

### Methods

- ::new
- #explicit?
- #explicitly
- #method_missing
- #mock=

### Files

- CHANGES
- GoogleExample.rdoc
- rspec_examples_spec.rdoc
- test_unit_examples_test.rdoc
- index.rdoc
- flexmock-0.4.0.rdoc
- flexmock-0.4.1.rdoc
- flexmock-0.4.2.rdoc
- flexmock-0.4.3.rdoc
- flexmock-0.5.0.rdoc
- flexmock-0.5.1.rdoc
- flexmock-0.6.0.rdoc
- flexmock-0.6.1.rdoc
- flexmock-0.6.2.rdoc
- flexmock-0.6.3.rdoc
- flexmock-0.6.4.rdoc
- flexmock-0.7.0.rdoc
- flexmock-0.7.1.rdoc
- flexmock-0.8.0.rdoc
- flexmock-0.8.2.rdoc
- flexmock-0.8.3.rdoc
- flexmock-0.8.4.rdoc
- flexmock-0.8.5.rdoc
- flexmock-0.9.0.rdoc
- flexmock-1.0.0.rdoc
- flexmock-1.0.3.rdoc
- flexmock-1.0.4.rdoc
- flexmock-1.1.0.rdoc
- flexmock-1.2.0.rdoc
- flexmock-1.3.0.rdoc
- flexmock-1.3.1.rdoc

### Class/Module Index

Quicksearch

- FlexMock
- FlexMock::AnyMatcher
- FlexMock::ArgumentMatching
- FlexMock::ArgumentTypes
- FlexMock::AtLeastCountValidator
- FlexMock::AtMostCountValidator
- FlexMock::CallValidator
- FlexMock::CompositeExpectation
- FlexMock::CountValidator
- FlexMock::DefaultFrameworkAdapter
- FlexMock::DefaultFrameworkAdapter::AssertionFailedError
- FlexMock::DuckMatcher
- FlexMock::EqualMatcher
- FlexMock::ExactCountValidator
- FlexMock::Expectation
- FlexMock::ExpectationBuilder
- FlexMock::ExpectationDirector
- FlexMock::ExpectationRecorder
- FlexMock::ExplicitNeeded
- FlexMock::ExtensionRegistry
- FlexMock::Extensions
- FlexMock::Extensions::ActiveRecordModel
- FlexMock::GenericTestCase
- FlexMock::HashMatcher
- FlexMock::MockBuilder
- FlexMock::MockContainer
- FlexMock::MockError
- FlexMock::OptionalProcMatcher
- FlexMock::Ordering
- FlexMock::PartialMockProxy
- FlexMock::ProcMatcher
- FlexMock::RSpecFrameworkAdapter
- FlexMock::RSpecFrameworkAdapter::AssertionFailedError
- FlexMock::RSpecMatchers
- FlexMock::RSpecMatchers::HaveReceived
- FlexMock::Recorder
- FlexMock::SpyDescribers
- FlexMock::TestCase
- FlexMock::TestUnitAssertions
- FlexMock::TestUnitFrameworkAdapter
- FlexMock::Undefined
- FlexMock::UsageError
- FlexMock::UseContainer
- FlexMock::Version
- MiniTest
- MiniTest::Unit
- MiniTest::Unit::TestCase
- Test
- Test::Unit
- Test::Unit::TestCase
- Class
- Module
- Object
- Symbol

No matching classes.

# FlexMock::ExplicitNeeded

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.

### Public Class Methods

new(expectation, method_name, base_class) click to toggle source

    # File lib/flexmock/explicit_needed.rb, line 12
    def initialize(expectation, method_name, base_class)
      @expectation = expectation
      @explicit = false
      @method_name = method_name
      @base_class = base_class
    end

### Public Instance Methods

explicit?() click to toggle source

    # File lib/flexmock/explicit_needed.rb, line 24
    def explicit?
      @explicit
    end

explicitly() click to toggle source

    # File lib/flexmock/explicit_needed.rb, line 19
    def explicitly
      @explicit = true
      self
    end

method_missing(sym, *args, &block) click to toggle source

    # File lib/flexmock/explicit_needed.rb, line 32
    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

mock=(m) click to toggle source

    # File lib/flexmock/explicit_needed.rb, line 28
    def mock=(m)
      @expectation.mock = m
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.