Skip to content

Commit

Permalink
Use Mocha vs Minitest Mock in inviting users test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
floehopper committed Jul 27, 2023
1 parent 0e6ae51 commit 0d843a6
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions test/integration/inviting_users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]"
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: "[email protected]"
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
Expand Down

0 comments on commit 0d843a6

Please sign in to comment.