Module: Facon::Baconize::ContextExtensions

Defined in:
lib/motion-facon/baconize.rb

Overview

Mixin intended for Bacon::Context so that it runs spec_verify on all mocks after each example.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



33
34
35
36
37
38
# File 'lib/motion-facon/baconize.rb', line 33

def self.included(base)
  base.class_eval do
    alias_method :it_without_mock_verification, :it
    alias_method :it, :it_with_mock_verification
  end
end

Instance Method Details

#it_with_mock_verification(description, &block) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/motion-facon/baconize.rb', line 55

def it_with_mock_verification(description, &block)
  @before.unshift(proc { setup_facon_mocks })
  @after << proc { verify_facon_mocks }
  it_without_mock_verification(description, &block)
ensure
  teardown_facon_mocks
end

#setup_facon_mocksObject



40
41
42
# File 'lib/motion-facon/baconize.rb', line 40

def setup_facon_mocks
  $facon_mocks ||= []
end

#teardown_facon_mocksObject



48
49
50
51
52
53
# File 'lib/motion-facon/baconize.rb', line 48

def teardown_facon_mocks
  if $facon_mocks
    $facon_mocks.each { |mock| mock.spec_reset }
    $facon_mocks.clear
  end
end

#verify_facon_mocksObject



44
45
46
# File 'lib/motion-facon/baconize.rb', line 44

def verify_facon_mocks
  $facon_mocks.each { |mock| mock.spec_verify }
end