Skip to content

Commit

Permalink
Group test cases base on prod/dev setup
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Dec 25, 2020
1 parent 8dbbc83 commit db3dc57
Showing 1 changed file with 76 additions and 34 deletions.
110 changes: 76 additions & 34 deletions sentry-rails/spec/sentry/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,104 @@
end

it "inserts middleware to a correct position" do
expect(Rails.application.middleware.find_index(Sentry::Rails::CaptureExceptions)).to eq(0)
app = Rails.application
expect(app.middleware.find_index(Sentry::Rails::CaptureExceptions)).to eq(0)
expect(app.middleware.find_index(Sentry::Rails::RescuedExceptionInterceptor)).to eq(app.middleware.count - 1)
end

it "doesn't do anything on a normal route" do
get "/"
context "with development config" do
before do
make_basic_app do |config, app|
app.config.consider_all_requests_local = true
config.rails.report_rescued_exceptions = report_rescued_exceptions
end
end

expect(response.status).to eq(200)
expect(transport.events.size).to eq(0)
end
context "with report_rescued_exceptions = true" do
let(:report_rescued_exceptions) { true }

it "excludes commonly seen exceptions (like RecordNotFound)" do
get "/not_found"
it "captures exceptions" do
get "/exception"

expect(response.status).to eq(400)
expect(transport.events).to be_empty
end
expect(response.status).to eq(500)

it "captures exceptions" do
get "/exception"
expect(event["exception"]["values"][0]["type"]).to eq("RuntimeError")
expect(event["exception"]["values"][0]["value"]).to eq("An unhandled exception!")
end
end

context "with report_rescued_exceptions = false" do
let(:report_rescued_exceptions) { false }

expect(response.status).to eq(500)
it "doesn't report rescued exceptions" do
get "/exception"

expect(event["exception"]["values"][0]["type"]).to eq("RuntimeError")
expect(event["exception"]["values"][0]["value"]).to eq("An unhandled exception!")
expect(transport.events.count).to eq(0)
end
end
end

it "filters exception backtrace with custom BacktraceCleaner" do
get "/view_exception"
context "with production config" do
before do
make_basic_app do |config, app|
app.config.consider_all_requests_local = false
end
end

traces = event.dig("exception", "values", 0, "stacktrace", "frames")
expect(traces.dig(-1, "filename")).to eq("inline template")
it "doesn't do anything on a normal route" do
get "/"

# we want to avoid something like "_inline_template__3014794444104730113_10960"
expect(traces.dig(-1, "function")).to be_nil
end
expect(response.status).to eq(200)
expect(transport.events.size).to eq(0)
end

it "excludes commonly seen exceptions (like RecordNotFound)" do
get "/not_found"

expect(response.status).to eq(400)
expect(transport.events).to be_empty
end

it "captures exceptions" do
get "/exception"

it "doesn't filters exception backtrace if backtrace_cleanup_callback is overridden" do
original_cleanup_callback = Sentry.configuration.backtrace_cleanup_callback
expect(response.status).to eq(500)

begin
Sentry.configuration.backtrace_cleanup_callback = nil
expect(event["exception"]["values"][0]["type"]).to eq("RuntimeError")
expect(event["exception"]["values"][0]["value"]).to eq("An unhandled exception!")
end

it "filters exception backtrace with custom BacktraceCleaner" do
get "/view_exception"

traces = event.dig("exception", "values", 0, "stacktrace", "frames")
expect(traces.dig(-1, "filename")).to eq("inline template")
expect(traces.dig(-1, "function")).not_to be_nil
ensure
Sentry.configuration.backtrace_cleanup_callback = original_cleanup_callback

# we want to avoid something like "_inline_template__3014794444104730113_10960"
expect(traces.dig(-1, "function")).to be_nil
end
end

it "sets transaction to ControllerName#method" do
get "/exception"
it "doesn't filters exception backtrace if backtrace_cleanup_callback is overridden" do
original_cleanup_callback = Sentry.configuration.backtrace_cleanup_callback

begin
Sentry.configuration.backtrace_cleanup_callback = nil

expect(event['transaction']).to eq("HelloController#exception")
get "/view_exception"

traces = event.dig("exception", "values", 0, "stacktrace", "frames")
expect(traces.dig(-1, "filename")).to eq("inline template")
expect(traces.dig(-1, "function")).not_to be_nil
ensure
Sentry.configuration.backtrace_cleanup_callback = original_cleanup_callback
end
end

it "sets transaction to ControllerName#method" do
get "/exception"

expect(event['transaction']).to eq("HelloController#exception")
end
end

it "sets Sentry.configuration.logger correctly" do
Expand Down

0 comments on commit db3dc57

Please sign in to comment.