Browse files

Exclude gem backtrace filter if rubygems is not loaded

  • Loading branch information...
1 parent 80a3983 commit fa1926ddaa7ad481c55b76d1f2c1952721b7b586 @josh josh committed Oct 20, 2009
Showing with 19 additions and 18 deletions.
  1. +2 −2 railties/lib/rails/backtrace_cleaner.rb
  2. +17 −16 railties/test/backtrace_cleaner_test.rb
View
4 railties/lib/rails/backtrace_cleaner.rb
@@ -27,10 +27,10 @@ def initialize
add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
end
-
-
+
private
def add_gem_filters
+ return unless defined? Gem
(Gem.path + [Gem.default_dir]).uniq.each do |path|
# http://gist.github.com/30430
add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
View
33 railties/test/backtrace_cleaner_test.rb
@@ -29,25 +29,26 @@ def setup
$stderr.puts 'No BacktraceFilter for minitest'
end
-class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
- def setup
- @cleaner = Rails::BacktraceCleaner.new
- end
-
- test "should format installed gems correctly" do
- @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
- @result = @cleaner.clean(@backtrace)
- assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
- end
+if defined? Gem
+ class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase
+ def setup
+ @cleaner = Rails::BacktraceCleaner.new
+ end
- test "should format installed gems not in Gem.default_dir correctly" do
- @target_dir = Gem.path.detect { |p| p != Gem.default_dir }
- # skip this test if default_dir is the only directory on Gem.path
- if @target_dir
- @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ test "should format installed gems correctly" do
+ @backtrace = [ "#{Gem.path[0]}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
@result = @cleaner.clean(@backtrace)
assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
end
- end
+ test "should format installed gems not in Gem.default_dir correctly" do
+ @target_dir = Gem.path.detect { |p| p != Gem.default_dir }
+ # skip this test if default_dir is the only directory on Gem.path
+ if @target_dir
+ @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ]
+ @result = @cleaner.clean(@backtrace)
+ assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0]
+ end
+ end
+ end
end

0 comments on commit fa1926d

Please sign in to comment.