9

Is there a standard help command for individual rake tasks?

rake -h displays the options for rake.

rake -D describes the rake tasks.

rake mytask runs mytask.

Is there something like rake -h mytask that would describe mytask, and list its optional and/or required arguments?

For example, the following code will run an individual test in rails:

rake test TEST=path_to_test

How do I discover that TEST=path_to_test is an optional argument to rake test?

user1385729
  • 1,276
  • 1
  • 15
  • 19

3 Answers3

5

The command rake -D test does not on my system. Instead you can use

# list test command with details
rake test -D 

# list all test tasks with description
rake test -T

# list all test tasks even without description(Recommened)
rake test -T -A
Billy Chan
  • 24,625
  • 4
  • 52
  • 68
1

The -D accepts a pattern. So you can use that.

Examples:

rake -D db

rake -D db:migrate
HungryCoder
  • 7,506
  • 1
  • 38
  • 51
  • 1
    Thanks, adding the pattern with `rake -D test` doesn't seem to list any arguments. It does work by listing two options for the example given `rake -D db:migrate`, but maybe there is another way that will work for both examples? – user1385729 Mar 28 '13 at 05:41
0

TEST=path_to_test is setting an environment variable. So if rake -D test doesn't give you any information on how environment variables are being used in the rake task, then you have to resort to looking at the source code or alternative documentation. And looking at the source code, there are only two environment variables being checked in Rails rake test: TEST and TESTOPTS, the latter is used in Minitest that is packaged with Ruby and used in Rails testing.

Documentation in Rails gives an example: rake test TEST=path/to/test.rb TESTOPTS="--name=test_something"

Other options include --color and --fail-fast (Reference: https://github.com/rails/rails/blob/df74da026b9210a9cb6258e7029cafcc02aa6d15/guides/source/testing.md)

(I've added this answer for anyone in the future looking into this, like me.)

Alternatively, you can run the test outside of rake. Not sure if that makes it faster.

For example, running "explicit class layout" test in MailLayoutTest can be done by: ruby -Itest test/mail_layout_test.rb -n test_explicit_class_layout

(Reference: https://github.com/rails/rails/blob/2f1fefe456932a6d7d2b155d27b5315c33f3daa1/guides/source/contributing_to_ruby_on_rails.md)

James
  • 659
  • 1
  • 5
  • 15