Permalink
Browse files

Added new method for filtering backtraces.

Backtraces can skip tconsole paths now.
  • Loading branch information...
1 parent 68a1e1d commit 586d5ca6e2fc61f1e8096c188afb9f3882327ab6 @commondream commondream committed May 19, 2012
Showing with 43 additions and 2 deletions.
  1. +12 −0 lib/tconsole/util.rb
  2. +2 −2 test/unit/config_test.rb
  3. +29 −0 test/unit/util_test.rb
View
@@ -17,5 +17,17 @@ def self.detect_terminal_size
rescue
nil
end
+
+ # Public: Filters a backtrace to exclude things that happened in TConsole
+ #
+ # backtrace: The backtrace array that we're filtering.
+ #
+ # Returns the updated backtrace.
+ def self.filter_backtrace(backtrace)
+ tconsole_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) + File::SEPARATOR
+ backtrace.select do |item|
+ !item.start_with?(tconsole_path)
+ end
+ end
end
end
View
@@ -4,7 +4,7 @@ module TConsole
class ConfigTest < MiniTest::Unit::TestCase
a "Config" do
- setup do
+ before do
@config = TConsole::Config.new
end
@@ -35,7 +35,7 @@ class ConfigTest < MiniTest::Unit::TestCase
end
the "Config class" do
- setup do
+ before do
TConsole::Config.clear_loaded_configs
end
View
@@ -0,0 +1,29 @@
+require 'test_helper'
+
+module TConsole
+ class ConfigTest < MiniTest::Unit::TestCase
+ a "Backtrace" do
+ before do
+ @non_tconsole_path = "/Users/alan/Projects/commondream/tconsole-test/test/functional/posts_controller_test.rb:16:in `block in <class:PostsControllerTest>'"
+ @tconsole_path = "#{File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))}/posts_controller_test.rb:16:in `block in <class:PostsControllerTest>'"
+
+ @backtrace = [
+ @non_tconsole_path,
+ @tconsole_path
+ ]
+
+ @filtered_backtrace = Util.filter_backtrace(@backtrace)
+ end
+
+ it "should remove the tconsole path" do
+ assert_equal 1, @filtered_backtrace.length
+ assert !@filtered_backtrace.include?(@tconsole_path), "Should filter backtrace item under tconsole"
+ end
+
+ it "shouldn't remove the non-tconsole path" do
+ assert @filtered_backtrace.include?(@non_tconsole_path), "Should not filter backtrace item outside of tconsole"
+ end
+
+ end
+ end
+end

0 comments on commit 586d5ca

Please sign in to comment.