Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8242bcfa
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,发现更多精彩内容 >>
提交
8242bcfa
编写于
11月 17, 2015
作者:
Y
yuuji.yaginuma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add `bin/test` script to rails plugin
上级
9d7d12c0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
153 addition
and
7 deletion
+153
-7
railties/CHANGELOG.md
railties/CHANGELOG.md
+6
-0
railties/lib/rails/generators/rails/plugin/plugin_generator.rb
...ies/lib/rails/generators/rails/plugin/plugin_generator.rb
+2
-3
railties/lib/rails/generators/rails/plugin/templates/bin/test.tt
...s/lib/rails/generators/rails/plugin/templates/bin/test.tt
+8
-0
railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb
...ils/generators/rails/plugin/templates/test/test_helper.rb
+4
-0
railties/lib/rails/test_unit/minitest_plugin.rb
railties/lib/rails/test_unit/minitest_plugin.rb
+4
-3
railties/test/generators/plugin_generator_test.rb
railties/test/generators/plugin_generator_test.rb
+6
-1
railties/test/generators/plugin_test_runner_test.rb
railties/test/generators/plugin_test_runner_test.rb
+123
-0
未找到文件。
railties/CHANGELOG.md
浏览文件 @
8242bcfa
*
Add
`bin/test`
script to rails plugin.
`bin/test` can use the same API as `bin/rails test`.
*Yuji Yaginuma*
*
Make
`static_index`
part of the
`config.public_file_server`
config and
call it
`public_file_server.index_name`
.
...
...
railties/lib/rails/generators/rails/plugin/plugin_generator.rb
浏览文件 @
8242bcfa
...
...
@@ -148,9 +148,8 @@ def javascripts
end
def
bin
(
force
=
false
)
return
unless
engine?
directory
"bin"
,
force:
force
do
|
content
|
bin_file
=
engine?
?
'bin/rails.tt'
:
'bin/test.tt'
template
bin_file
,
force:
force
do
|
content
|
"
#{
shebang
}
\n
"
+
content
end
chmod
"bin"
,
0755
,
verbose:
false
...
...
railties/lib/rails/generators/rails/plugin/templates/bin/test.tt
0 → 100644
浏览文件 @
8242bcfa
$: << File.expand_path(File.expand_path('../../test', __FILE__))
require 'bundler/setup'
require 'rails/test_unit/minitest_plugin'
Rails::TestUnitReporter.executable = 'bin/test'
exit Minitest.run(ARGV)
railties/lib/rails/generators/rails/plugin/templates/test/test_helper.rb
浏览文件 @
8242bcfa
...
...
@@ -14,6 +14,10 @@
# to be shown.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
<% unless engine? -%>
Rails::TestUnitReporter.executable = 'bin/test'
<% end -%>
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("
..
/fixtures", __FILE__)
...
...
railties/lib/rails/test_unit/minitest_plugin.rb
浏览文件 @
8242bcfa
...
...
@@ -14,15 +14,16 @@ def aggregated_results
SummaryReporter
.
prepend
AggregatedResultSuppresion
def
self
.
plugin_rails_options
(
opts
,
options
)
executable
=
Rails
::
TestUnitReporter
.
executable
opts
.
separator
""
opts
.
separator
"Usage:
bin/rails test
[options] [files or directories]"
opts
.
separator
"Usage:
#{
executable
}
[options] [files or directories]"
opts
.
separator
"You can run a single test by appending a line number to a filename:"
opts
.
separator
""
opts
.
separator
"
bin/rails test
test/models/user_test.rb:27"
opts
.
separator
"
#{
executable
}
test/models/user_test.rb:27"
opts
.
separator
""
opts
.
separator
"You can run multiple files and directories at the same time:"
opts
.
separator
""
opts
.
separator
"
bin/rails test
test/controllers test/integration/login_test.rb"
opts
.
separator
"
#{
executable
}
test/controllers test/integration/login_test.rb"
opts
.
separator
""
opts
.
separator
"By default test failures and errors are reported inline during a run."
opts
.
separator
""
...
...
railties/test/generators/plugin_generator_test.rb
浏览文件 @
8242bcfa
...
...
@@ -65,8 +65,11 @@ def test_generating_without_options
assert_match
(
/require.+test\/dummy\/config\/environment/
,
content
)
assert_match
(
/ActiveRecord::Migrator\.migrations_paths.+test\/dummy\/db\/migrate/
,
content
)
assert_match
(
/Minitest\.backtrace_filter = Minitest::BacktraceFilter\.new/
,
content
)
assert_match
(
/Rails::TestUnitReporter\.executable = 'bin\/test'/
,
content
)
end
assert_file
"test/bukkits_test.rb"
,
/assert_kind_of Module, Bukkits/
assert_file
'bin/test'
assert_no_file
'bin/rails'
end
def
test_generating_test_files_in_full_mode
...
...
@@ -223,7 +226,7 @@ def test_ensure_that_tests_work
run_generator
FileUtils
.
cd
destination_root
quietly
{
system
'bundle install'
}
assert_match
(
/1 runs, 1 assertions, 0 failures, 0 errors/
,
`b
undle exec rake
test 2>&1`
)
assert_match
(
/1 runs, 1 assertions, 0 failures, 0 errors/
,
`b
in/
test 2>&1`
)
end
def
test_ensure_that_tests_works_in_full_mode
...
...
@@ -315,7 +318,9 @@ def test_create_mountable_application_with_mountable_option
assert_match
(
/ActiveRecord::Migrator\.migrations_paths.+\.\.\/test\/dummy\/db\/migrate/
,
content
)
assert_match
(
/ActiveRecord::Migrator\.migrations_paths.+<<.+\.\.\/db\/migrate/
,
content
)
assert_match
(
/ActionDispatch::IntegrationTest\.fixture_path = ActiveSupport::TestCase\.fixture_pat/
,
content
)
assert_no_match
(
/Rails::TestUnitReporter\.executable = 'bin\/test'/
,
content
)
end
assert_no_file
'bin/test'
end
def
test_create_mountable_application_with_mountable_option_and_hypenated_name
...
...
railties/test/generators/plugin_test_runner_test.rb
0 → 100644
浏览文件 @
8242bcfa
require
'tmpdir'
require
'abstract_unit'
class
PluginTestRunnerTest
<
ActiveSupport
::
TestCase
def
setup
@destination_root
=
Dir
.
mktmpdir
(
'bukkits'
)
Dir
.
chdir
(
@destination_root
)
{
`bundle exec rails plugin new bukkits --skip-bundle`
}
plugin_file
'test/dummy/db/schema.rb'
,
''
end
def
teardown
FileUtils
.
rm_rf
(
@destination_root
)
end
def
test_run_single_file
create_test_file
'foo'
create_test_file
'bar'
assert_match
"1 runs, 1 assertions, 0 failures"
,
run_test_command
(
"test/foo_test.rb"
)
end
def
test_run_multiple_files
create_test_file
'foo'
create_test_file
'bar'
assert_match
"2 runs, 2 assertions, 0 failures"
,
run_test_command
(
"test/foo_test.rb test/bar_test.rb"
)
end
def
test_mix_files_and_line_filters
create_test_file
'account'
plugin_file
'test/post_test.rb'
,
<<-
RUBY
require 'test_helper'
class PostTest < ActiveSupport::TestCase
def test_post
puts 'PostTest'
assert true
end
def test_line_filter_does_not_run_this
assert true
end
end
RUBY
run_test_command
(
'test/account_test.rb test/post_test.rb:4'
).
tap
do
|
output
|
assert_match
'AccountTest'
,
output
assert_match
'PostTest'
,
output
assert_match
'2 runs, 2 assertions'
,
output
end
end
def
test_multiple_line_filters
create_test_file
'account'
create_test_file
'post'
run_test_command
(
'test/account_test.rb:4 test/post_test.rb:4'
).
tap
do
|
output
|
assert_match
'AccountTest'
,
output
assert_match
'PostTest'
,
output
end
end
def
test_line_filter_without_line_runs_all_tests
create_test_file
'account'
run_test_command
(
'test/account_test.rb:'
).
tap
do
|
output
|
assert_match
'AccountTest'
,
output
end
end
def
test_output_inline_by_default
create_test_file
'post'
,
pass:
false
output
=
run_test_command
(
'test/post_test.rb'
)
assert_match
%r{Running:
\n\n
PostTest
\n
F
\n\n
wups!
\n\n
bin/test
#{
plugin_path
}
/test/post_test.rb:6}
,
output
end
def
test_only_inline_failure_output
create_test_file
'post'
,
pass:
false
output
=
run_test_command
(
'test/post_test.rb'
)
assert_match
%r{Finished in.*
\n\n
1 runs, 1 assertions}
,
output
end
def
test_fail_fast
create_test_file
'post'
,
pass:
false
assert_match
(
/Interrupt/
,
capture
(
:stderr
)
{
run_test_command
(
'test/post_test.rb --fail-fast'
)
})
end
def
test_raise_error_when_specified_file_does_not_exist
error
=
capture
(
:stderr
)
{
run_test_command
(
'test/not_exists.rb'
)
}
assert_match
(
%r{cannot load such file.+test/not_exists
\.
rb}
,
error
)
end
private
def
plugin_path
"
#{
@destination_root
}
/bukkits"
end
def
run_test_command
(
arguments
)
Dir
.
chdir
(
plugin_path
)
{
`bin/test
#{
arguments
}
`
}
end
def
create_test_file
(
name
,
pass:
true
)
plugin_file
"test/
#{
name
}
_test.rb"
,
<<-
RUBY
require 'test_helper'
class
#{
name
.
camelize
}
Test < ActiveSupport::TestCase
def test_truth
puts "
#{
name
.
camelize
}
Test"
assert
#{
pass
}
, 'wups!'
end
end
RUBY
end
def
plugin_file
(
path
,
contents
,
mode:
'w'
)
FileUtils
.
mkdir_p
File
.
dirname
(
"
#{
plugin_path
}
/
#{
path
}
"
)
File
.
open
(
"
#{
plugin_path
}
/
#{
path
}
"
,
mode
)
do
|
f
|
f
.
puts
contents
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录