views:

217

answers:

3

rake test ANYTHING seems to not help

P.S. The question is about rails itself, not rails app.

A: 

If you want to run a single test, you can just run them as a regular Ruby script

ruby actionmailer/test/mail_layout_test.rb

You can also run a whole suite (eg. ActiveRecord or ActionMailer) by cd-ing into the directory and running rake test inside there.

Aupajo
Not in Rails -- at least not with the default test files generated. They have "require 'test_helper'" on the first line, but the load path won't have been set up in time. If you change every first line to an explicit require ("require File.join(File.dirname(__FILE__), '..', 'test_helper')"), then your solution works.
James A. Rosen
ahem, that's `require File.join(File.dirname(__FILE__), '..', 'test_helper')`
James A. Rosen
@Gaius Double-checked. First one doesn't work, but `cd`-ing in does. Just to be clear (I'm not sure if I'm mis-reading this, but you did say "generated test files"), this is for the Rails library itself, *not* a Rails project.
Aupajo
+2  A: 

To run a single test, use the following command from your rails project's main directory:

ruby -I test test/unit/my_model_test.rb -n test_name

This runs a single test named "name", defined in the MyModelTest class in the specified file. The test_name is formed by taking the test name, prepending it with the word "test", then separating the words with underscores. For example:

class MyModelTest < ActiveSupport::TestCase

  test "valid with good attributes" do
    # do whatever you do
  end

  test "invalid with bad attributes" do
    # do whatever you do
  end
end

You can run both tests via:

ruby -I test test/unit/my_model_test.rb

and just the second test via

ruby -I test test/unit/my_model_test.rb -n test_invalid_with_bad_attributes
Darryl
A: 

That was a silly midnight question of mine. Rails kindly prints the command it is executing upon rake test. The rest is a cut and paste exercise.

~/projects/rails/actionpack (my2.3.4)$ ruby -I"lib:test" "/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/controller/base_test.rb"
artemave