diff options
author | utilum <oz@utilum.com> | 2018-06-20 02:32:12 +0200 |
---|---|---|
committer | utilum <oz@utilum.com> | 2018-07-09 21:41:29 +0200 |
commit | 331cca17587f2ef23d69a5288a93d6444da2c980 (patch) | |
tree | c80120bd2f5fc0507ef889fabb00584acab27ed8 /activerecord/test/cases | |
parent | 2cc514a74a293d175904c08fd74b8a037d8959e2 (diff) | |
download | rails-331cca17587f2ef23d69a5288a93d6444da2c980.tar.gz rails-331cca17587f2ef23d69a5288a93d6444da2c980.tar.bz2 rails-331cca17587f2ef23d69a5288a93d6444da2c980.zip |
Reduce mocking by testing value instead of method call
Step 2 in #33162
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/tasks/database_tasks_test.rb | 32 | ||||
-rw-r--r-- | activerecord/test/cases/tasks/postgresql_rake_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/tasks/sqlite_rake_test.rb | 5 |
3 files changed, 24 insertions, 18 deletions
diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb index a6f684a137..159590a810 100644 --- a/activerecord/test/cases/tasks/database_tasks_test.rb +++ b/activerecord/test/cases/tasks/database_tasks_test.rb @@ -123,6 +123,13 @@ module ActiveRecord 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 @@ module ActiveRecord 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 @@ module ActiveRecord @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 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb index bdce1cbd20..d2474ba786 100644 --- a/activerecord/test/cases/tasks/postgresql_rake_test.rb +++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb @@ -66,11 +66,8 @@ if current_adapter?(:PostgreSQLAdapter) 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 diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb index 7b4cb51c56..f1edae43f4 100644 --- a/activerecord/test/cases/tasks/sqlite_rake_test.rb +++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb @@ -61,11 +61,8 @@ if current_adapter?(:SQLite3Adapter) 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 |