Minitest Adapter #62

Merged
merged 2 commits into from Jun 25, 2011
View
@@ -84,6 +84,7 @@
require "#{dir}/rr/adapters/rspec"
require "#{dir}/rr/adapters/test_unit"
+require "#{dir}/rr/adapters/minitest"
module RR
class << self
@@ -0,0 +1,31 @@
+module RR
+ module Adapters
+ module MiniTest
+ include RRMethods
+ def self.included(mod)
+ RR.trim_backtrace = true
+ mod.class_eval do
+ unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
+ alias_method :setup_without_rr, :setup
+ def setup_with_rr
+ setup_without_rr
+ RR.reset
+ end
+ alias_method :setup, :setup_with_rr
+
+ alias_method :teardown_without_rr, :teardown
+ def teardown_with_rr
+ RR.verify
+ teardown_without_rr
+ end
+ alias_method :teardown, :teardown_with_rr
+ end
+ end
+ end
+
+ def assert_received(subject, &block)
+ block.call(received(subject)).call
+ end
+ end
+ end
+end
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,21 @@
+require "rubygems"
+require "spec"
+
+class MiniTestTestSuite
+ def run
+ require_tests
+
+ puts "Running MiniTest Test Suite"
+ end
+
+ def require_tests
+ dir = File.dirname(__FILE__)
+ Dir["#{dir}/rr/minitest/**/*_test.rb"].each do |file|
+ require File.expand_path(file)
+ end
+ end
+end
+
+if $0 == __FILE__
+ MiniTestTestSuite.new.run
+end
@@ -0,0 +1,59 @@
+require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
+
+class MiniTestIntegrationTest < MiniTest::Unit::TestCase
+ include RR::Adapters::MiniTest # Testing against double inclusion issues
+
+ def setup
+ super
+ @subject = Object.new
+ end
+
+ def teardown
+ super
+ end
+
+ def test_using_a_mock
+ mock(@subject).foobar(1, 2) {:baz}
+ assert_equal :baz, @subject.foobar(1, 2)
+ end
+
+ def test_using_a_stub
+ stub(@subject).foobar {:baz}
+ assert_equal :baz, @subject.foobar("any", "thing")
+ end
+
+ def test_using_a_mock_proxy
+ def @subject.foobar
+ :baz
+ end
+
+ mock.proxy(@subject).foobar
+ assert_equal :baz, @subject.foobar
+ end
+
+ def test_using_a_stub_proxy
+ def @subject.foobar
+ :baz
+ end
+
+ stub.proxy(@subject).foobar
+ assert_equal :baz, @subject.foobar
+ end
+
+ def test_times_called_verification
+ mock(@subject).foobar(1, 2) {:baz}
+ assert_raises RR::Errors::TimesCalledError do
+ teardown
+ end
+ end
+
+ def test_using_assert_received
+ stub(@subject).foobar(1, 2)
+ @subject.foobar(1, 2)
+ assert_received(@subject) {|subject| subject.foobar(1, 2)}
+
+ assert_raises RR::Errors::SpyVerificationErrors::InvocationCountError do
+ assert_received(@subject) {|subject| subject.foobar(1, 2, 3)}
+ end
+ end
+end
@@ -0,0 +1,7 @@
+require File.expand_path("#{File.dirname(__FILE__)}/../../environment_fixture_setup")
+
+require "minitest/autorun"
+
+class MiniTest::Unit::TestCase
+ include RR::Adapters::MiniTest
+end
View
@@ -12,6 +12,7 @@ def run
run_core_examples
run_rspec_examples
run_test_unit_examples
+ run_minitest_examples
end
def run_core_examples
@@ -26,6 +27,10 @@ def run_test_unit_examples
run_suite("#{dir}/test_unit_spec_suite.rb") || raise("Test::Unit suite Failed")
end
+ def run_minitest_examples
+ run_suite("#{dir}/minitest_spec_suite.rb") || raise("MiniTest suite Failed")
+ end
+
def run_suite(path)
# From http://www.eglug.org/node/946
bash.execute "exec 3>&1", :out => STDOUT, :err => STDERR
@@ -46,4 +51,4 @@ def dir
if $0 == __FILE__
ExampleSuite.new.run
-end
+end