提交 bef6c8bb 编写于 作者: U utilum

Stub with Minitest and test with MethodCallAssertions

上级 f2970a08
......@@ -152,10 +152,14 @@ def teardown
end
def test_establishes_connection_to_mysql_database
with_stubbed_connection_establish_connection do
ActiveRecord::Base.expects(:establish_connection).with @configuration
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
ActiveRecord::Base.stub(:connection, @connection) do
assert_called_with(
ActiveRecord::Base,
:establish_connection,
[@configuration]
) do
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
end
end
end
......@@ -196,10 +200,14 @@ def setup
end
def test_establishes_connection_to_the_appropriate_database
with_stubbed_connection_establish_connection do
ActiveRecord::Base.expects(:establish_connection).with(@configuration)
ActiveRecord::Tasks::DatabaseTasks.purge @configuration
ActiveRecord::Base.stub(:connection, @connection) do
assert_called_with(
ActiveRecord::Base,
:establish_connection,
[@configuration]
) do
ActiveRecord::Tasks::DatabaseTasks.purge @configuration
end
end
end
......
......@@ -166,12 +166,17 @@ def teardown
def test_establishes_connection_to_postgresql_database
ActiveRecord::Base.stub(:connection, @connection) do
ActiveRecord::Base.expects(:establish_connection).with(
"adapter" => "postgresql",
"database" => "postgres",
"schema_search_path" => "public"
)
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
assert_called_with(
ActiveRecord::Base,
:establish_connection,
[
"adapter" => "postgresql",
"database" => "postgres",
"schema_search_path" => "public"
]
) do
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
end
end
end
......
......@@ -47,9 +47,9 @@ def test_db_create_when_file_exists
def test_db_create_with_file_does_nothing
File.stub(:exist?, true) do
ActiveRecord::Base.expects(:establish_connection).never
ActiveRecord::Tasks::DatabaseTasks.create @configuration, "/rails/root"
assert_not_called(ActiveRecord::Base, :establish_connection) do
ActiveRecord::Tasks::DatabaseTasks.create @configuration, "/rails/root"
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册