Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d1a35c35
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,发现更多精彩内容 >>
提交
d1a35c35
编写于
9月 23, 2015
作者:
R
Ronak Jangir
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed Mocha from app generators tests
上级
f860ab3f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
106 addition
and
87 deletion
+106
-87
railties/test/generators/app_generator_test.rb
railties/test/generators/app_generator_test.rb
+106
-87
未找到文件。
railties/test/generators/app_generator_test.rb
浏览文件 @
d1a35c35
require
'generators/generators_test_helper'
require
'rails/generators/rails/app/app_generator'
require
'generators/shared_generator_tests'
require
'mocha/setup'
# FIXME: stop using mocha
DEFAULT_APP_FILES
=
%w(
.gitignore
...
...
@@ -117,35 +116,33 @@ def test_application_name_is_detected_if_it_exists_and_app_folder_renamed
run_generator
[
app_root
]
Rails
.
application
.
config
.
root
=
app_moved_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
stub_rails_application
(
app_moved_root
)
do
Rails
.
application
.
stub
(
:is_a?
,
->
*
args
{
Rails
::
Application
})
do
FileUtils
.
mv
(
app_root
,
app_moved_root
)
FileUtils
.
mv
(
app_root
,
app_moved_root
)
# make sure we are in correct dir
FileUtils
.
cd
(
app_moved_root
)
# make sure we are in correct dir
FileUtils
.
cd
(
app_moved_root
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_moved_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"myapp_moved/config/environment.rb"
,
/Rails\.application\.initialize!/
assert_file
"myapp_moved/config/initializers/session_store.rb"
,
/_myapp_session/
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_moved_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"myapp_moved/config/environment.rb"
,
/Rails\.application\.initialize!/
assert_file
"myapp_moved/config/initializers/session_store.rb"
,
/_myapp_session/
end
end
end
def
test_rails_update_generates_correct_session_key
app_root
=
File
.
join
(
destination_root
,
'myapp'
)
run_generator
[
app_root
]
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"myapp/config/initializers/session_store.rb"
,
/_myapp_session/
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"myapp/config/initializers/session_store.rb"
,
/_myapp_session/
end
end
def
test_new_application_use_json_serialzier
...
...
@@ -158,14 +155,12 @@ def test_rails_update_keep_the_cookie_serializer_if_it_is_already_configured
app_root
=
File
.
join
(
destination_root
,
'myapp'
)
run_generator
[
app_root
]
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
(
"
#{
app_root
}
/config/initializers/cookies_serializer.rb"
,
/Rails\.application\.config\.action_dispatch\.cookies_serializer = :json/
)
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
(
"
#{
app_root
}
/config/initializers/cookies_serializer.rb"
,
/Rails\.application\.config\.action_dispatch\.cookies_serializer = :json/
)
end
end
def
test_rails_update_does_not_create_callback_terminator_initializer
...
...
@@ -174,14 +169,12 @@ def test_rails_update_does_not_create_callback_terminator_initializer
FileUtils
.
rm
(
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
)
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_no_file
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_no_file
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
end
end
def
test_rails_update_does_not_remove_callback_terminator_initializer_if_already_present
...
...
@@ -190,14 +183,12 @@ def test_rails_update_does_not_remove_callback_terminator_initializer_if_already
FileUtils
.
touch
(
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
)
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"
#{
app_root
}
/config/initializers/callback_terminator.rb"
end
end
def
test_rails_update_set_the_cookie_serializer_to_marchal_if_it_is_not_already_configured
...
...
@@ -206,14 +197,12 @@ def test_rails_update_set_the_cookie_serializer_to_marchal_if_it_is_not_already_
FileUtils
.
rm
(
"
#{
app_root
}
/config/initializers/cookies_serializer.rb"
)
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
(
"
#{
app_root
}
/config/initializers/cookies_serializer.rb"
,
/Rails\.application\.config\.action_dispatch\.cookies_serializer = :marshal/
)
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
(
"
#{
app_root
}
/config/initializers/cookies_serializer.rb"
,
/Rails\.application\.config\.action_dispatch\.cookies_serializer = :marshal/
)
end
end
def
test_rails_update_does_not_create_active_record_belongs_to_required_by_default
...
...
@@ -222,14 +211,12 @@ def test_rails_update_does_not_create_active_record_belongs_to_required_by_defau
FileUtils
.
rm
(
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
)
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_no_file
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_no_file
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
end
end
def
test_rails_update_does_not_remove_active_record_belongs_to_required_by_default_if_already_present
...
...
@@ -238,14 +225,12 @@ def test_rails_update_does_not_remove_active_record_belongs_to_required_by_defau
FileUtils
.
touch
(
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
)
Rails
.
application
.
config
.
root
=
app_root
Rails
.
application
.
class
.
stubs
(
:name
).
returns
(
"Myapp"
)
Rails
.
application
.
stubs
(
:is_a?
).
returns
(
Rails
::
Application
)
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
stub_rails_application
(
app_root
)
do
generator
=
Rails
::
Generators
::
AppGenerator
.
new
[
"rails"
],
{
with_dispatchers:
true
},
destination_root:
app_root
,
shell:
@shell
generator
.
send
(
:app_const
)
quietly
{
generator
.
send
(
:update_config_files
)
}
assert_file
"
#{
app_root
}
/config/initializers/active_record_belongs_to_required_by_default.rb"
end
end
def
test_application_names_are_not_singularized
...
...
@@ -456,13 +441,15 @@ def test_template_from_dir_pwd
end
def
test_usage_read_from_file
File
.
expects
(
:read
).
returns
(
"USAGE FROM FILE"
)
assert_equal
"USAGE FROM FILE"
,
Rails
::
Generators
::
AppGenerator
.
desc
assert_called
(
File
,
:read
,
returns:
"USAGE FROM FILE"
)
do
assert_equal
"USAGE FROM FILE"
,
Rails
::
Generators
::
AppGenerator
.
desc
end
end
def
test_default_usage
Rails
::
Generators
::
AppGenerator
.
expects
(
:usage_path
).
returns
(
nil
)
assert_match
(
/Create rails files for app generator/
,
Rails
::
Generators
::
AppGenerator
.
desc
)
assert_called
(
Rails
::
Generators
::
AppGenerator
,
:usage_path
,
returns:
nil
)
do
assert_match
(
/Create rails files for app generator/
,
Rails
::
Generators
::
AppGenerator
.
desc
)
end
end
def
test_default_namespace
...
...
@@ -538,18 +525,31 @@ def test_spring
def
test_spring_binstubs
jruby_skip
"spring doesn't run on JRuby"
generator
.
stubs
(
:bundle_command
).
with
(
'install'
)
generator
.
expects
(
:bundle_command
).
with
(
'exec spring binstub --all'
).
once
quietly
{
generator
.
invoke_all
}
command_check
=
->
command
do
@binstub_called
||=
0
case
command
when
'install'
# Called when running bundle, we just want to stub it so nothing to do here.
when
'exec spring binstub --all'
@binstub_called
+=
1
assert_equal
1
,
@binstub_called
,
"exec spring binstub --all expected to be called once, but was called
#{
@install_called
}
times."
end
end
generator
.
stub
:bundle_command
,
command_check
do
quietly
{
generator
.
invoke_all
}
end
end
def
test_spring_no_fork
jruby_skip
"spring doesn't run on JRuby"
Process
.
stubs
(
:respond_to?
).
with
(
:fork
).
returns
(
false
)
run_generator
assert_called_with
(
Process
,
:respond_to?
,
[
:fork
],
returns:
false
)
do
run_generator
assert_file
"Gemfile"
do
|
content
|
assert_no_match
(
/spring/
,
content
)
assert_file
"Gemfile"
do
|
content
|
assert_no_match
(
/spring/
,
content
)
end
end
end
...
...
@@ -651,18 +651,37 @@ def test_after_bundle_callback
template
=
%{ after_bundle { run 'echo ran after_bundle' } }
template
.
instance_eval
"def read; self; end"
# Make the string respond to read
generator
([
destination_root
],
template:
path
).
expects
(
:open
).
with
(
path
,
'Accept'
=>
'application/x-thor-template'
).
returns
(
template
)
check_open
=
->
*
args
do
assert_equal
[
path
,
'Accept'
=>
'application/x-thor-template'
],
args
template
end
bundler_first
=
sequence
(
'bundle, binstubs, after_bundle'
)
generator
.
expects
(
:bundle_command
).
with
(
'install'
).
once
.
in_sequence
(
bundler_first
)
generator
.
expects
(
:bundle_command
).
with
(
'exec spring binstub --all'
).
in_sequence
(
bundler_first
)
generator
.
expects
(
:run
).
with
(
'echo ran after_bundle'
).
in_sequence
(
bundler_first
)
sequence
=
[
'install'
,
'exec spring binstub --all'
,
'echo ran after_bundle'
]
ensure_bundler_first
=
->
command
do
@sequence_step
||=
0
quietly
{
generator
.
invoke_all
}
assert_equal
sequence
[
@sequence_step
],
command
,
"commands should be called in sequence
#{
sequence
}
"
@sequence_step
+=
1
end
generator
([
destination_root
],
template:
path
).
stub
(
:open
,
check_open
,
template
)
do
generator
.
stub
(
:bundle_command
,
ensure_bundler_first
)
do
generator
.
stub
(
:run
,
ensure_bundler_first
)
do
quietly
{
generator
.
invoke_all
}
end
end
end
end
protected
def
stub_rails_application
(
root
)
Rails
.
application
.
config
.
root
=
root
Rails
.
application
.
class
.
stub
(
:name
,
"Myapp"
)
do
yield
end
end
def
action
(
*
args
,
&
block
)
capture
(
:stdout
)
{
generator
.
send
(
*
args
,
&
block
)
}
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录