Class: Shoe::Tasks::Test

Inherits:
Task
  • Object
show all
Defined in:
lib/shoe/tasks/test.rb

Overview

Defines `rake test` to run your tests.

Uses testrb to run your test_files.

To enable and configure, edit the test_files[http://docs.rubygems.org/read/chapter/20#test_files] in your gemspec.

(You may also want to add a .gemtest file to the root of your gem, so that others can run your tests via rubygems-test.)

A Few Precautions

  • Using testrb means that only Test::Unit (all Rubies) and MiniTest::Unit (Ruby 1.9) tests will be run.

  • You’ll need to Bundler.setup(:default, :development) in your Rakefile so that testrb can find your code.

  • Your test_files need only contain actual tests – support files, like test_helper, need not be included.

  • The LOAD_PATH will contain all of the immediate parent directories of your test_files. You should not count on the top-level project directory being included – in other words, "require 'test/test_helper'" may not work, and "require 'test_helper'" will only work if test_helper is a sibling of one of your test_files.

For further clarification on these guidelines, you may find it helpful to browse Shoe’s own test setup.

Instance Attribute Summary

Attributes inherited from Task

#spec

Instance Method Summary collapse

Methods inherited from Task

#initialize

Constructor Details

This class inherits a constructor from Shoe::Tasks::Task

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/shoe/tasks/test.rb', line 38

def active?
  !spec.test_files.empty?
end

#defineObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shoe/tasks/test.rb', line 42

def define
  desc <<-END.gsub(/^ */, '')
    Run tests.
    Configure via the `test_files` field in #{spec.name}.gemspec.
  END

  task :test do
    system 'testrb', *spec.test_files
  end

  task :prepare

  task :test => :prepare

  task :default
  Rake.application[:default].prerequisites.unshift(Rake.application[:test])
end