Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a4f16d93
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,发现更多精彩内容 >>
未验证
提交
a4f16d93
编写于
7月 09, 2018
作者:
R
Rafael França
提交者:
GitHub
7月 09, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33322 from utilum/test_value_instead_of_method_call
Reduce mocking by testing value instead of method call
上级
2cc514a7
331cca17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
18 deletion
+24
-18
activerecord/test/cases/tasks/database_tasks_test.rb
activerecord/test/cases/tasks/database_tasks_test.rb
+22
-10
activerecord/test/cases/tasks/postgresql_rake_test.rb
activerecord/test/cases/tasks/postgresql_rake_test.rb
+1
-4
activerecord/test/cases/tasks/sqlite_rake_test.rb
activerecord/test/cases/tasks/sqlite_rake_test.rb
+1
-4
未找到文件。
activerecord/test/cases/tasks/database_tasks_test.rb
浏览文件 @
a4f16d93
...
...
@@ -123,6 +123,13 @@ def setup
ActiveRecord
::
Base
.
stubs
(
:configurations
).
returns
(
@configurations
)
# To refrain from connecting to a newly created empty DB in sqlite3_mem tests
ActiveRecord
::
Base
.
connection_handler
.
stubs
(
:establish_connection
)
$stdout
,
@original_stdout
=
StringIO
.
new
,
$stdout
$stderr
,
@original_stderr
=
StringIO
.
new
,
$stderr
end
def
teardown
$stdout
,
$stderr
=
@original_stdout
,
@original_stderr
end
def
test_ignores_configurations_without_databases
...
...
@@ -145,9 +152,10 @@ def test_ignores_remote_databases
def
test_warning_for_remote_databases
@configurations
[
"development"
].
merge!
(
"host"
=>
"my.server.tld"
)
assert_called_with
(
$stderr
,
:puts
,
[
"This task only modifies local databases. my-db is on a remote host."
])
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_all
end
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create_all
assert_match
"This task only modifies local databases. my-db is on a remote host."
,
$stderr
.
string
end
def
test_creates_configurations_with_local_ip
...
...
@@ -345,6 +353,13 @@ def setup
@configurations
=
{
development:
{
"database"
=>
"my-db"
}
}
ActiveRecord
::
Base
.
stubs
(
:configurations
).
returns
(
@configurations
)
$stdout
,
@original_stdout
=
StringIO
.
new
,
$stdout
$stderr
,
@original_stderr
=
StringIO
.
new
,
$stderr
end
def
teardown
$stdout
,
$stderr
=
@original_stdout
,
@original_stderr
end
def
test_ignores_configurations_without_databases
...
...
@@ -367,13 +382,10 @@ def test_ignores_remote_databases
def
test_warning_for_remote_databases
@configurations
[
:development
].
merge!
(
"host"
=>
"my.server.tld"
)
assert_called_with
(
$stderr
,
:puts
,
[
"This task only modifies local databases. my-db is on a remote host."
],
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_all
end
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop_all
assert_match
"This task only modifies local databases. my-db is on a remote host."
,
$stderr
.
string
end
def
test_drops_configurations_with_local_ip
...
...
activerecord/test/cases/tasks/postgresql_rake_test.rb
浏览文件 @
a4f16d93
...
...
@@ -66,11 +66,8 @@ def test_establishes_connection_to_new_database
def
test_db_create_with_error_prints_message
ActiveRecord
::
Base
.
stubs
(
:establish_connection
).
raises
(
Exception
)
$stderr
.
stubs
(
:puts
)
$stderr
.
expects
(
:puts
).
with
(
"Couldn't create database for
#{
@configuration
.
inspect
}
"
)
assert_raises
(
Exception
)
{
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
}
assert_match
"Couldn't create database for
#{
@configuration
.
inspect
}
"
,
$stderr
.
string
end
def
test_when_database_created_successfully_outputs_info_to_stdout
...
...
activerecord/test/cases/tasks/sqlite_rake_test.rb
浏览文件 @
a4f16d93
...
...
@@ -61,11 +61,8 @@ def test_db_create_establishes_a_connection
def
test_db_create_with_error_prints_message
ActiveRecord
::
Base
.
stubs
(
:establish_connection
).
raises
(
Exception
)
$stderr
.
stubs
(
:puts
).
returns
(
true
)
$stderr
.
expects
(
:puts
).
with
(
"Couldn't create database for
#{
@configuration
.
inspect
}
"
)
assert_raises
(
Exception
)
{
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
,
"/rails/root"
}
assert_match
"Couldn't create database for
#{
@configuration
.
inspect
}
"
,
$stderr
.
string
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录