Browse files

updated some more testing stuff, blegh

  • Loading branch information...
1 parent 8cf1dbe commit 501547c68eb5a112d64bb3ca53bfc2d656645081 @banister banister committed Dec 23, 2011
Showing with 100 additions and 37 deletions.
  1. +2 −0 Gemfile
  2. +13 −2 Rakefile
  3. +36 −0 test/helper.rb
  4. +49 −35 test/test_exception_explorer.rb
View
2 Gemfile
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
View
15 Rakefile
@@ -15,7 +15,7 @@ CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake",
def apply_spec_defaults(s)
s.name = PROJECT_NAME
- s.summary = "FIX ME"
+ s.summary = "Enter the context of exceptions"
s.version = PryExceptionExplorer::VERSION
s.date = Time.now.strftime '%Y-%m-%d'
s.author = "John Mair (banisterfiend)"
@@ -24,7 +24,11 @@ def apply_spec_defaults(s)
s.require_path = 'lib'
s.homepage = "https://github.com/banister/pry-exception_explorer"
s.add_dependency('pry-stack_explorer')
- s.files = Dir["lib/**/*.rb", "test/*.rb", "CHANGELOG", "README.md", "Rakefile"]
+ s.add_development_dependency("bacon","~>1.1.0")
+ s.add_development_dependency('rake', '~> 0.9')
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- test/*`.split("\n")
end
desc "run pry with plugin enabled"
@@ -54,6 +58,13 @@ namespace :ruby do
pkg.need_zip = false
pkg.need_tar = false
end
+
+ desc "Generate gemspec file"
+ task :gemspec do
+ File.open("#{spec.name}.gemspec", "w") do |f|
+ f << spec.to_ruby
+ end
+ end
end
desc "shorthand for :gems task"
View
36 test/helper.rb
@@ -11,3 +11,39 @@
puts "Ruby version: #{RUBY_VERSION}"
EE = PryExceptionExplorer
+
+# override enter_exception_inline so we can use it for testing purposes
+EE.instance_eval do
+ alias original_enter_exception_inline enter_exception_inline
+end
+
+def EE.exception_intercepted?
+ @exception_intercepted
+end
+
+EE.instance_eval do
+ @exception_intercepted = false
+end
+
+def EE.enter_exception_inline(ex)
+ @exception_intercepted = true
+ EE::CONTINUE_INLINE_EXCEPTION
+end
+
+class Ratty
+ def ratty
+ Weasel.new.weasel
+ end
+end
+
+class Weasel
+ def weasel
+ Toad.new.toad
+ end
+end
+
+class Toad
+ def toad
+ raise "toad hall"
+ end
+end
View
84 test/test_exception_explorer.rb
@@ -1,31 +1,7 @@
require 'helper'
-EE.instance_eval do
- alias original_enter_exception_inline enter_exception_inline
-end
-
-def EE.exception_intercepted?
- @exception_intercepted
-end
-
-EE.instance_eval do
- @exception_intercepted = false
-end
-
-def EE.enter_exception_inline(ex)
- @exception_intercepted = true
- EE::CONTINUE_INLINE_EXCEPTION
-end
-
describe PryExceptionExplorer do
- before do
- @o = Object.new
- def @o.ratty() weasel() end
- def @o.weasel() toad() end
- def @o.toad() raise "toad hall" end
- end
-
after do
EE.instance_eval do
@exception_intercepted = false
@@ -34,20 +10,58 @@ def @o.toad() raise "toad hall" end
describe "PryExceptionExplorer#intercept" do
describe "method_name" do
- it "should intercept exception based on first frame's method name" do
- EE.intercept { |frame, ex| frame.method_name == :toad }
- @o.toad
- EE.exception_intercepted?.should == true
+ describe "first frame" do
+ it "should intercept exception based on first frame's method name" do
+ EE.intercept { |frame, ex| frame.method_name == :toad }
+ Ratty.new.ratty
+ EE.exception_intercepted?.should == true
+ end
+
+ it "should NOT intercept exception if method name doesn't match" do
+ EE.intercept { |frame, ex| frame.method_name == :ratty }
+ begin
+ Ratty.new.ratty
+ rescue Exception => ex
+ ex.is_a?(RuntimeError).should == true
+ end
+ EE.exception_intercepted?.should == false
+ end
+ end
+
+ describe "second frame" do
+ it "should intercept exception based on second frame's method name" do
+ EE.intercept { |frame, ex| frame.prev.method_name == :weasel }
+ Ratty.new.ratty
+ EE.exception_intercepted?.should == true
+ end
+
+ it "should NOT intercept exception if method name doesn't match" do
+ EE.intercept { |frame, ex| frame.prev.method_name == :toad }
+ begin
+ Ratty.new.ratty
+ rescue Exception => ex
+ ex.is_a?(RuntimeError).should == true
+ end
+ EE.exception_intercepted?.should == false
+ end
end
- it "should NOT intercept exception if method name doesn't match" do
- EE.intercept { |frame, ex| frame.method_name == :ratty }
- begin
- @o.toad
- rescue Exception => ex
- ex.is_a?(RuntimeError).should == true
+ describe "third frame" do
+ it "should intercept exception based on third frame's method name" do
+ EE.intercept { |frame, ex| frame.prev.prev.method_name == :ratty }
+ Ratty.new.ratty
+ EE.exception_intercepted?.should == true
+ end
+
+ it "should NOT intercept exception if method name doesn't match" do
+ EE.intercept { |frame, ex| frame.prev.prev.method_name == :toad }
+ begin
+ Ratty.new.ratty
+ rescue Exception => ex
+ ex.is_a?(RuntimeError).should == true
+ end
+ EE.exception_intercepted?.should == false
end
- EE.exception_intercepted?.should == false
end
end

0 comments on commit 501547c

Please sign in to comment.