Rake doesn't know how to build tasks: default or minitest

michaelmichael picture michaelmichael · Dec 27, 2012 · Viewed 16.2k times · Source

I built a gem a while back and did not include any tests (shame on me). I've since attempted to redress this by including minitest, but I'm getting stuck right out of the gate with the following error:

Don't know how to build task 'default'

Here's my Rakefile

require 'rake/testtask'

Rake::TestTask.new do |t|
  t.test_files = FileList['test/*_test.rb']
end

And the dummy file in test/unit_test.rb

require 'minitest/autorun'

class TestPackage < MiniTest::Unit::TestCase

  def test
    assert_equal 10, Array.new(10).size
  end
end

If I change the Rakefile to include task :default => 'minitest' the error message changes to Don't know how to build task 'minitest'

rake --trace seems to just direct me back to the parts of the Rake gem that handle task invocation. No clues that I can see:

~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/task_manager.rb:49:in `[]'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:115:in `invoke_task'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:94:in `each'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/rake/application.rb:63:in `run'
~/.rbenv/versions/1.9.3-p286/bin/rake:32:in `<main>'

Answer

Casper picture Casper · Dec 27, 2012

Rake tasks are always named. The Rake::TestTask task is named test, so if you run rake test it will run your tests.

To make Rake::TestTask your default task just include:

task :default => :test

in your Rakefile.

http://rake.rubyforge.org/Rake/TestTask.html