Class: FlexMock::MockBuilder

### Home Classes Methods

### In Files

- lib/flexmock/mock_builder.rb

### Parent

Object

### Methods

- ::new
- #create_double
- #define_a_mock
- #flexmock_mock_setup
- #parse_creation_args
- #run_post_creation_hooks

### 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::MockBuilder

This class contains helper methods for mock containers. Since MockContainer is a module that is designed to be mixed into other classes, (particularly testing framework test cases), we don't want to pollute the method namespace of the class that mixes in MockContainer. So we have aggressively moved a number of MockContainer methods out of that class and into MockBuilder to isoloate the names.

### Constants

FlexOpts

### Public Class Methods

new(container) click to toggle source

    # File lib/flexmock/mock_builder.rb, line 12
    def initialize(container)
      @container = container
    end

### Public Instance Methods

create_double(opts) click to toggle source

Create the test double based on the args options.

    # File lib/flexmock/mock_builder.rb, line 62
    def create_double(opts)
      if opts.extended
        result = opts.extended.create(container, opts)
      elsif opts.domain_obj
        result = create_partial(opts)
      else
        result = create_mock(opts)
      end
      opts.mock ||= result
      result
    end

define_a_mock(location, *args, &block) click to toggle source

    # File lib/flexmock/mock_builder.rb, line 16
    def define_a_mock(location, *args, &block)
      opts = parse_creation_args(args)
      if opts.safe_mode && ! block_given?
        raise UsageError, "a block is required in safe mode"
      end

      result = create_double(opts)
      flexmock_mock_setup(opts.mock, opts, location, &block)
      run_post_creation_hooks(opts, location)
      result
    end

flexmock_mock_setup(mock, opts, location) click to toggle source

Setup the test double with its expections and such.

    # File lib/flexmock/mock_builder.rb, line 83
    def flexmock_mock_setup(mock, opts, location)
      mock.flexmock_based_on(opts.base_class) if opts.base_class
      mock.flexmock_define_expectation(location, opts.defs)
      yield(mock) if block_given?
      container.flexmock_remember(mock)
    end

parse_creation_args(args) click to toggle source

Parse the list of flexmock() arguments and populate the opts object.

    # File lib/flexmock/mock_builder.rb, line 39
    def parse_creation_args(args)
      opts = FlexOpts.new
      while ! args.empty?
        case args.first
        when Symbol
          unless parse_create_symbol(args, opts)
            opts.name = args.shift.to_s
          end
        when String, Symbol
          opts.name = args.shift.to_s
        when Hash
          opts.defs = args.shift
        when FlexMock
          opts.mock = args.shift
        else
          opts.domain_obj = args.shift
        end
      end
      set_base_class(opts)
      opts
    end

run_post_creation_hooks(opts, location) click to toggle source

Run any post creation hooks specified by an extension.

    # File lib/flexmock/mock_builder.rb, line 75
    def run_post_creation_hooks(opts, location)
      if opts.extended
        opts.extended.post_create(opts, location)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.