Skip to content

Instantly share code, notes, and snippets.

@travisp
Last active January 26, 2018 23:13
Show Gist options
  • Save travisp/044b9e296229f90f5bc3d274414db45b to your computer and use it in GitHub Desktop.
Save travisp/044b9e296229f90f5bc3d274414db45b to your computer and use it in GitHub Desktop.
# 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.0.6"
gem "sentry-raven", require: 'sentry-raven-without-integrations'
gem 'grape'
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"
require 'raven/integrations/rack'
class API < Grape::API
use Raven::Rack
before do
Raven.extra_context({test: 'mycontext'})
end
rescue_from :all do |e|
puts Raven.context.extra
Raven.capture_exception(e)
Rack::Response.new({ error: 'An error ocurred' }.to_json, 500, { "Content-type" => "application/json" })
end
get :hello do
{ hello: 'world' }
end
get :exception do
raise "herp"
end
end
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
mount API => '/'
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
def test_hello
get "/hello"
assert last_response.ok?
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