quietbacktrace 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/Manifest.txt +9 -0
- data/README.txt +85 -0
- data/Rakefile +21 -0
- data/bin/quietbacktrace +0 -0
- data/lib/aliasing.rb +82 -0
- data/lib/attribute_accessors.rb +123 -0
- data/lib/quiet_backtrace.rb +138 -0
- data/test/quiet_backtrace_test.rb +144 -0
- metadata +65 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
= Quiet Backtrace
|
2
|
+
|
3
|
+
Quiet Backtrace suppresses the noise in your Test::Unit backtrace.
|
4
|
+
It also provides hooks for you to add additional silencers and filters.
|
5
|
+
|
6
|
+
== Install
|
7
|
+
|
8
|
+
sudo gem install quietbacktrace
|
9
|
+
|
10
|
+
== Usage
|
11
|
+
|
12
|
+
Quiet Backtrace works by adding new attributes to Test::Unit::TestCase.
|
13
|
+
By default, their values are:
|
14
|
+
self.quiet_backtrace = true
|
15
|
+
self.backtrace_silencers = [:test_unit, :gem_root, :e1]
|
16
|
+
self.backtrace_filters = [:method_name]
|
17
|
+
|
18
|
+
Override the defaults by adding your own backtrace_silencers:
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
self.backtrace_silencers :shoulda do |line|
|
21
|
+
line.include? 'vendor/plugins/shoulda'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Adding your own backtrace_filters works the same way:
|
26
|
+
class Test::Unit::TestCase
|
27
|
+
self.backtrace_filters :ruby_path do |line|
|
28
|
+
ruby_file_path = '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8'
|
29
|
+
line.slice!(0..(line =~ ruby_file_path)) if (line =~ ruby_file_path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
== Rails-specific usage
|
34
|
+
|
35
|
+
If you're working with Rails, you must add the built-in silencer
|
36
|
+
and filter because they are not turned on by default:
|
37
|
+
class Test::Unit::TestCase
|
38
|
+
self.backtrace_silencers << :rails_vendor
|
39
|
+
self.backtrace_filters << :rails_root
|
40
|
+
end
|
41
|
+
|
42
|
+
== Resources
|
43
|
+
|
44
|
+
* mailing list: http://groups.google.com/group/quiet_backtrace
|
45
|
+
* project site: http://rubyforge.org/projects/quietbacktrace
|
46
|
+
* svn repo: https://svn.thoughtbot.com/gems/quiet_backtrace
|
47
|
+
|
48
|
+
== Authors
|
49
|
+
|
50
|
+
* Dan Croak (dcroak@thoughtbot.com, http://dancroak.com)
|
51
|
+
* James Golick (james@giraffesoft.ca, http://jamesgolick.com)
|
52
|
+
* Joe Ferris (jferris@thoughtbot.com)
|
53
|
+
|
54
|
+
Special thanks to the Boston.rb group (http://boston.rubygroup.org)
|
55
|
+
for cultivating this idea at our inaugural hackfest.
|
56
|
+
|
57
|
+
== Requirements
|
58
|
+
|
59
|
+
* Test::Unit
|
60
|
+
* aliasing.rb and attribute_accessors.rb, which are snipped from ActiveSupport and
|
61
|
+
are included in the gem. They allow quiet_backtrace.rb to use alias_method_chain,
|
62
|
+
cattr_accessor, and mattr_accessor.
|
63
|
+
|
64
|
+
== License
|
65
|
+
|
66
|
+
Copyright (c) 2007 Dan Croak, thoughtbot, inc., released under the MIT license
|
67
|
+
|
68
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
69
|
+
a copy of this software and associated documentation files (the
|
70
|
+
"Software"), to deal in the Software without restriction, including
|
71
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
72
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
73
|
+
permit persons to whom the Software is furnished to do so, subject to
|
74
|
+
the following conditions:
|
75
|
+
|
76
|
+
The above copyright notice and this permission notice shall be
|
77
|
+
included in all copies or substantial portions of the Software.
|
78
|
+
|
79
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
80
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
81
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
82
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
83
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
84
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
85
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/quiet_backtrace.rb'
|
6
|
+
|
7
|
+
Hoe.new('quietbacktrace', '0.0.1') do |p|
|
8
|
+
p.rubyforge_name = 'quietbacktrace'
|
9
|
+
p.author = 'Dan Croak'
|
10
|
+
p.email = 'dcroak@thoughtbot.com'
|
11
|
+
p.summary = <<-EOF
|
12
|
+
quiet_backtrace suppresses the noise in your Test::Unit backtrace.
|
13
|
+
It also provides hooks for you to add additional filters.
|
14
|
+
EOF
|
15
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
16
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
17
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
18
|
+
p.remote_rdoc_dir = '' # Release to root
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=Ruby
|
data/bin/quietbacktrace
ADDED
File without changes
|
data/lib/aliasing.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
# Copyright (c) 2005-2006 David Heinemeier Hansson
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
# activesupport/lib/activesupport/core_ext/module/aliasing.rb
|
24
|
+
|
25
|
+
class Module # :nodoc:
|
26
|
+
# Encapsulates the common pattern of:
|
27
|
+
#
|
28
|
+
# alias_method :foo_without_feature, :foo
|
29
|
+
# alias_method :foo, :foo_with_feature
|
30
|
+
#
|
31
|
+
# With this, you simply do:
|
32
|
+
#
|
33
|
+
# alias_method_chain :foo, :feature
|
34
|
+
#
|
35
|
+
# And both aliases are set up for you.
|
36
|
+
#
|
37
|
+
# Query and bang methods (foo?, foo!) keep the same punctuation:
|
38
|
+
#
|
39
|
+
# alias_method_chain :foo?, :feature
|
40
|
+
#
|
41
|
+
# is equivalent to
|
42
|
+
#
|
43
|
+
# alias_method :foo_without_feature?, :foo?
|
44
|
+
# alias_method :foo?, :foo_with_feature?
|
45
|
+
#
|
46
|
+
# so you can safely chain foo, foo?, and foo! with the same feature.
|
47
|
+
def alias_method_chain(target, feature)
|
48
|
+
# Strip out punctuation on predicates or bang methods since
|
49
|
+
# e.g. target?_without_feature is not a valid method name.
|
50
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
51
|
+
yield(aliased_target, punctuation) if block_given?
|
52
|
+
alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
|
53
|
+
alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Allows you to make aliases for attributes, which includes
|
57
|
+
# getter, setter, and query methods.
|
58
|
+
#
|
59
|
+
# Example:
|
60
|
+
#
|
61
|
+
# class Content < ActiveRecord::Base
|
62
|
+
# # has a title attribute
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# class Email < ActiveRecord::Base
|
66
|
+
# alias_attribute :subject, :title
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# e = Email.find(1)
|
70
|
+
# e.title # => "Superstars"
|
71
|
+
# e.subject # => "Superstars"
|
72
|
+
# e.subject? # => true
|
73
|
+
# e.subject = "Megastars"
|
74
|
+
# e.title # => "Megastars"
|
75
|
+
def alias_attribute(new_name, old_name)
|
76
|
+
module_eval <<-STR, __FILE__, __LINE__+1
|
77
|
+
def #{new_name}; #{old_name}; end
|
78
|
+
def #{new_name}?; #{old_name}?; end
|
79
|
+
def #{new_name}=(v); self.#{old_name} = v; end
|
80
|
+
STR
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
# Copyright (c) 2005-2006 David Heinemeier Hansson
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
# activesupport/lib/activesupport/core_ext/module/attribute_accessors.rb
|
24
|
+
#
|
25
|
+
# Extends the module object with module and instance accessors for class attributes,
|
26
|
+
# just like the native attr* accessors for instance attributes.
|
27
|
+
class Module # :nodoc:
|
28
|
+
def mattr_reader(*syms)
|
29
|
+
syms.each do |sym|
|
30
|
+
next if sym.is_a?(Hash)
|
31
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
32
|
+
unless defined? @@#{sym}
|
33
|
+
@@#{sym} = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.#{sym}
|
37
|
+
@@#{sym}
|
38
|
+
end
|
39
|
+
|
40
|
+
def #{sym}
|
41
|
+
@@#{sym}
|
42
|
+
end
|
43
|
+
EOS
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def mattr_writer(*syms)
|
48
|
+
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
49
|
+
syms.each do |sym|
|
50
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
51
|
+
unless defined? @@#{sym}
|
52
|
+
@@#{sym} = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.#{sym}=(obj)
|
56
|
+
@@#{sym} = obj
|
57
|
+
end
|
58
|
+
|
59
|
+
#{"
|
60
|
+
def #{sym}=(obj)
|
61
|
+
@@#{sym} = obj
|
62
|
+
end
|
63
|
+
" unless options[:instance_writer] == false }
|
64
|
+
EOS
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def mattr_accessor(*syms)
|
69
|
+
mattr_reader(*syms)
|
70
|
+
mattr_writer(*syms)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# activesupport/lib/activesupport/core_ext/class/attribute_accessors.rb
|
75
|
+
|
76
|
+
# Extends the class object with class and instance accessors for class attributes,
|
77
|
+
# just like the native attr* accessors for instance attributes.
|
78
|
+
class Class # :nodoc:
|
79
|
+
def cattr_reader(*syms)
|
80
|
+
syms.flatten.each do |sym|
|
81
|
+
next if sym.is_a?(Hash)
|
82
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
83
|
+
unless defined? @@#{sym}
|
84
|
+
@@#{sym} = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.#{sym}
|
88
|
+
@@#{sym}
|
89
|
+
end
|
90
|
+
|
91
|
+
def #{sym}
|
92
|
+
@@#{sym}
|
93
|
+
end
|
94
|
+
EOS
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def cattr_writer(*syms)
|
99
|
+
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
100
|
+
syms.flatten.each do |sym|
|
101
|
+
class_eval(<<-EOS, __FILE__, __LINE__)
|
102
|
+
unless defined? @@#{sym}
|
103
|
+
@@#{sym} = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.#{sym}=(obj)
|
107
|
+
@@#{sym} = obj
|
108
|
+
end
|
109
|
+
|
110
|
+
#{"
|
111
|
+
def #{sym}=(obj)
|
112
|
+
@@#{sym} = obj
|
113
|
+
end
|
114
|
+
" unless options[:instance_writer] == false }
|
115
|
+
EOS
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def cattr_accessor(*syms)
|
120
|
+
cattr_reader(*syms)
|
121
|
+
cattr_writer(*syms)
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# = Quiet Backtrace
|
2
|
+
#
|
3
|
+
# Quiet Backtrace suppresses the noise in your Test::Unit backtrace.
|
4
|
+
# It also provides hooks for you to add additional silencers and filters.
|
5
|
+
#
|
6
|
+
# == Install
|
7
|
+
#
|
8
|
+
# sudo gem install quietbacktrace
|
9
|
+
#
|
10
|
+
# == Usage
|
11
|
+
#
|
12
|
+
# Quiet Backtrace works by adding new attributes to Test::Unit::TestCase.
|
13
|
+
# By default, their values are:
|
14
|
+
# self.quiet_backtrace = true
|
15
|
+
# self.backtrace_silencers = [:test_unit, :gem_root, :e1]
|
16
|
+
# self.backtrace_filters = [:method_name]
|
17
|
+
#
|
18
|
+
# Silencers remove lines from the backtrace that return true for given conditions.
|
19
|
+
# Filters modify the output of backtrace lines.
|
20
|
+
#
|
21
|
+
# Override the defaults by adding your own backtrace_silencers:
|
22
|
+
# class Test::Unit::TestCase
|
23
|
+
# self.backtrace_silencers :shoulda do |line|
|
24
|
+
# line.include? 'vendor/plugins/shoulda'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Or your own backtrace_filters:
|
29
|
+
# class Test::Unit::TestCase
|
30
|
+
# self.backtrace_filters :ruby_path do |line|
|
31
|
+
# ruby_file_path = '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8'
|
32
|
+
# line.slice!(0..(line =~ ruby_file_path)) if (line =~ ruby_file_path)
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Turn Quiet Backtrace off anywhere in your test suite by setting the flag to false:
|
37
|
+
# Test::Unit::TestCase.quiet_backtrace = false
|
38
|
+
#
|
39
|
+
# == Rails-specific usage
|
40
|
+
#
|
41
|
+
# If you're working with Rails, you must add the built-in silencer
|
42
|
+
# and filter because they are not turned on by default:
|
43
|
+
# class Test::Unit::TestCase
|
44
|
+
# self.backtrace_silencers << :rails_vendor
|
45
|
+
# self.backtrace_filters << :rails_root
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# Because Quiet Backtrace works by adding attributes onto Test::Unit::TestCase,
|
49
|
+
# you can add and remove silencers and filters at any level in your test suite,
|
50
|
+
# down to the individual test.
|
51
|
+
#
|
52
|
+
# == Resources
|
53
|
+
#
|
54
|
+
# * mailing list: http://groups.google.com/group/quiet_backtrace
|
55
|
+
# * project site: http://rubyforge.org/projects/quietbacktrace
|
56
|
+
# * svn repo: https://svn.thoughtbot.com/gems/quiet_backtrace
|
57
|
+
#
|
58
|
+
# == Authors
|
59
|
+
#
|
60
|
+
# * Dan Croak (dcroak@thoughtbot.com, http://dancroak.com)
|
61
|
+
# * James Golick (james@giraffesoft.ca, http://jamesgolick.com)
|
62
|
+
# * Joe Ferris (jferris@thoughtbot.com)
|
63
|
+
#
|
64
|
+
# Special thanks to the Boston.rb group (http://boston.rubygroup.org)
|
65
|
+
# for cultivating this idea at our inaugural hackfest.
|
66
|
+
#
|
67
|
+
# == Requirements
|
68
|
+
#
|
69
|
+
# * Test::Unit
|
70
|
+
# * aliasing.rb and attribute_accessors.rb, which are snipped from ActiveSupport and
|
71
|
+
# are included in the gem. They allow quiet_backtrace.rb to use alias_method_chain,
|
72
|
+
# cattr_accessor, and mattr_accessor.
|
73
|
+
#
|
74
|
+
# == Copyright
|
75
|
+
#
|
76
|
+
# Copyright (c) 2007 Dan Croak, thoughtbot, inc., released under the MIT license
|
77
|
+
|
78
|
+
require 'test/unit'
|
79
|
+
require 'lib/attribute_accessors'
|
80
|
+
require 'lib/aliasing'
|
81
|
+
|
82
|
+
module QuietBacktrace # :nodoc: all
|
83
|
+
module BacktraceFilter
|
84
|
+
def self.included(klass)
|
85
|
+
klass.class_eval { alias_method_chain :filter_backtrace, :quieting }
|
86
|
+
end
|
87
|
+
|
88
|
+
mattr_accessor :silencers
|
89
|
+
self.silencers = { :test_unit => lambda { |line| (line.include?("ruby") && line.include?("/test/unit")) },
|
90
|
+
:gem_root => lambda { |line| line =~ /ruby\/gems/i },
|
91
|
+
:e1 => lambda { |line| line == "-e:1" },
|
92
|
+
:rails_vendor => lambda { |line| (line.include?("vendor/plugins") || line.include?("vendor/gems") || line.include?("vendor/rails")) }
|
93
|
+
}
|
94
|
+
|
95
|
+
mattr_accessor :filters
|
96
|
+
self.filters = { :method_name => lambda { |line| line.slice!((line =~ /:in /)..line.length) if (line =~ /:in /) },
|
97
|
+
:rails_root => lambda { |line| line.sub!("#{RAILS_ROOT}/", '') if (defined?(RAILS_ROOT) && line.include?(RAILS_ROOT)) }}
|
98
|
+
|
99
|
+
def filter_backtrace_with_quieting(backtrace)
|
100
|
+
filter_backtrace_without_quieting(backtrace)
|
101
|
+
|
102
|
+
if Test::Unit::TestCase.quiet_backtrace
|
103
|
+
backtrace.reject! do |line|
|
104
|
+
[*Test::Unit::TestCase.backtrace_silencers].any? do |silencer_name|
|
105
|
+
QuietBacktrace::BacktraceFilter.silencers[silencer_name].call(line) if silencer_name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
backtrace.each do |line|
|
110
|
+
[*Test::Unit::TestCase.backtrace_filters].each do |filter_name|
|
111
|
+
QuietBacktrace::BacktraceFilter.filters[filter_name].call(line) if filter_name
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
backtrace = backtrace.first.split("\n") if backtrace.size == 1
|
117
|
+
backtrace
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
module TestCase
|
122
|
+
def self.included(klass)
|
123
|
+
klass.class_eval do
|
124
|
+
cattr_accessor :quiet_backtrace
|
125
|
+
self.quiet_backtrace = true
|
126
|
+
|
127
|
+
cattr_accessor :backtrace_silencers
|
128
|
+
self.backtrace_silencers = [:test_unit, :gem_root, :e1]
|
129
|
+
|
130
|
+
cattr_accessor :backtrace_filters
|
131
|
+
self.backtrace_filters = [:method_name]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
Test::Unit::Util::BacktraceFilter.module_eval { include QuietBacktrace::BacktraceFilter }
|
138
|
+
Test::Unit::TestCase.class_eval { include QuietBacktrace::TestCase }
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# = Quiet Backtrace Test
|
2
|
+
#
|
3
|
+
# It is worth looking through the Quiet Backtrace test source
|
4
|
+
# to see how Shoulda and Quiet Backtrace play well together.
|
5
|
+
#
|
6
|
+
# Shoulda's context blocks are perfect spots to turn Quiet Backtrace
|
7
|
+
# off if you need a more verbose backtrace to debug a particular problem.
|
8
|
+
#
|
9
|
+
# For example:
|
10
|
+
# context "Setting quiet backtrace to false" do
|
11
|
+
#
|
12
|
+
# setup do
|
13
|
+
# self.quiet_backtrace = false
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# should "keep the backtrace noisy" do
|
17
|
+
# assert_equal @backtrace, @unfiltered_backtrace
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# For more on Shoulda, see http://thoughtbot.com/projects/shoulda
|
23
|
+
|
24
|
+
require 'lib/quiet_backtrace'
|
25
|
+
require 'test/unit'
|
26
|
+
require 'rubygems'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
class MockTestUnit # :nodoc:
|
30
|
+
def filter_backtrace(backtrace); end
|
31
|
+
include QuietBacktrace::BacktraceFilter
|
32
|
+
end
|
33
|
+
|
34
|
+
class QuietBacktraceTest < Test::Unit::TestCase # :nodoc:
|
35
|
+
def setup
|
36
|
+
@backtrace = [ "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block'",
|
37
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:495:in `_wrap_assertion'",
|
38
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:46:in `assert_block'",
|
39
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:313:in `flunk'",
|
40
|
+
"/Users/james/Documents/railsApps/generating_station/app/controllers/photos_controller.rb:315:in `something'",
|
41
|
+
"/Users/james/Documents/railsApps/generating_station/vendor/plugins/quiet_stacktraces/test/quiet_stacktraces_test.rb:21:in `test_this_plugin'",
|
42
|
+
"/Users/james/Documents/railsApps/generating_station/vendor/plugins/quiet_stacktraces/quiet_stacktraces_test.rb:25:in `test_this_plugin'",
|
43
|
+
"/Library/Ruby/Gems/1.8/gems/activerecord-1.99.0/lib/active_record/connection_adapters/mysql_adapter.rb:471:in `real_connect'",
|
44
|
+
"/Library/Ruby/Gems/1.8/gems/activerecord-1.99.0/lib/active_record/fixtures.rb:895:in `teardown'",
|
45
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'",
|
46
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in `start_mediator'",
|
47
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in `start'",
|
48
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'",
|
49
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'",
|
50
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'",
|
51
|
+
"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit.rb:278",
|
52
|
+
"/Users/james/Documents/railsApps/generating_station/vendor/plugins/quiet_stacktraces/test/quiet_stacktraces_test.rb:20"]
|
53
|
+
end
|
54
|
+
|
55
|
+
context "The default quiet backtrace" do
|
56
|
+
|
57
|
+
setup do
|
58
|
+
reset_filter!
|
59
|
+
@mock = MockTestUnit.new
|
60
|
+
@default_quiet_backtrace = @mock.filter_backtrace(@backtrace.dup)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "silence any line from the test unit framework" do
|
64
|
+
assert !@default_quiet_backtrace.any? { |line| line.include?('ruby') && line.include?('test/unit') }, "One or more lines from the test/unit framework are not being filtered: #{@default_quiet_backtrace}"
|
65
|
+
end
|
66
|
+
|
67
|
+
should "silence any line that includes ruby slash gems" do
|
68
|
+
assert !@default_quiet_backtrace.any? { |line| line =~ /ruby\/gems/i }, "One or more lines from ruby/gems are not being filtered: #{@default_quiet_backtrace}"
|
69
|
+
end
|
70
|
+
|
71
|
+
should "silence any line that includes the e1 nonsense" do
|
72
|
+
assert !@default_quiet_backtrace.any? { |line| line == "-e:1" }, "One or more e1 nonsense lines are not being filtered: #{@default_quiet_backtrace}"
|
73
|
+
end
|
74
|
+
|
75
|
+
should "remove in methods from the end of lines" do
|
76
|
+
assert !@default_quiet_backtrace.any? { |line| line =~ /\:in / }, "Method name was not removed from one or more lines: #{@default_quiet_backtrace}"
|
77
|
+
end
|
78
|
+
|
79
|
+
should "not silence or filter a legitimate line" do
|
80
|
+
assert @default_quiet_backtrace.any? { |line| line == '/Users/james/Documents/railsApps/generating_station/app/controllers/photos_controller.rb:315' }, "Rails root is not being filtered: #{@default_quiet_backtrace}"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
context "The quiet backtrace with complementary Rails silencers and filters" do
|
86
|
+
|
87
|
+
setup do
|
88
|
+
reset_filter!
|
89
|
+
::RAILS_ROOT = '/Users/james/Documents/railsApps/generating_station'
|
90
|
+
self.backtrace_silencers << :rails_vendor
|
91
|
+
self.backtrace_filters << :rails_root
|
92
|
+
@mock = MockTestUnit.new
|
93
|
+
@rails_quiet_backtrace = @mock.filter_backtrace(@backtrace.dup)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "silence any line from the RAILS_ROOT/vendor directory" do
|
97
|
+
assert !@rails_quiet_backtrace.any? { |line| (line.include?("vendor/gems") || line.include?("vendor/plugins") || line.include?("vendor/rails")) }, "One or more lines from the vendor directory are not being silenced: #{@rails_quiet_backtrace.inspect}"
|
98
|
+
end
|
99
|
+
|
100
|
+
should "remove RAILS_ROOT text from the beginning of lines" do
|
101
|
+
assert !@rails_quiet_backtrace.any? { |line| line.include?("#{RAILS_ROOT}") }, "One or more lines that include RAILS_ROOT text are not being filtered: #{@rails_quiet_backtrace.inspect}"
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
context "Setting quiet backtrace to false" do
|
107
|
+
|
108
|
+
setup do
|
109
|
+
reset_filter!
|
110
|
+
self.quiet_backtrace = false
|
111
|
+
@mock = MockTestUnit.new
|
112
|
+
@unfiltered_backtrace = @mock.filter_backtrace(@backtrace.dup)
|
113
|
+
end
|
114
|
+
|
115
|
+
should "keep the backtrace noisy" do
|
116
|
+
assert_equal @backtrace, @unfiltered_backtrace, "Backtrace was silenced when it was told not to. This tool is a dictator."
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
context "Overriding the defaults" do
|
122
|
+
|
123
|
+
setup do
|
124
|
+
reset_filter!
|
125
|
+
self.backtrace_silencers = [:test_unit, :rails_vendor]
|
126
|
+
@mock = MockTestUnit.new
|
127
|
+
@not_filtering_gem_root = @mock.filter_backtrace(@backtrace.dup)
|
128
|
+
end
|
129
|
+
|
130
|
+
should "not apply a filter when it is not included in silencers" do
|
131
|
+
assert @not_filtering_gem_root.any? { |line| line =~ /ruby\/gems/i }, "One or more lines from ruby/gems were filtered, when that filter was excluded: #{@not_filtering_gem_root}"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def reset_filter!
|
139
|
+
self.quiet_backtrace = true
|
140
|
+
self.backtrace_silencers = [:test_unit, :gem_root]
|
141
|
+
self.backtrace_filters = [:method_name]
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: quietbacktrace
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-12-03 00:00:00 -05:00
|
8
|
+
summary: quiet_backtrace suppresses the noise in your Test::Unit backtrace. It also provides hooks for you to add additional filters.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: dcroak@thoughtbot.com
|
12
|
+
homepage:
|
13
|
+
rubyforge_project: quietbacktrace
|
14
|
+
description: "== Install sudo gem install quietbacktrace == Usage Quiet Backtrace works by adding new attributes to Test::Unit::TestCase. By default, their values are: self.quiet_backtrace = true self.backtrace_silencers = [:test_unit, :gem_root, :e1] self.backtrace_filters = [:method_name]"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Dan Croak
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/quietbacktrace
|
37
|
+
- lib/aliasing.rb
|
38
|
+
- lib/attribute_accessors.rb
|
39
|
+
- lib/quiet_backtrace.rb
|
40
|
+
- test/quiet_backtrace_test.rb
|
41
|
+
test_files: []
|
42
|
+
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.txt
|
46
|
+
extra_rdoc_files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.txt
|
50
|
+
executables:
|
51
|
+
- quietbacktrace
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
dependencies:
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: hoe
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.0
|
65
|
+
version:
|