-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary Mocha stubs #33309
Remove unnecessary Mocha stubs #33309
Conversation
r? @schneems (@rails-bot has picked a reviewer for you, use r? to override) |
I also found few unnecessary Mocha stubs on the current branch. diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index 6cddfaefeb..d39122d9ef 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -77,7 +77,6 @@ def test_create_when_database_exists_outputs_info_to_stderr
class MysqlDBCreateWithInvalidPermissionsTest < ActiveRecord::TestCase
def setup
- @connection = stub("Connection", create_database: true)
@error = Mysql2::Error.new("Invalid permissions")
@configuration = {
"adapter" => "mysql2",
@@ -86,7 +85,6 @@ def setup
"password" => "wossname"
}
- ActiveRecord::Base.stubs(:connection).returns(@connection)
ActiveRecord::Base.stubs(:establish_connection).raises(@error)
$stdout, @original_stdout = StringIO.new, $stdout
diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb
index 6be929d1af..2f41f6a556 100644
--- a/activerecord/test/cases/tasks/postgresql_rake_test.rb
+++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -141,7 +141,6 @@ def setup
}
ActiveRecord::Base.stubs(:connection).returns(@connection)
- ActiveRecord::Base.stubs(:clear_active_connections!).returns(true)
ActiveRecord::Base.stubs(:establish_connection).returns(true)
end
@@ -219,7 +218,6 @@ def test_db_retrieves_collation
class PostgreSQLStructureDumpTest < ActiveRecord::TestCase
def setup
- @connection = stub(schema_search_path: nil, structure_dump: true)
@configuration = {
"adapter" => "postgresql",
"database" => "my-app-db"
@@ -355,7 +353,6 @@ def with_structure_dump_flags(flags)
class PostgreSQLStructureLoadTest < ActiveRecord::TestCase
def setup
- @connection = stub
@configuration = {
"adapter" => "postgresql",
"database" => "my-app-db"
diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb
index 0594e304e3..c9e7badf76 100644
--- a/activerecord/test/cases/tasks/sqlite_rake_test.rb
+++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb
@@ -45,8 +45,6 @@ def test_db_create_when_file_exists
end
def test_db_create_with_file_does_nothing
- File.stubs(:exist?).returns(true)
-
ActiveRecord::Base.expects(:establish_connection).never
ActiveRecord::Tasks::DatabaseTasks.create @configuration, "/rails/root" |
87fa1f6
to
80d257a
Compare
Looks good! Thank you. |
Why are these stubs not needed? Were they never needed? Can you elaborate a bit about how you found out they weren't needed in your commit message? Thanks for working on this, both of you! |
Step 1 in rails#33162 [utilum + bogdanvlviv]
80d257a
to
8c1e172
Compare
Following @bogdanvlviv 's additional deletions, I rescanned the code and found several more such cases. Just pushed. |
Remove returning of `false` value for stubbed `lock_thread=` methods since there aren't any needs in it. Remove unnecessary returning of `true` for stubbed `drop_database` method. Follow up rails#33309. Related to rails#33162, rails#33326.
Should have been removed in rails#33309.
Step 1 in #33162
While modifying tests to replace use of Mocha it became evident that some calls to
Mocha#stub
andMocha#stubs
do not have any impact on the test case. The same is true of some calls toreturns
on such objects. This patch removes both.I speculate that the setup for one test was sometimes copied from onto another without verifying necessity. Tracing each of these instances to its origins and determining the moment it became unnecessary is fascinating, but a lot of work.
For example,
@connection = stub("Connection", create_database: true)
was introduced six years ago as part of quite a refactoring. I'd need a whole new stack to verify it was necessary at the time, and it's gone through several changes since.So I did not complete the historical research.