Method: FlexMock.forbid_mocking

Defined in:
lib/flexmock/core_class_methods.rb

.forbid_mocking(mocking_forbidden_return = nil) ⇒ Object

Forbid mock calls to happen while the block is being evaluated

Parameters:

  • mocking_forbidden_return (Object) (defaults to: nil)

    the return value that should be used if a mocking call has happened. If no mocking calls happened, returns the return value of the block



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/flexmock/core_class_methods.rb', line 58

def forbid_mocking(mocking_forbidden_return = nil)
  current, Thread.current[FORBID_MOCKING] =
      Thread.current[FORBID_MOCKING], true

  catch(FORBID_MOCKING) do
    return yield
  end
  mocking_forbidden_return

ensure
  Thread.current[FORBID_MOCKING] = current
end