Module: Facon::Baconize::ContextExtensions

Defined in:
lib/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/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



53
54
55
56
57
58
59
# File 'lib/facon/baconize.rb', line 53

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/facon/baconize.rb', line 40

def setup_facon_mocks
  $facon_mocks ||= []
end

#teardown_facon_mocksObject



48
49
50
51
# File 'lib/facon/baconize.rb', line 48

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

#verify_facon_mocksObject



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

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