Improve wording for rails test command

This commit is contained in:
Dalibor Nasevic 2013-02-08 00:53:11 +01:00 committed by Prem Sichanugrist
parent 1a0c58b298
commit df85dfa6fa
5 changed files with 43 additions and 41 deletions

View File

@ -1,8 +1,7 @@
A Guide to Testing Rails Applications
=====================================
This guide covers built-in mechanisms offered by Rails to test your
application.
This guide covers built-in mechanisms in Rails for testing your application.
After reading this guide, you will know:
@ -234,7 +233,7 @@ Finished tests in 0.009262s, 107.9680 tests/s, 107.9680 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
```
You can also run a particular test method from the test case by running the test and use the `-n` switch with the `test method name`.
You can also run a particular test method from the test case by running the test and using `-n` switch with the `test method name`.
```bash
$ rails test test/models/post_test.rb -n test_the_truth
@ -245,7 +244,7 @@ Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
```
This will run all the test methods from the test case. Note that `test_helper.rb` is in the `test` directory, hence this directory needs to be added to the load path using the `-I` switch.
This will run all test methods from the test case. Note that `test_helper.rb` is in the `test` directory, hence this directory needs to be added to the load path using the `-I` switch.
The `.` (dot) above indicates a passing test. When a test fails you see an `F`; when a test throws an error you see an `E` in its place. The last line of the output is the summary.

View File

@ -19,7 +19,7 @@
*Terence Lee*
* Rails now generate a `test/test_helper.rb` file with `fixtures :all` commented out by default,
* Rails now generates a `test/test_helper.rb` file with `fixtures :all` commented out by default,
since we don't want to force loading all fixtures for user when a single test is run. However,
fixtures are still going to be loaded automatically for test suites.
@ -27,24 +27,27 @@
*Prem Sichanugrist*
* Add `rails test` command to run the test suite
* Add `rails test` command for running tests
To run the whole test suite:
To run all tests:
$ rails test
To run the test file(s):
$ rails test test/unit/foo_test.rb [test/unit/bar_test.rb ...]
To run the test suite
To run a test suite
$ rails test [models,helpers,units,controllers,mailers,...]
To run a selected test file(s):
$ rails test test/unit/foo_test.rb [test/unit/bar_test.rb ...]
To run a single test from a test file
$ rails test test/unit/foo_test.rb -n test_the_truth
For more information, see `rails test --help`.
This command will eventually replacing `rake test:*`, and `rake test`
command will actually invoking `rails test` instead.
This command will eventually replace `rake test:*` and `rake test` tasks
*Prem Sichanugrist and Chris Toomey*

View File

@ -2,13 +2,13 @@ require 'optparse'
require 'minitest/unit'
module Rails
# Handling the all the logic behind +rails test+ command.
# Handles all logic behind +rails test+ command.
class TestRunner
class << self
# Parse the test suite name from the arguments array and pass in a list
# of file to a new +TestRunner+ object, then invoke the evaluation. If
# the argument is not a test suite name, it will be treated as a file
# name and passed to the +TestRunner+ instance right away.
# Creates a new +TestRunner+ object with an array of test files to run
# based on the arguments. When no arguments are provided, it runs all test
# files. When a suite argument is provided, it runs only the test files in
# that suite. Otherwise, it runs the specified test file(s).
def start(files, options = {})
original_fixtures_options = options.delete(:fixtures)
options[:fixtures] = true
@ -36,18 +36,18 @@ module Rails
end
end
# Parse arguments and set them as option flags
# Parses arguments and sets them as option flags
def parse_arguments(arguments)
options = {}
orig_arguments = arguments.dup
OptionParser.new do |opts|
opts.banner = "Usage: rails test [path to test file(s) or test suite type]"
opts.banner = "Usage: rails test [path to test file(s) or test suite]"
opts.separator ""
opts.separator "Run single test file, or a test suite, under Rails'"
opts.separator "Run a specific test file(s) or a test suite, under Rails'"
opts.separator "environment. If the file name(s) or suit name is omitted,"
opts.separator "Rails will run all the test suites."
opts.separator "Rails will run all tests."
opts.separator ""
opts.separator "Specific options:"
@ -91,7 +91,7 @@ module Rails
end
end
# Create a new +TestRunner+ object with a list of test file paths.
# Creates a new +TestRunner+ object with a list of test file paths.
def initialize(files, options)
@files = files
Rake::Task['test:prepare'].invoke
@ -108,25 +108,25 @@ module Rails
MiniTest::Unit.output = SilentUntilSyncStream.new(MiniTest::Unit.output)
end
# Run the test files by evaluate each of them.
# Runs test files by evaluating each of them.
def run
@files.each { |filename| load(filename) }
end
# A null stream object which ignores everything until +sync+ has been set
# to true. This is only to be used to silence unnecessary output from
# MiniTest, as MiniTest calls +output.sync = true+ right before output the
# first test result.
# to true. This is only used to silence unnecessary output from MiniTest,
# as MiniTest calls +output.sync = true+ right before it outputs the first
# test result.
class SilentUntilSyncStream < File
# Create a +SilentUntilSyncStream+ object by given a stream object that
# this stream should set +MiniTest::Unit.output+ to after +sync+ has been
# Creates a +SilentUntilSyncStream+ object by giving it a target stream
# object that will be assigned to +MiniTest::Unit.output+ after +sync+ is
# set to true.
def initialize(target_stream)
@target_stream = target_stream
super(File::NULL, 'w')
end
# Swap +MiniTest::Unit.output+ to another stream when +sync+ is true.
# Swaps +MiniTest::Unit.output+ to another stream when +sync+ is true.
def sync=(sync)
if sync
@target_stream.sync = true

View File

@ -6,8 +6,8 @@ class ActiveSupport::TestCase
<% unless options[:skip_active_record] -%>
ActiveRecord::Migration.check_pending!
# Uncomment the `fixtures` line below to setup all fixtures in test/fixtures/*.yml for all tests
# in alphabetical order.
# Uncomment the `fixtures :all` line below to setup all fixtures in test/fixtures/*.yml
# for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting

View File

@ -141,11 +141,11 @@ module ApplicationTests
end
end
def test_run_whole_suite
types = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration]
types.each { |type| create_test_file type, "foo_#{type}" }
def test_run_all_suites
suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration]
suites.each { |suite| create_test_file suite, "foo_#{suite}" }
run_test_command('') .tap do |output|
types.each { |type| assert_match /Foo#{type.to_s.camelize}Test/, output }
suites.each { |suite| assert_match /Foo#{suite.to_s.camelize}Test/, output }
assert_match /7 tests, 7 assertions, 0 failures/, output
end
end
@ -180,13 +180,13 @@ module ApplicationTests
def test_load_fixtures_when_running_test_suites
create_model_with_fixture
types = [:models, :helpers, [:units, :unit], :controllers, :mailers,
suites = [:models, :helpers, [:units, :unit], :controllers, :mailers,
[:functionals, :functional], :integration]
types.each do |type, directory|
directory ||= type
suites.each do |suite, directory|
directory ||= suite
create_fixture_test directory
assert_match /3 users/, run_test_command(type)
assert_match /3 users/, run_test_command(suite)
Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
end
end