thoughtbot-quietbacktrace 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.markdown +9 -52
- data/Rakefile +34 -0
- data/lib/backtrace_cleaner.rb +100 -0
- data/lib/quietbacktrace.rb +12 -80
- metadata +11 -6
data/MIT-LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -12,70 +12,27 @@ sudo gem install thoughtbot-quietbacktrace --source=http://gems.github.com
|
|
12
12
|
Usage
|
13
13
|
-----
|
14
14
|
|
15
|
-
|
16
|
-
By default, their values are:
|
15
|
+
Silencers remove lines from the backtrace. Create your own:
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
# Will reject all lines that include the word "mongrel",
|
18
|
+
# like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
|
19
|
+
backtrace_cleaner = QuietBacktrace.BacktraceCleaner.new
|
20
|
+
backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
|
21
21
|
|
22
|
-
|
23
|
-
Filters modify the output of backtrace lines.
|
22
|
+
Filters modify the output of backtrace lines. Create your own:
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
self.new_backtrace_silencer :shoulda do |line|
|
29
|
-
line.include? 'vendor/plugins/shoulda'
|
30
|
-
end
|
31
|
-
self.backtrace_silencers << :shoulda
|
32
|
-
end
|
33
|
-
|
34
|
-
Or your own backtrace_filters:
|
35
|
-
|
36
|
-
class Test::Unit::TestCase
|
37
|
-
self.new_backtrace_filter :ruby_path do |line|
|
38
|
-
ruby_file_path = '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8'
|
39
|
-
line.slice!(0..(line =~ ruby_file_path)) if (line =~ ruby_file_path)
|
40
|
-
end
|
41
|
-
self.backtrace_filters << :ruby_path
|
42
|
-
end
|
43
|
-
|
44
|
-
Turn Quiet Backtrace off anywhere in your test suite by setting the flag to false:
|
45
|
-
|
46
|
-
Test::Unit::TestCase.quiet_backtrace = false
|
47
|
-
|
48
|
-
Rails-specific usage
|
49
|
-
--------------------
|
50
|
-
|
51
|
-
Install the gem and add it your Rails app:
|
52
|
-
|
53
|
-
* gem install thoughtbot-quietbacktrace --source http://gems.github.com
|
54
|
-
* cd vendor/gems
|
55
|
-
* gem unpack quietbacktrace
|
56
|
-
|
57
|
-
Quiet Backtrace comes with an excellent Rails-specific silencer and filter.
|
58
|
-
They must be added (usually in test_helper.rb) because they are not turned on by default:
|
59
|
-
|
60
|
-
class Test::Unit::TestCase
|
61
|
-
self.backtrace_silencers << :rails_vendor
|
62
|
-
self.backtrace_filters << :rails_root
|
63
|
-
end
|
64
|
-
|
65
|
-
Because Quiet Backtrace works by adding attributes onto Test::Unit::TestCase,
|
66
|
-
you can add and remove silencers and filters at any level in your test suite,
|
67
|
-
down to the individual test.
|
24
|
+
# Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
|
25
|
+
backtrace_cleaner = QuietBacktrace.BacktraceCleaner.new
|
26
|
+
backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
|
68
27
|
|
69
28
|
Requirements
|
70
29
|
------------
|
71
30
|
|
72
31
|
* Test::Unit
|
73
|
-
* ActiveSupport (alias method chain, cattr accessor, & mattr accessor)
|
74
32
|
|
75
33
|
Resources
|
76
34
|
---------
|
77
35
|
|
78
|
-
* [mailing list](http://groups.google.com/group/quiet_backtrace)
|
79
36
|
* [project site](http://github.com/thoughtbot/quietbacktrace)
|
80
37
|
|
81
38
|
Authors
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
desc "Run the test suite"
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the quietbacktrace gem.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
gem_spec = Gem::Specification.new do |gem_spec|
|
17
|
+
gem_spec.name = "quietbacktrace"
|
18
|
+
gem_spec.version = "1.1.6"
|
19
|
+
gem_spec.summary = "Suppresses the noise in your Test::Unit backtraces."
|
20
|
+
gem_spec.email = "support@thoughtbot.com"
|
21
|
+
gem_spec.homepage = "http://github.com/thoughtbot/quietbacktrace"
|
22
|
+
gem_spec.description = "Silence or filter lines of your backtrace programatically."
|
23
|
+
gem_spec.authors = ["thoughtbot, inc.", "Dan Croak", "James Golick",
|
24
|
+
"Mike Burns", "Joe Ferris", "Boston.rb"]
|
25
|
+
gem_spec.files = FileList["[A-Z]*", "{lib}/**/*"]
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Generate a gemspec file"
|
29
|
+
task :gemspec do
|
30
|
+
File.open("#{gem_spec.name}.gemspec", 'w') do |f|
|
31
|
+
f.write gem_spec.to_yaml
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module QuietBacktrace
|
2
|
+
class BacktraceCleaner
|
3
|
+
|
4
|
+
RUBY_NOISE = %w( ruby Ruby.framework
|
5
|
+
rubygems/custom_require benchmark.rb )
|
6
|
+
TEST_UNIT_NOISE = %w( test/unit )
|
7
|
+
GEM_NOISE = %w( -e:1 )
|
8
|
+
|
9
|
+
SHOULDA_NOISE = %w( shoulda )
|
10
|
+
|
11
|
+
RAILS_NOISE = %w( script/server lib/active_record )
|
12
|
+
VENDOR_DIRS = %w( vendor/gems vendor/rails vendor/plugins )
|
13
|
+
SERVER_DIRS = %w( lib/mongrel bin/mongrel
|
14
|
+
lib/passenger bin/passenger-spawn-server
|
15
|
+
lib/rack )
|
16
|
+
|
17
|
+
ERB_METHOD_SIG = /:in `_run_erb_.*/
|
18
|
+
|
19
|
+
ALL_NOISE = RUBY_NOISE + TEST_UNIT_NOISE + GEM_NOISE + SHOULDA_NOISE +
|
20
|
+
RAILS_NOISE + VENDOR_DIRS + SERVER_DIRS
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@filters, @silencers = [], []
|
24
|
+
|
25
|
+
if defined?(RAILS_ROOT)
|
26
|
+
add_filter { |line| line.sub("#{RAILS_ROOT}/", '') }
|
27
|
+
end
|
28
|
+
|
29
|
+
add_filter { |line| line.sub(ERB_METHOD_SIG, '') }
|
30
|
+
add_filter { |line| line.sub('./', '/') }
|
31
|
+
|
32
|
+
if defined?(Gem)
|
33
|
+
add_filter do |line|
|
34
|
+
line.sub(/(#{Gem.default_dir})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the backtrace after all filters and silencers has been run against it.
|
42
|
+
# Filters run first, then silencers.
|
43
|
+
def clean(backtrace)
|
44
|
+
silence(filter(backtrace))
|
45
|
+
end
|
46
|
+
|
47
|
+
# Adds a filter from the block provided.
|
48
|
+
# Each line in the backtrace will be mapped against this filter.
|
49
|
+
#
|
50
|
+
# Example:
|
51
|
+
#
|
52
|
+
# Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
|
53
|
+
#
|
54
|
+
# backtrace_cleaner = QuietBacktrace.BacktraceCleaner.new
|
55
|
+
# backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
|
56
|
+
def add_filter(&block)
|
57
|
+
@filters << block
|
58
|
+
end
|
59
|
+
|
60
|
+
# Adds a silencer from the block provided. If the silencer returns true for a given line, it'll be excluded from the
|
61
|
+
# quiet backtrace.
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
#
|
65
|
+
# Will reject all lines that include the word "mongrel",
|
66
|
+
# like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
|
67
|
+
#
|
68
|
+
# backtrace_cleaner = QuietBacktrace.BacktraceCleaner.new
|
69
|
+
# backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
|
70
|
+
def add_silencer(&block)
|
71
|
+
@silencers << block
|
72
|
+
end
|
73
|
+
|
74
|
+
# Will remove all silencers, but leave in the filters.
|
75
|
+
# This is useful if your context of debugging suddenly expands as
|
76
|
+
# you suspect a bug in the libraries you use.
|
77
|
+
def remove_silencers!
|
78
|
+
@silencers = []
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def filter(backtrace)
|
84
|
+
@filters.each do |f|
|
85
|
+
backtrace = backtrace.map { |line| f.call(line) }
|
86
|
+
end
|
87
|
+
|
88
|
+
backtrace
|
89
|
+
end
|
90
|
+
|
91
|
+
def silence(backtrace)
|
92
|
+
@silencers.each do |s|
|
93
|
+
backtrace = backtrace.reject { |line| s.call(line) }
|
94
|
+
end
|
95
|
+
|
96
|
+
backtrace
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/quietbacktrace.rb
CHANGED
@@ -1,90 +1,22 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
3
|
-
require 'activesupport'
|
2
|
+
require File.join(File.dirname(__FILE__), 'backtrace_cleaner')
|
4
3
|
|
5
|
-
module QuietBacktrace
|
6
|
-
module
|
4
|
+
module QuietBacktrace
|
5
|
+
module CleanerForTestUnit
|
7
6
|
def self.included(klass)
|
8
|
-
klass.
|
7
|
+
klass.send :alias_method, :filter_backtrace_without_cleaning, :filter_backtrace
|
8
|
+
klass.send :alias_method, :filter_backtrace, :filter_backtrace_with_cleaning
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def filter_backtrace_with_quieting(backtrace)
|
15
|
-
filter_backtrace_without_quieting(backtrace)
|
16
|
-
|
17
|
-
# Rails view backtraces are flattened into one String. Adjust.
|
11
|
+
def filter_backtrace_with_cleaning(backtrace)
|
12
|
+
backtrace = filter_backtrace_without_cleaning(backtrace)
|
18
13
|
backtrace = backtrace.first.split("\n") if backtrace.size == 1
|
19
|
-
|
20
|
-
|
21
|
-
backtrace.reject! do |line|
|
22
|
-
[*Test::Unit::TestCase.backtrace_silencers].any? do |silencer_name|
|
23
|
-
QuietBacktrace::BacktraceFilter.silencers[silencer_name].call(line) if silencer_name
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
backtrace.each do |line|
|
28
|
-
[*Test::Unit::TestCase.backtrace_filters].each do |filter_name|
|
29
|
-
QuietBacktrace::BacktraceFilter.filters[filter_name].call(line) if filter_name
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
backtrace
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module TestCase
|
39
|
-
def self.included(klass)
|
40
|
-
klass.class_eval do
|
41
|
-
cattr_accessor :quiet_backtrace, :backtrace_silencers, :backtrace_filters
|
42
|
-
self.backtrace_filters, self.backtrace_silencers = [], []
|
43
|
-
|
44
|
-
extend ClassMethods
|
45
|
-
|
46
|
-
new_backtrace_silencer(:test_unit) do |line|
|
47
|
-
(line.include?("ruby") && line.include?("/test/unit"))
|
48
|
-
end
|
49
|
-
new_backtrace_silencer(:os_x_ruby) do |line|
|
50
|
-
line.include?('Ruby.framework')
|
51
|
-
end
|
52
|
-
new_backtrace_silencer(:gem_root) do |line|
|
53
|
-
line =~ /ruby\/gems/i
|
54
|
-
end
|
55
|
-
new_backtrace_silencer(:e1) do |line|
|
56
|
-
line == "-e:1"
|
57
|
-
end
|
58
|
-
new_backtrace_silencer(:rails_vendor) do |line|
|
59
|
-
(line.include?("vendor/plugins") ||
|
60
|
-
line.include?("vendor/gems") ||
|
61
|
-
line.include?("vendor/rails"))
|
62
|
-
end
|
63
|
-
|
64
|
-
new_backtrace_filter(:method_name) do |line|
|
65
|
-
line.slice!((line =~ /:in /)..line.length) if (line =~ /:in /)
|
66
|
-
end
|
67
|
-
new_backtrace_filter(:rails_root) do |line|
|
68
|
-
line.sub!("#{RAILS_ROOT}/", '') if (defined?(RAILS_ROOT) && line.include?(RAILS_ROOT))
|
69
|
-
end
|
70
|
-
|
71
|
-
self.quiet_backtrace = true
|
72
|
-
self.backtrace_silencers = [:test_unit, :os_x_ruby, :gem_root, :e1]
|
73
|
-
self.backtrace_filters = [:method_name]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
module ClassMethods
|
78
|
-
def new_backtrace_silencer(symbol, &block)
|
79
|
-
QuietBacktrace::BacktraceFilter.silencers[symbol] = block
|
80
|
-
end
|
81
|
-
|
82
|
-
def new_backtrace_filter(symbol, &block)
|
83
|
-
QuietBacktrace::BacktraceFilter.filters[symbol] = block
|
84
|
-
end
|
14
|
+
cleaner = QuietBacktrace::BacktraceCleaner.new
|
15
|
+
cleaner.clean(backtrace)
|
85
16
|
end
|
86
17
|
end
|
87
18
|
end
|
88
19
|
|
89
|
-
Test::Unit::Util::BacktraceFilter.module_eval
|
90
|
-
|
20
|
+
Test::Unit::Util::BacktraceFilter.module_eval do
|
21
|
+
include QuietBacktrace::CleanerForTestUnit
|
22
|
+
end
|
metadata
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thoughtbot-quietbacktrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot, inc.
|
8
8
|
- Dan Croak
|
9
9
|
- James Golick
|
10
|
+
- Mike Burns
|
11
|
+
- Joe Ferris
|
12
|
+
- Boston.rb
|
10
13
|
autorequire:
|
11
14
|
bindir: bin
|
12
15
|
cert_chain: []
|
13
16
|
|
14
|
-
date:
|
17
|
+
date: 2009-02-28 21:00:00 -08:00
|
15
18
|
default_executable:
|
16
19
|
dependencies: []
|
17
20
|
|
18
|
-
description:
|
19
|
-
email:
|
21
|
+
description: Silence or filter lines of your backtrace programatically.
|
22
|
+
email: support@thoughtbot.com
|
20
23
|
executables: []
|
21
24
|
|
22
25
|
extensions: []
|
@@ -24,9 +27,11 @@ extensions: []
|
|
24
27
|
extra_rdoc_files: []
|
25
28
|
|
26
29
|
files:
|
30
|
+
- MIT-LICENSE
|
31
|
+
- Rakefile
|
27
32
|
- README.markdown
|
33
|
+
- lib/backtrace_cleaner.rb
|
28
34
|
- lib/quietbacktrace.rb
|
29
|
-
- MIT-LICENSE
|
30
35
|
has_rdoc: false
|
31
36
|
homepage: http://github.com/thoughtbot/quietbacktrace
|
32
37
|
post_install_message:
|
@@ -52,6 +57,6 @@ rubyforge_project:
|
|
52
57
|
rubygems_version: 1.2.0
|
53
58
|
signing_key:
|
54
59
|
specification_version: 2
|
55
|
-
summary:
|
60
|
+
summary: Suppresses the noise in your Test::Unit backtraces.
|
56
61
|
test_files: []
|
57
62
|
|