From 76470febb7c2f4d9ee682363960951eec620a0ba Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Tue, 5 Apr 2022 14:21:23 -0500 Subject: [PATCH] Expect to raise error should use a block (#17131) * Expect to raise error should use a block This is kind of pedantic, since we _had_ been using a lambda, and calling as a value. Now explicitly call the proc in a block and expect the block to raise error. * Replace lambda with block Replace lambda passed as a value to an implicit block with a block. --- spec/requests/admin/reactions_spec.rb | 2 +- spec/services/analytics_service_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/requests/admin/reactions_spec.rb b/spec/requests/admin/reactions_spec.rb index d278e1172..43b157238 100644 --- a/spec/requests/admin/reactions_spec.rb +++ b/spec/requests/admin/reactions_spec.rb @@ -62,7 +62,7 @@ RSpec.describe "/admin/reactions", type: :request do put admin_reaction_path(reaction.id), params: { id: reaction.id, status: "confirmed" } end - expect(invalid_request).to raise_error(Pundit::NotAuthorizedError) + expect { invalid_request.call }.to raise_error(Pundit::NotAuthorizedError) end end end diff --git a/spec/services/analytics_service_spec.rb b/spec/services/analytics_service_spec.rb index c703eb023..a99aaae43 100644 --- a/spec/services/analytics_service_spec.rb +++ b/spec/services/analytics_service_spec.rb @@ -27,17 +27,17 @@ RSpec.describe AnalyticsService, type: :service do describe "initialization" do it "raises an error if start date is invalid" do - expect(-> { described_class.new(user, start_date: "2000-") }).to raise_error(ArgumentError) + expect { described_class.new(user, start_date: "2000-") }.to raise_error(ArgumentError) end it "raises an error if end date is invalid" do - expect(-> { described_class.new(user, end_date: "2000-") }).to raise_error(ArgumentError) + expect { described_class.new(user, end_date: "2000-") }.to raise_error(ArgumentError) end it "raises an error if an article does not belong to the user" do other_user = create(:user) article = create(:article, user: other_user) - expect(-> { described_class.new(user, article_id: article.id) }).to raise_error(ArgumentError) + expect { described_class.new(user, article_id: article.id) }.to raise_error(ArgumentError) end end