Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (43 sloc) 1.396 kb
f61e789 @jferris Moved changes from jferris-mocha into a separate repo that monkey-patche...
jferris authored
1 require 'test/unit/testcase'
2
3 if defined?(MiniTest)
4 require 'mocha/integration/mini_test'
5 require File.expand_path('../mini_test_result', __FILE__)
6 else
7 require 'test/unit/testresult'
8 end
9
10 module TestRunner
11 def run_as_test(test_result = nil, &block)
12 test_class = Class.new(Test::Unit::TestCase) do
13 define_method(:test_me, &block)
14 end
15 test = test_class.new(:test_me)
c3cc6bd @tristandunn Remove trailing whitespace.
tristandunn authored
16
f61e789 @jferris Moved changes from jferris-mocha into a separate repo that monkey-patche...
jferris authored
17 if defined?(Test::Unit::TestResult)
18 test_result ||= Test::Unit::TestResult.new
19 test.run(test_result) {}
20 class << test_result
21 attr_reader :failures, :errors
22 def failure_messages
23 failures.map { |failure| failure.message }
24 end
50e94e9 @sikachu Now working with Ruby 1.9.x (with Minitest 2.5.x)
sikachu authored
25 def failure_message_lines
26 failure_messages.map { |message| message.split("\n") }.flatten
27 end
f61e789 @jferris Moved changes from jferris-mocha into a separate repo that monkey-patche...
jferris authored
28 def error_messages
29 errors.map { |error| error.message }
30 end
31 end
32 else
33 runner = MiniTest::Unit.new
34 test.run(runner)
35 test_result = MiniTestResult.new(runner, test)
36 end
c3cc6bd @tristandunn Remove trailing whitespace.
tristandunn authored
37
f61e789 @jferris Moved changes from jferris-mocha into a separate repo that monkey-patche...
jferris authored
38 test_result
39 end
c3cc6bd @tristandunn Remove trailing whitespace.
tristandunn authored
40
f61e789 @jferris Moved changes from jferris-mocha into a separate repo that monkey-patche...
jferris authored
41 def assert_passed(test_result)
42 flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
43 flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
44 end
45
46 def assert_failed(test_result)
47 flunk "Test passed unexpectedly" if test_result.passed?
48 end
49
50e94e9 @sikachu Now working with Ruby 1.9.x (with Minitest 2.5.x)
sikachu authored
50 end
51
Something went wrong with that request. Please try again.