aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/assertions.rb28
-rw-r--r--actionpack/test/controller/test_test.rb32
2 files changed, 39 insertions, 21 deletions
diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb
index f52076e863..956e5da140 100644
--- a/actionpack/lib/action_controller/assertions.rb
+++ b/actionpack/lib/action_controller/assertions.rb
@@ -9,7 +9,7 @@ module ActionController #:nodoc:
# * session: Objects being saved in the session.
# * flash: The flash objects currently in the session.
# * cookies: Cookies being sent to the user on this request.
- #
+ #
# These collections can be used just like any other hash:
#
# assert_not_nil assigns(:person) # makes sure that a @person instance variable was set
@@ -40,37 +40,27 @@ module ActionController #:nodoc:
# == Testing named routes
#
# If you're using named routes, they can be easily tested using the original named routes methods straight in the test case.
- # Example:
+ # Example:
#
# assert_redirected_to page_url(:title => 'foo')
module Assertions
def self.included(klass)
- klass.class_eval do
- include ActionController::Assertions::ResponseAssertions
- include ActionController::Assertions::SelectorAssertions
- include ActionController::Assertions::RoutingAssertions
- include ActionController::Assertions::TagAssertions
- include ActionController::Assertions::DomAssertions
- include ActionController::Assertions::ModelAssertions
+ %w(response selector tag dom routing model).each do |kind|
+ require "action_controller/assertions/#{kind}_assertions"
+ klass.send :include, const_get("#{kind.camelize}Assertions")
end
end
def clean_backtrace(&block)
yield
- rescue Test::Unit::AssertionFailedError => e
- path = File.expand_path(__FILE__)
- raise Test::Unit::AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
+ rescue Test::Unit::AssertionFailedError => error
+ framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
+ raise
end
end
end
-require File.dirname(__FILE__) + '/assertions/response_assertions'
-require File.dirname(__FILE__) + '/assertions/selector_assertions'
-require File.dirname(__FILE__) + '/assertions/tag_assertions'
-require File.dirname(__FILE__) + '/assertions/dom_assertions'
-require File.dirname(__FILE__) + '/assertions/routing_assertions'
-require File.dirname(__FILE__) + '/assertions/model_assertions'
-
module Test #:nodoc:
module Unit #:nodoc:
class TestCase #:nodoc:
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 2b0086c5f4..ab44fbf3ca 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../abstract_unit'
-require File.dirname(__FILE__) + '/fake_controllers'
+require "#{File.dirname(__FILE__)}/../abstract_unit"
+require "#{File.dirname(__FILE__)}/fake_controllers"
class TestTest < Test::Unit::TestCase
class TestController < ActionController::Base
@@ -493,3 +493,31 @@ HTML
end
end
end
+
+
+class CleanBacktraceTest < Test::Unit::TestCase
+ def test_should_reraise_the_same_object
+ exception = Test::Unit::AssertionFailedError.new('message')
+ clean_backtrace { raise exception }
+ rescue => caught
+ assert_equal exception.object_id, caught.object_id
+ assert_equal exception.message, caught.message
+ end
+
+ def test_should_clean_assertion_lines_from_backtrace
+ path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller")
+ exception = Test::Unit::AssertionFailedError.new('message')
+ exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
+ clean_backtrace { raise exception }
+ rescue => caught
+ assert_equal ["#{path}/abc"], caught.backtrace
+ end
+
+ def test_should_only_clean_assertion_failure_errors
+ clean_backtrace do
+ raise "can't touch this", [File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller/assertions/abc")]
+ end
+ rescue => caught
+ assert !caught.backtrace.empty?
+ end
+end