From a1b43e4236a578c8930959e59427e56ed84cea7e Mon Sep 17 00:00:00 2001 From: Kevin Tuhumury Date: Wed, 17 Apr 2013 00:11:23 +0200 Subject: [PATCH] Output the backtrace like Rails does, so list the name and version of the gem before it's file path. Adds the enhancement requested in #29. --- lib/better_errors/stack_frame.rb | 2 +- spec/better_errors/stack_frame_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/better_errors/stack_frame.rb b/lib/better_errors/stack_frame.rb index abc9b6d8..d9e14926 100644 --- a/lib/better_errors/stack_frame.rb +++ b/lib/better_errors/stack_frame.rb @@ -50,7 +50,7 @@ def gem? def gem_path Gem.path.each do |path| if filename.index(path) == 0 - return filename.gsub("#{path}/gems/", "(gem) ") + return filename.gsub(%r{#{path}/gems/([^/]+)-([\w.]+)/}, '\1 (\2) ') end end end diff --git a/spec/better_errors/stack_frame_spec.rb b/spec/better_errors/stack_frame_spec.rb index be47e020..b0e9e8a2 100644 --- a/spec/better_errors/stack_frame_spec.rb +++ b/spec/better_errors/stack_frame_spec.rb @@ -54,7 +54,7 @@ module BetterErrors Gem.stub!(:path).and_return(["/abc/xyz"]) frame = StackFrame.new("/abc/xyz/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo") - frame.gem_path.should == "(gem) whatever-1.2.3/lib/whatever.rb" + frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb" end it "should prioritize gem path over application path" do @@ -62,7 +62,7 @@ module BetterErrors Gem.stub!(:path).and_return(["/abc/xyz/vendor"]) frame = StackFrame.new("/abc/xyz/vendor/gems/whatever-1.2.3/lib/whatever.rb", 123, "foo") - frame.gem_path.should == "(gem) whatever-1.2.3/lib/whatever.rb" + frame.gem_path.should == "whatever (1.2.3) lib/whatever.rb" end end