From 0b43f2c6d5877ea9b60f40ab8b689bd0e4f16539 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Mon, 20 Feb 2017 09:56:25 -0800 Subject: [PATCH] set a default root_directory so source code highlighting works out of the box --- lib/airbrake-ruby/config.rb | 5 +++++ spec/airbrake_spec.rb | 6 +++--- spec/config_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/airbrake-ruby/config.rb b/lib/airbrake-ruby/config.rb index b4458842..1a665b6a 100644 --- a/lib/airbrake-ruby/config.rb +++ b/lib/airbrake-ruby/config.rb @@ -96,6 +96,11 @@ def initialize(user_config = {}) self.blacklist_keys = [] self.whitelist_keys = [] + self.root_directory = ( + (defined?(Bundler) && Bundler.root) || + File.expand_path(Dir.pwd) + ) + merge(user_config) end diff --git a/spec/airbrake_spec.rb b/spec/airbrake_spec.rb index c916a997..11a52901 100644 --- a/spec/airbrake_spec.rb +++ b/spec/airbrake_spec.rb @@ -78,7 +78,7 @@ # rubocop:disable Metrics/LineLength expected_body = %r| {"errors":\[{"type":"RuntimeError","message":"bingo","backtrace":\[ - {"file":"[\w/\-\.]+spec/airbrake_spec.rb","line":\d+,"function":"[\w/\s\(\)<>]+"}, + {"file":"\[PROJECT_ROOT\]/spec/airbrake_spec.rb","line":\d+,"function":"[\w/\s\(\)<>]+"}, {"file":"\[GEM_ROOT\]/gems/rspec-core-.+/.+","line":\d+,"function":"[\w/\s\(\)<>]+"} |x # rubocop:enable Metrics/LineLength @@ -167,11 +167,11 @@ filter_chain = notifier.instance_variable_get(:@filter_chain) filters = filter_chain.instance_variable_get(:@filters) - expect(filters.size).to eq(2) + expect(filters.size).to eq(3) described_class.add_filter {} - expect(filters.size).to eq(3) + expect(filters.size).to eq(4) expect(filters.last).to be_a(Proc) end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index e47d6b51..53bdc328 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -51,8 +51,8 @@ expect(config.queue_size).to eq(100) end - it "doesn't set the default root_directory" do - expect(config.root_directory).to be_nil + it "sets the default root_directory" do + expect(config.root_directory).to eq Bundler.root end it "doesn't set the default environment" do