module Mocha::Integration::TestUnit::Adapter

Integrates Mocha into recent versions of Test::Unit.

See the source code for an example of how to integrate Mocha into a test library.

Public Class Methods

applicable_to?(test_unit_version, _ruby_version = nil) click to toggle source

@private

# File lib/mocha/integration/test_unit/adapter.rb, line 15
def self.applicable_to?(test_unit_version, _ruby_version = nil)
  Gem::Requirement.new('>= 2.5.1').satisfied_by?(test_unit_version)
end
description() click to toggle source

@private

# File lib/mocha/integration/test_unit/adapter.rb, line 20
def self.description
  'adapter for Test::Unit gem >= v2.5.1'
end
included(mod) click to toggle source

@private

# File lib/mocha/integration/test_unit/adapter.rb, line 25
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 Instance Methods

handle_mocha_expectation_error(exception) click to toggle source

@private

# File lib/mocha/integration/test_unit/adapter.rb, line 41
def handle_mocha_expectation_error(exception)
  return false unless exception.is_a?(Mocha::ExpectationError)
  problem_occurred
  add_failure(exception.message, exception.backtrace)
  true
end