File: adapter.rb

package info (click to toggle)
ruby-mocha 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,388 kB
  • ctags: 2,008
  • sloc: ruby: 10,919; makefile: 12
file content (54 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'mocha/api'
require 'mocha/integration/assertion_counter'
require 'mocha/expectation_error_factory'

module Mocha
  module Integration
    module MiniTest

      # Integrates Mocha into recent versions of MiniTest.
      #
      # See the source code for an example of how to integrate Mocha into a test library.
      module Adapter
        include Mocha::API

        # @private
        def self.applicable_to?(mini_test_version)
          Gem::Requirement.new('>= 3.3.0').satisfied_by?(mini_test_version)
        end

        # @private
        def self.description
          "adapter for MiniTest gem >= v3.3.0"
        end

        # @private
        def self.included(mod)
          Mocha::ExpectationErrorFactory.exception_class = ::MiniTest::Assertion
        end

        # @private
        def before_setup
          mocha_setup
          super
        end

        # @private
        def before_teardown
          return unless passed?
          assertion_counter = Integration::AssertionCounter.new(self)
          mocha_verify(assertion_counter)
        ensure
          super
        end

        # @private
        def after_teardown
          super
          mocha_teardown
        end
      end
    end
  end
end