diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/exception_wrapper_test.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/actionpack/test/dispatch/exception_wrapper_test.rb b/actionpack/test/dispatch/exception_wrapper_test.rb index 3ddaa7294b..d7408164ba 100644 --- a/actionpack/test/dispatch/exception_wrapper_test.rb +++ b/actionpack/test/dispatch/exception_wrapper_test.rb @@ -10,6 +10,12 @@ module ActionDispatch end end + class BadlyDefinedError < StandardError + def backtrace + nil + end + end + setup do Rails.stubs(:root).returns(Pathname.new('.')) @@ -19,15 +25,16 @@ module ActionDispatch @environment = { 'action_dispatch.backtrace_cleaner' => cleaner } end - test '#source_extract fetches source fragments for every backtrace entry' do + test '#source_extracts fetches source fragments for every backtrace entry' do exception = TestError.new("lib/file.rb:42:in `index'") wrapper = ExceptionWrapper.new({}, exception) wrapper.expects(:source_fragment).with('lib/file.rb', 42).returns('foo') - assert_equal [ code: 'foo', file: 'lib/file.rb', line_number: 42 ], wrapper.source_extract + assert_equal [ code: 'foo', line_number: 42 ], wrapper.source_extracts end + test '#application_trace returns traces only from the application' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@environment, exception) @@ -35,6 +42,14 @@ module ActionDispatch assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace end + test '#application_trace cannot be nil' do + nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + + assert_equal [], nil_backtrace_wrapper.application_trace + assert_equal [], nil_cleaner_wrapper.application_trace + end + test '#framework_trace returns traces outside the application' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@environment, exception) @@ -42,6 +57,14 @@ module ActionDispatch assert_equal caller, wrapper.framework_trace end + test '#framework_trace cannot be nil' do + nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + + assert_equal [], nil_backtrace_wrapper.framework_trace + assert_equal [], nil_cleaner_wrapper.framework_trace + end + test '#full_trace returns application and framework traces' do exception = TestError.new(caller.prepend("lib/file.rb:42:in `index'")) wrapper = ExceptionWrapper.new(@environment, exception) @@ -49,6 +72,14 @@ module ActionDispatch assert_equal exception.backtrace, wrapper.full_trace end + test '#full_trace cannot be nil' do + nil_backtrace_wrapper = ExceptionWrapper.new(@environment, BadlyDefinedError.new) + nil_cleaner_wrapper = ExceptionWrapper.new({}, BadlyDefinedError.new) + + assert_equal [], nil_backtrace_wrapper.full_trace + assert_equal [], nil_cleaner_wrapper.full_trace + end + test '#traces returns every trace by category enumerated with an index' do exception = TestError.new("lib/file.rb:42:in `index'", "/gems/rack.rb:43:in `index'") wrapper = ExceptionWrapper.new(@environment, exception) |