Skip to content

Commit

Permalink
Add error specs for BodyWrapper close method
Browse files Browse the repository at this point in the history
I noticed I broke something earlier while writing the previous commit in
the close method, but it didn't fail any specs. That's because there
weren't any for the error reporting. Add these errors so we can be sure
it works.
  • Loading branch information
tombruijn committed Sep 12, 2024
1 parent 9c2f761 commit eb4511c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions spec/lib/appsignal/rack/body_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,43 @@

expect(transaction).to include_event("name" => "close_response_body.rack")
end

it "reports an error if an error occurs on close" do
fake_body = double
expect(fake_body).to receive(:close).and_raise(ExampleException, "error message")

wrapped = described_class.wrap(fake_body, transaction)
expect do
wrapped.close
end.to raise_error(ExampleException, "error message")

expect(transaction).to have_error("ExampleException", "error message")
end

it "doesn't report EPIPE error on close" do
fake_body = double
expect(fake_body).to receive(:close).and_raise(Errno::EPIPE)

wrapped = described_class.wrap(fake_body, transaction)
expect do
wrapped.close
end.to raise_error(Errno::EPIPE)

expect(transaction).to_not have_error
end

it "does not report EPIPE error when it's the error cause on close" do
error = error_with_cause(StandardError, "error message", Errno::EPIPE)
fake_body = double
expect(fake_body).to receive(:close).and_raise(error)

wrapped = described_class.wrap(fake_body, transaction)
expect do
wrapped.close
end.to raise_error(StandardError, "error message")

expect(transaction).to_not have_error
end
end

describe "with a body supporting both each() and call" do
Expand Down

0 comments on commit eb4511c

Please sign in to comment.