Sha256: f4fd7d2144745b2b3c3343b4d83453d95f46cfb19e5027d51df6d5569212b7b3

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

require 'mocha/api'
require 'mocha/integration/assertion_counter'
require 'mocha/expectation_error'

module Mocha
  module Integration
    module TestUnit
      # Integrates Mocha into recent versions of Test::Unit.
      #
      # 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?(test_unit_version)
          Gem::Requirement.new('>= 2.5.1').satisfied_by?(test_unit_version)
        end

        # @private
        def self.description
          'adapter for Test::Unit gem >= v2.5.1'
        end

        # @private
        def self.included(mod)
          mod.setup :mocha_setup, before: :prepend

          mod.exception_handler(:handle_mocha_expectation_error)

          mod.cleanup after: :append do
            assertion_counter = Integration::AssertionCounter.new(self)
            mocha_verify(assertion_counter)
          end

          mod.teardown :mocha_teardown, after: :append
        end

        private

        # @private
        def handle_mocha_expectation_error(exception)
          return false unless exception.is_a?(Mocha::ExpectationError)
          problem_occurred
          add_failure(exception.message, exception.backtrace)
          true
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mocha-2.1.0 lib/mocha/integration/test_unit/adapter.rb
mocha-2.0.4 lib/mocha/integration/test_unit/adapter.rb
mocha-2.0.3 lib/mocha/integration/test_unit/adapter.rb