3

I'm using minitest for one of my projects, and I can't seem to get the Rake TestTask to actually run the files.

require 'rake'
require 'rake/testtask'

task :mytest do
  Rake::TestTask.new do |t|
    t.test_files = Dir.glob('test/model/*_test.rb')
    t.verbose = true
    puts t.inspect
    puts '-------------------------------------'
  end
end

when I run this task rake mytest, I get the following output :

projects@webdev-local:/home/projects/framework# rake mytest
#<Rake::TestTask:0x00000001775050 @name=:test, @libs=["lib"], @pattern=nil,  
@options=nil, @test_files=["test/model/page_model_test.rb", 
"test/model/widget_model_test.rb"], @verbose=true, @warning=false, @loader=:rake, 
@ruby_opts=[]>
-------------------------------------

As you can see, The task finds the files, but it never actually runs them. How can I get it to run these files?

Using Rails 3.2.8 and ruby 1.9.3

CJ.
  • 153
  • 2
  • 8

1 Answers1

1

So, two things you might want to check:

1) Make sure you're using the minitest-rails gem

It adds a lot of the test runner tasks we want and need.

https://github.com/blowmage/minitest-rails

2) The contents of your minitest_helper.rb file (a la spec_helper.rb)

You should have some kind of helper file that you're requiring in all your tests. Make sure it looks something like this:

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)

require "minitest/autorun"
require "minitest/rails"

class ActiveSupport::TestCase
  fixtures :all
end

Now that you have that setup, you can run all the tests as follows:

bundle exec rake test
bundle exec rake minitest # alias for test
bundle exec rake minitest:models

# ... etc ...
Swift
  • 13,118
  • 5
  • 56
  • 80
  • Thanks for the feedback! It caused me to go back and take a look at my gemfile, because I actually didn't have those rake tasks defined ('minitest' and 'minitest:models'). My problem actually ended up being conflicting gems, so after tidying up, everything seems to be working great. thanks again! – CJ. Jan 17 '13 at 22:25
  • Glad you got it figured out. Mini-test rails actually dynamically adds those tasks for you, so you can use them in any project. – Swift Jan 18 '13 at 16:19