mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Fix Test::Unit::TestCase#clean_backtrace
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6056 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user