I have a MiniTest suite. I'm using the basic Minitest::Unit::TestCase, not specs. I have setup and teardown methods defined in my TestCase subclass. They work perfectly when I run a test file like so: ruby test/whatever_test.rb. But when I run rake test, setup and teardown are not called. The relevant portion of my Rakefile is:
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = FileList['test/*_test.rb']
t.verbose = true
end
Why wouldn't the setup and teardown be run when Rake::TestTask is used?
I'd paste the test case code into here, but there's quite a lot of it. I'll certainly paste in some subset of it, if there's a particular section you'd like to see.
I'm running Minitest 4.3.2 on Ruby 1.9.3-p194.
The problem was that another test case was overwriting the setup and teardown methods. I had accidentally given two test cases the same class name, which is why the overwriting happened. Naturally, this error didn't happen when I ran a single test case, which explains the difference in behavior when using Rake.
In my case, I was writing tests for socket communication and had added a helper method named send. Since MiniTest uses send internally to call the teardown methods, it was instead calling my own send instead of the method-dispatch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With