Skip to content

Commit 6d47f99

Browse files
simonbairdclaude
andcommitted
Remove minitest/mock
IIUC this is going away in minitest 6.0. We're only using it in a few places, so let's try to replace those with the equivalent mocha style stubbing. Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent 6eb3d05 commit 6d47f99

4 files changed

Lines changed: 18 additions & 25 deletions

File tree

rails/test/integration/claim_sites_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'test_helper'
2-
require 'minitest/mock'
32

43
class ClaimSitesTest < CapybaraIntegrationTest
54
setup do

rails/test/models/settings_test.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ def self.quux_enabled?(_user) = false
2828
end
2929
end
3030

31-
def with_mocked_grant_feature_data(user_list, &)
32-
stubbed = lambda do |*args|
33-
assert_equal args, [:grant_feature, :foo_bar]
34-
user_list
35-
end
36-
37-
Settings.stub(:secrets, stubbed, &)
31+
def with_mocked_grant_feature_data(user_list)
32+
Settings.stubs(:secrets).with(:grant_feature, :foo_bar).returns(user_list)
33+
yield
34+
Settings.unstub(:secrets)
3835
end
3936

4037
test 'manually granted feature access' do

rails/test/models/site_test.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,24 @@ def setup_some_saved_versions
296296
end
297297

298298
# Main blob is missing, but no non-missing other blob was found
299-
WithSavedContent.stub(:blob_exists_in_storage?, ->(_blob) { false }) do
300-
assert_raises(RuntimeError, "No good blob found!") do
301-
@site.reload.restore_missing_main_blob!
302-
end
299+
WithSavedContent.stubs(:blob_exists_in_storage?).returns(false)
300+
assert_raises(RuntimeError, "No good blob found!") do
301+
@site.reload.restore_missing_main_blob!
303302
end
303+
WithSavedContent.unstub(:blob_exists_in_storage?)
304304

305305
# Main blob missing, and there is an non-missing older blob available
306-
WithSavedContent.stub(:blob_exists_in_storage?, ->(blob) { blob.id == old_blob.id }) do
307-
@site.reload.restore_missing_main_blob!
306+
# Set up general stub first, then specific stub for old_blob
307+
WithSavedContent.stubs(:blob_exists_in_storage?).returns(false)
308+
WithSavedContent.stubs(:blob_exists_in_storage?).with(old_blob).returns(true)
308309

309-
# Should have created a new version with the older content
310-
assert_equal 3, @site.reload.saved_content_files.count
311-
assert_equal 'older version', @site.file_download
312-
end
310+
@site.reload.restore_missing_main_blob!
311+
312+
# Should have created a new version with the older content
313+
assert_equal 3, @site.reload.saved_content_files.count
314+
assert_equal 'older version', @site.file_download
315+
316+
WithSavedContent.unstub(:blob_exists_in_storage?)
313317
end
314318

315319
test 'tagging basic functionality' do

rails/test/test_helper.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
require 'capybara/rails'
1111
require 'capybara/minitest'
12-
require 'minitest/mock'
1312
require 'mocha/minitest'
1413

1514
# Load test support modules
@@ -77,12 +76,6 @@ class ActionDispatch::IntegrationTest
7776
setup do
7877
host! Settings.url_defaults[:host]
7978
end
80-
81-
def mock_helper
82-
mock = Minitest::Mock.new
83-
yield mock if block_given?
84-
mock
85-
end
8679
end
8780

8881
class CapybaraIntegrationTest < ActionDispatch::IntegrationTest

0 commit comments

Comments
 (0)