Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c7a148f3
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7a148f3
编写于
4月 05, 2013
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removing `rails test`, updating docs to show how to use `rake test`
上级
3844bb5e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
19 addition
and
194 deletion
+19
-194
guides/source/testing.md
guides/source/testing.md
+14
-14
railties/CHANGELOG.md
railties/CHANGELOG.md
+5
-19
railties/lib/rails/commands.rb
railties/lib/rails/commands.rb
+0
-9
railties/lib/rails/commands/test_runner.rb
railties/lib/rails/commands/test_runner.rb
+0
-146
railties/test/application/test_runner_test.rb
railties/test/application/test_runner_test.rb
+0
-6
未找到文件。
guides/source/testing.md
浏览文件 @
c7a148f3
...
...
@@ -222,10 +222,10 @@ TIP: You can see all these rake tasks and their descriptions by running `rake --
### Running Tests
Running a test is as simple as invoking the file containing the test cases through
`ra
ils
test`
command.
Running a test is as simple as invoking the file containing the test cases through
`ra
ke
test`
command.
```
bash
$
ra
ils
test test
/models/post_test.rb
$
ra
ke
test test
/models/post_test.rb
.
Finished tests
in
0.009262s, 107.9680 tests/s, 107.9680 assertions/s.
...
...
@@ -236,7 +236,7 @@ Finished tests in 0.009262s, 107.9680 tests/s, 107.9680 assertions/s.
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
$
ra
ils
test test
/models/post_test.rb
-n
test_the_truth
$
ra
ke
test test
/models/post_test.rb
TESTOPTS
=
'-n test_the_truth'
.
Finished tests
in
0.009064s, 110.3266 tests/s, 110.3266 assertions/s.
...
...
@@ -260,7 +260,7 @@ end
Let us run this newly added test.
```
bash
$
ra
ils
test test
/models/post_test.rb
-n
test_should_not_save_post_without_title
$
ra
ke
test test
/models/post_test.rb
TESTOPTS
=
'-n test_should_not_save_post_without_title'
F
Finished tests
in
0.044632s, 22.4054 tests/s, 22.4054 assertions/s.
...
...
@@ -300,7 +300,7 @@ end
Now the test should pass. Let us verify by running the test again:
```
bash
$
ra
ils
test test
/models/post_test.rb
-n
test_should_not_save_post_without_title
$
ra
ke
test test
/models/post_test.rb
TESTOPTS
=
'-n test_should_not_save_post_without_title'
.
Finished tests
in
0.047721s, 20.9551 tests/s, 20.9551 assertions/s.
...
...
@@ -325,7 +325,7 @@ end
Now you can see even more output in the console from running the tests:
```
bash
$
ra
ils
test test
/models/post_test.rb
-n
test_should_report_error
$
ra
ke
test test
/models/post_test.rb
TESTOPTS
=
'-n test_should_report_error'
E
Finished tests
in
0.030974s, 32.2851 tests/s, 0.0000 assertions/s.
...
...
@@ -761,14 +761,14 @@ You don't need to set up and run your tests by hand on a test-by-test basis. Rai
| Tasks | Description |
| ------------------------ | ----------- |
|
`ra
ils test`
| Runs all unit, functional and integration tests. You can also simply run
`rails
test`
as Rails will run all the tests by default|
|
`ra
ils test
controllers`
| Runs all the controller tests from
`test/controllers`
|
|
`ra
ils test
functionals`
| Runs all the functional tests from
`test/controllers`
,
`test/mailers`
, and
`test/functional`
|
|
`ra
ils test
helpers`
| Runs all the helper tests from
`test/helpers`
|
|
`ra
ils test
integration`
| Runs all the integration tests from
`test/integration`
|
|
`ra
ils test
mailers`
| Runs all the mailer tests from
`test/mailers`
|
|
`ra
ils test
models`
| Runs all the model tests from
`test/models`
|
|
`ra
ils test
units`
| Runs all the unit tests from
`test/models`
,
`test/helpers`
, and
`test/unit`
|
|
`ra
ke test`
| Runs all unit, functional and integration tests. You can also simply run
`rake
test`
as Rails will run all the tests by default|
|
`ra
ke test:
controllers`
| Runs all the controller tests from
`test/controllers`
|
|
`ra
ke test:
functionals`
| Runs all the functional tests from
`test/controllers`
,
`test/mailers`
, and
`test/functional`
|
|
`ra
ke test:
helpers`
| Runs all the helper tests from
`test/helpers`
|
|
`ra
ke test:
integration`
| Runs all the integration tests from
`test/integration`
|
|
`ra
ke test:
mailers`
| Runs all the mailer tests from
`test/mailers`
|
|
`ra
ke test:
models`
| Runs all the model tests from
`test/models`
|
|
`ra
ke test:
units`
| Runs all the unit tests from
`test/models`
,
`test/helpers`
, and
`test/unit`
|
There're also some test commands which you can initiate by running rake tasks:
...
...
railties/CHANGELOG.md
浏览文件 @
c7a148f3
...
...
@@ -38,37 +38,23 @@
*Sam Ruby*
*
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.
To force all fixtures to be create in your database, use `rails test -f` to run your test.
*Prem Sichanugrist*
*
Add
`rails test`
command for running tests
*
Improved
`rake test`
command for running tests
To run all tests:
$ ra
ils
test
$ ra
ke
test
To run a test suite
$ ra
ils test
[models,helpers,units,controllers,mailers,...]
$ ra
ke test:
[models,helpers,units,controllers,mailers,...]
To run a selected test file(s):
$ ra
ils
test test/unit/foo_test.rb [test/unit/bar_test.rb ...]
$ ra
ke
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 replace `rake test:*` and `rake test` tasks.
*Prem Sichanugrist and Chris Toomey*
$ rake test test/unit/foo_test.rb TESTOPTS='-n test_the_truth'
*
Improve service pages with new layout (404, etc).
...
...
railties/lib/rails/commands.rb
浏览文件 @
c7a148f3
...
...
@@ -80,15 +80,6 @@
server
.
start
end
when
'test'
$LOAD_PATH
.
unshift
(
"./test"
)
require
'rails/commands/test_runner'
options
=
Rails
::
TestRunner
.
parse_arguments
(
ARGV
)
ENV
[
'RAILS_ENV'
]
||=
options
[
:environment
]
||
'test'
require
APP_PATH
Rails
::
TestRunner
.
start
(
ARGV
,
options
)
when
'dbconsole'
require
'rails/commands/dbconsole'
Rails
::
DBConsole
.
start
...
...
railties/lib/rails/commands/test_runner.rb
已删除
100644 → 0
浏览文件 @
3844bb5e
require
'optparse'
require
'minitest/unit'
module
Rails
# Handles all logic behind +rails test+ command.
class
TestRunner
class
<<
self
# 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
case
files
.
first
when
nil
new
(
Dir
[
'test/**/*_test.rb'
],
options
).
run
when
'models'
new
(
Dir
[
'test/models/**/*_test.rb'
],
options
).
run
when
'helpers'
new
(
Dir
[
'test/helpers/**/*_test.rb'
],
options
).
run
when
'units'
new
(
Dir
[
'test/{models,helpers,unit}/**/*_test.rb'
],
options
).
run
when
'controllers'
new
(
Dir
[
'test/controllers/**/*_test.rb'
],
options
).
run
when
'mailers'
new
(
Dir
[
'test/mailers/**/*_test.rb'
],
options
).
run
when
'functionals'
new
(
Dir
[
'test/{controllers,mailers,functional}/**/*_test.rb'
],
options
).
run
when
'integration'
new
(
Dir
[
'test/integration/**/*_test.rb'
],
options
).
run
else
options
[
:fixtures
]
=
original_fixtures_options
new
(
files
,
options
).
run
end
end
# 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]"
opts
.
separator
""
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 tests."
opts
.
separator
""
opts
.
separator
"Specific options:"
opts
.
on
'-h'
,
'--help'
,
'Display this help.'
do
puts
opts
exit
end
opts
.
on
'-e'
,
'--environment NAME'
,
String
,
'Specifies the environment to run this test under'
do
|
e
|
options
[
:environment
]
=
e
end
opts
.
on
'-f'
,
'--fixtures'
,
'Load fixtures in test/fixtures/ before running the tests'
do
options
[
:fixtures
]
=
true
end
opts
.
on
'-s'
,
'--seed SEED'
,
Integer
,
"Sets random seed"
do
|
m
|
options
[
:seed
]
=
m
.
to_i
end
opts
.
on
'-v'
,
'--verbose'
,
"Verbose. Show progress processing files."
do
options
[
:verbose
]
=
true
end
opts
.
on
'-n'
,
'--name PATTERN'
,
"Filter test names on pattern (e.g. /foo/)"
do
|
n
|
options
[
:filter
]
=
n
end
opts
.
separator
""
opts
.
separator
"Support types of test suites:"
opts
.
separator
"-------------------------------------------------------------"
opts
.
separator
"* models (test/models/**/*)"
opts
.
separator
"* helpers (test/helpers/**/*)"
opts
.
separator
"* units (test/{models,helpers,unit}/**/*"
opts
.
separator
"* controllers (test/controllers/**/*)"
opts
.
separator
"* mailers (test/mailers/**/*)"
opts
.
separator
"* functionals (test/{controllers,mailers,functional}/**/*)"
opts
.
separator
"* integration (test/integration/**/*)"
opts
.
separator
"-------------------------------------------------------------"
opts
.
parse!
arguments
orig_arguments
-=
arguments
end
options
end
end
# Creates a new +TestRunner+ object with a list of test file paths.
def
initialize
(
files
,
options
)
@files
=
files
Rails
.
application
.
load_tasks
Rake
::
Task
[
'db:test:load'
].
invoke
if
options
.
delete
(
:fixtures
)
if
defined?
(
ActiveRecord
::
Base
)
ActiveSupport
::
TestCase
.
send
:include
,
ActiveRecord
::
TestFixtures
ActiveSupport
::
TestCase
.
fixture_path
=
"
#{
Rails
.
root
}
/test/fixtures/"
ActiveSupport
::
TestCase
.
fixtures
:all
end
end
MiniTest
::
Unit
.
runner
.
options
=
options
MiniTest
::
Unit
.
output
=
SilentUntilSyncStream
.
new
(
MiniTest
::
Unit
.
output
)
end
# 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 used to silence unnecessary output from MiniTest,
# as MiniTest calls +output.sync = true+ right before it outputs the first
# test result.
class
SilentUntilSyncStream
<
File
# 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
# Swaps +MiniTest::Unit.output+ to another stream when +sync+ is true.
def
sync
=
(
sync
)
if
sync
@target_stream
.
sync
=
true
MiniTest
::
Unit
.
output
=
@target_stream
end
super
end
end
end
end
railties/test/application/test_runner_test.rb
浏览文件 @
c7a148f3
...
...
@@ -29,12 +29,6 @@ def test_env
assert_match
"Current Environment: test"
,
run_test_command
(
'test/unit/env_test.rb'
)
end
def
test_run_shortcut
create_test_file
:models
,
'foo'
output
=
Dir
.
chdir
(
app_path
)
{
`bundle exec rails t test/models/foo_test.rb`
}
assert_match
"1 tests, 1 assertions, 0 failures"
,
output
end
def
test_run_single_file
create_test_file
:models
,
'foo'
create_test_file
:models
,
'bar'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录