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.
This commit is contained in:
Daniel Uber 2022-04-05 14:21:23 -05:00 committed by GitHub
parent bd980c3dd7
commit 76470febb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -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

View file

@ -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