Module ActiveSupport::Testing
In: vendor/rails/activesupport/lib/active_support/testing/default.rb
vendor/rails/activesupport/lib/active_support/testing/performance.rb
vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb

Methods

Included Modules

ActiveSupport::Callbacks

Classes and Modules

Module ActiveSupport::Testing::Metrics
Module ActiveSupport::Testing::Performance
Module ActiveSupport::Testing::SetupAndTeardown
Class ActiveSupport::Testing::Benchmarker
Class ActiveSupport::Testing::Performer
Class ActiveSupport::Testing::Profiler

Public Class methods

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 26
26:       def self.included(base)
27:         base.superclass_delegating_accessor :profile_options
28:         base.profile_options = DEFAULTS
29:       end

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb, line 12
12:       def self.included(base)
13:         base.class_eval do
14:           include ActiveSupport::Callbacks
15:           define_callbacks :setup, :teardown
16: 
17:           if defined?(::Mini)
18:             undef_method :run
19:             alias_method :run, :run_with_callbacks_and_miniunit
20:           else
21:             begin
22:               require 'mocha'
23:               undef_method :run
24:               alias_method :run, :run_with_callbacks_and_mocha
25:             rescue LoadError
26:               undef_method :run
27:               alias_method :run, :run_with_callbacks_and_testunit
28:             end
29:           end
30:         end
31:       end

Public Instance methods

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 31
31:       def full_test_name
32:         "#{self.class.name}##{method_name}"
33:       end

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 35
35:       def run(result)
36:         return if method_name =~ /^default_test$/
37: 
38:         yield(self.class::STARTED, name)
39:         @_result = result
40: 
41:         run_warmup
42:         if profile_options && metrics = profile_options[:metrics]
43:           metrics.each do |metric_name|
44:             if klass = Metrics[metric_name.to_sym]
45:               run_profile(klass.new)
46:               result.add_run
47:             end
48:           end
49:         end
50: 
51:         yield(self.class::FINISHED, name)
52:       end

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 54
54:       def run_test(metric, mode)
55:         run_callbacks :setup
56:         setup
57:         metric.send(mode) { __send__ @method_name }
58:       rescue ::Test::Unit::AssertionFailedError => e
59:         add_failure(e.message, e.backtrace)
60:       rescue StandardError, ScriptError
61:         add_error($!)
62:       ensure
63:         begin
64:           teardown
65:           run_callbacks :teardown, :enumerator => :reverse_each
66:         rescue ::Test::Unit::AssertionFailedError => e
67:           add_failure(e.message, e.backtrace)
68:         rescue StandardError, ScriptError
69:           add_error($!)
70:         end
71:       end

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb, line 33
33:       def run_with_callbacks_and_miniunit(runner)
34:         result = '.'
35:         begin
36:           run_callbacks :setup
37:           result = super
38:         rescue Exception => e
39:           result = runner.puke(self.class, self.name, e)
40:         ensure
41:           begin
42:             teardown
43:             run_callbacks :teardown, :enumerator => :reverse_each
44:           rescue Exception => e
45:             result = runner.puke(self.class, self.name, e)
46:           end
47:         end
48:         result
49:       end

Doubly unfortunate: mocha does the same so we have to hax their hax.

[Source]

     # File vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb, line 84
 84:       def run_with_callbacks_and_mocha(result)
 85:         return if @method_name.to_s == "default_test"
 86: 
 87:         yield(Test::Unit::TestCase::STARTED, name)
 88:         @_result = result
 89:         begin
 90:           mocha_setup
 91:           begin
 92:             run_callbacks :setup
 93:             setup
 94:             __send__(@method_name)
 95:             mocha_verify { add_assertion }
 96:           rescue Mocha::ExpectationError => e
 97:             add_failure(e.message, e.backtrace)
 98:           rescue Test::Unit::AssertionFailedError => e
 99:             add_failure(e.message, e.backtrace)
100:           rescue StandardError, ScriptError
101:             add_error($!)
102:           ensure
103:             begin
104:               teardown
105:               run_callbacks :teardown, :enumerator => :reverse_each
106:             rescue Test::Unit::AssertionFailedError => e
107:               add_failure(e.message, e.backtrace)
108:             rescue StandardError, ScriptError
109:               add_error($!)
110:             end
111:           end
112:         ensure
113:           mocha_teardown
114:         end
115:         result.add_run
116:         yield(Test::Unit::TestCase::FINISHED, name)
117:       end

Protected Instance methods

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 84
84:         def run_profile(metric)
85:           klass = profile_options[:benchmark] ? Benchmarker : Profiler
86:           performer = klass.new(self, metric)
87: 
88:           performer.run
89:           puts performer.report
90:           performer.record
91:         end

[Source]

    # File vendor/rails/activesupport/lib/active_support/testing/performance.rb, line 74
74:         def run_warmup
75:           GC.start
76: 
77:           time = Metrics::Time.new
78:           run_test(time, :benchmark)
79:           puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
80: 
81:           GC.start
82:         end

[Validate]