Module: MockSuey

Defined in:
lib/mock_suey/logging.rb,
lib/mock_suey/core.rb,
lib/mock_suey/rspec.rb,
lib/mock_suey/tracer.rb,
lib/mock_suey/version.rb,
lib/mock_suey/ext/rspec.rb,
lib/mock_suey/method_call.rb,
lib/mock_suey/type_checks.rb,
lib/mock_suey/mock_contract.rb,
lib/mock_suey/type_checks/ruby.rb,
lib/mock_suey/ext/instance_class.rb,
lib/mock_suey/rspec/mock_context.rb,
lib/mock_suey/rspec/proxy_method_invoked.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Ext, Logging, RSpec, TypeChecks Classes: Configuration, MethodCall, MockContract, Tracer

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.stored_mocked_callsObject (readonly)

Returns the value of attribute stored_mocked_calls.



81
82
83
# File 'lib/mock_suey/core.rb', line 81

def stored_mocked_calls
  @stored_mocked_calls
end

.stored_real_callsObject (readonly)

Returns the value of attribute stored_real_calls.



81
82
83
# File 'lib/mock_suey/core.rb', line 81

def stored_real_calls
  @stored_real_calls
end

.tracerObject (readonly)

Returns the value of attribute tracer.



81
82
83
# File 'lib/mock_suey/core.rb', line 81

def tracer
  @tracer
end

.type_checkerObject

Returns the value of attribute type_checker.



82
83
84
# File 'lib/mock_suey/core.rb', line 82

def type_checker
  @type_checker
end

Class Method Details

.configObject



84
# File 'lib/mock_suey/core.rb', line 84

def config = @config ||= Configuration.new

.configure {|config| ... } ⇒ Object

Yields:



86
# File 'lib/mock_suey/core.rb', line 86

def configure = yield config

.cookObject

Load extensions and start tracing if required



103
104
105
106
107
108
# File 'lib/mock_suey/core.rb', line 103

def cook
  setup_logger
  setup_type_checker
  setup_mocked_calls_collection if config.store_mocked_calls
  setup_real_calls_collection if config.trace_real_calls
end

.eatObject

Run post-suite checks



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/mock_suey/core.rb', line 111

def eat
  @stored_real_calls = tracer.stop if config.trace_real_calls

  offenses = []

  if config.store_mocked_calls
    logger.debug { "Stored mocked calls:\n#{stored_mocked_calls.map { "  #{_1.inspect}" }.join("\n")}" }
  end

  if config.trace_real_calls
    logger.debug { "Traced real calls:\n#{stored_real_calls.map { "  #{_1.inspect}" }.join("\n")}" }
  end

  if config.auto_type_check
    perform_auto_type_check(offenses)
  end

  if config.verify_mock_contracts
    perform_contracts_verification(offenses)
  end

  offenses
end

.handle_mocked_call(call_obj) ⇒ Object



94
95
96
# File 'lib/mock_suey/core.rb', line 94

def handle_mocked_call(call_obj)
  on_mocked_callbacks.each { _1.call(call_obj) }
end

.loggerObject



88
# File 'lib/mock_suey/core.rb', line 88

def logger = config.logger

.on_mocked_call(&block) ⇒ Object



90
91
92
# File 'lib/mock_suey/core.rb', line 90

def on_mocked_call(&block)
  on_mocked_callbacks << block
end

.on_mocked_callbacksObject



98
99
100
# File 'lib/mock_suey/core.rb', line 98

def on_mocked_callbacks
  @on_mocked_callbacks ||= []
end