From 0d843a6e937c71448d5991bfd4c7584fe3b386c3 Mon Sep 17 00:00:00 2001 From: James Mead Date: Thu, 27 Jul 2023 14:33:13 +0100 Subject: [PATCH] Use Mocha vs Minitest Mock in inviting users test The use of MiniTest::Mock in this test was causing a problem when trying to upgrade to Minitest v5.19.0, because we should be using the newer Minitest module name. I could have just changed that here, but it seemed odd that we're using Minitest mocking & stubbing in this one test, while in every other test we're using Mocha. So I decided to convert this test to use Mocha too. I'm pretty confident that we don't need to "expect" the calls to the code & body methods on the response since their values are read and asserted against in the assert_response_contains call, so using stubbed return values is sufficient. I think these changes also make the test easier to read. --- test/integration/inviting_users_test.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/integration/inviting_users_test.rb b/test/integration/inviting_users_test.rb index 9bf227b85..7514278a9 100644 --- a/test/integration/inviting_users_test.rb +++ b/test/integration/inviting_users_test.rb @@ -346,22 +346,16 @@ class InvitingUsersTest < ActionDispatch::IntegrationTest end should "raise an error if email address is not in Notify team" do - raises_exception = lambda do |_request, _params| - response = MiniTest::Mock.new - response.expect :code, 400 - response.expect :body, "Can't send to this recipient using a team-only API key" - raise Notifications::Client::BadRequestError, response - end + response = stub("response", code: 400, body: "Can't send to this recipient using a team-only API key") + User.stubs(:invite!).raises(Notifications::Client::BadRequestError, response) - User.stub(:invite!, raises_exception) do - perform_enqueued_jobs do - visit new_user_invitation_path - fill_in "Name", with: "Fred Bloggs" - fill_in "Email", with: "fred@example.com" - click_button "Create user and send email" + perform_enqueued_jobs do + visit new_user_invitation_path + fill_in "Name", with: "Fred Bloggs" + fill_in "Email", with: "fred@example.com" + click_button "Create user and send email" - assert_response_contains "Error: One or more recipients not in GOV.UK Notify team (code: 400)" - end + assert_response_contains "Error: One or more recipients not in GOV.UK Notify team (code: 400)" end end end