Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Created August 14, 2017 15:51
Show Gist options
  • Save nateberkopec/030581ead896bbb8f5ccbc5b961929c7 to your computer and use it in GitHub Desktop.
Save nateberkopec/030581ead896bbb8f5ccbc5b961929c7 to your computer and use it in GitHub Desktop.
Sentry repro script for rails
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
gem "rails", "5.1.0"
gem "sentry-raven"
end
require 'raven/transports/dummy'
Raven.configure do |config|
config.dsn = "dummy://12345:67890@sentry.localdomain/sentry/42"
end
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.consider_all_requests_local = true
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.append do
get "/" => "test#index"
get "/exception" => "test#exception"
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: "Home"
end
def exception
raise "herp"
end
end
TestApp.initialize!
require "minitest/autorun"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_has_middleware
assert_includes app.middleware, Raven::Rack
end
def test_captures_exception
get "/exception"
refute last_response.ok?
assert_equal 1, Raven.client.transport.events.size
end
private
def app
Rails.application
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment