diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/testing/performance.rb | 41 | ||||
-rw-r--r-- | activesupport/test/core_ext/kernel_test.rb | 1 | ||||
-rw-r--r-- | activesupport/test/testing/performance_test.rb | 23 |
3 files changed, 44 insertions, 21 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index 517926c74d..a6c57cd0ff 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -1,5 +1,4 @@ require 'fileutils' -require 'rails/version' require 'active_support/concern' require 'active_support/core_ext/class/delegating_attributes' require 'active_support/core_ext/string/inflections' @@ -149,26 +148,20 @@ module ActiveSupport end def environment - unless defined? @env - app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/ - - rails = Rails::VERSION::STRING - if File.directory?('vendor/rails/.git') - Dir.chdir('vendor/rails') do - rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/ - end - end - - ruby = "#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}" - - @env = [app, rails, ruby, RUBY_PLATFORM] * ',' - end - - @env + @env ||= [].tap do |env| + env << "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/ + env << rails_version if defined?(Rails::VERSION::STRING) + env << "#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}" + env << RUBY_PLATFORM + end.join(',') end protected - HEADER = 'measurement,created_at,app,rails,ruby,platform' + if defined?(Rails::VERSION::STRING) + HEADER = 'measurement,created_at,app,rails,ruby,platform' + else + HEADER = 'measurement,created_at,app,ruby,platform' + end def with_output_file fname = output_filename @@ -186,6 +179,18 @@ module ActiveSupport def output_filename "#{super}.csv" end + + def rails_version + "rails-#{Rails::VERSION::STRING}#{rails_branch}" + end + + def rails_branch + if File.directory?('vendor/rails/.git') + Dir.chdir('vendor/rails') do + ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/ + end + end + end end module Metrics diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 99e4506be7..439bc87323 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -96,7 +96,6 @@ class KernelDebuggerTest < ActiveSupport::TestCase end def test_debugger_not_available_message_to_rails_logger - Object.send(:remove_const, :Rails) if Object.const_defined?(:Rails) rails = Class.new do def self.logger @logger ||= MockStdErr.new diff --git a/activesupport/test/testing/performance_test.rb b/activesupport/test/testing/performance_test.rb index 74d7dae9e7..53073cb8db 100644 --- a/activesupport/test/testing/performance_test.rb +++ b/activesupport/test/testing/performance_test.rb @@ -11,7 +11,7 @@ module ActiveSupport assert_equal "1", amount_metric.format(1.23) assert_equal "40,000,000", amount_metric.format(40000000) end - + def test_time_format time_metric = ActiveSupport::Testing::Performance::Metrics[:time].new assert_equal "0 ms", time_metric.format(0) @@ -21,7 +21,7 @@ module ActiveSupport assert_equal "40000.00 sec", time_metric.format(40000) assert_equal "-5000 ms", time_metric.format(-5) end - + def test_space_format space_metric = ActiveSupport::Testing::Performance::Metrics[:digital_information_unit].new assert_equal "0 Bytes", space_metric.format(0) @@ -35,6 +35,25 @@ module ActiveSupport assert_equal "91 TB", space_metric.format(10**14) assert_equal "910000 TB", space_metric.format(10**18) end + + def test_environment_format_without_rails + metric = ActiveSupport::Testing::Performance::Metrics[:time].new + benchmarker = ActiveSupport::Testing::Performance::Benchmarker.new(self, metric) + assert_equal "#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL},#{RUBY_PLATFORM}", benchmarker.environment + end + + def test_environment_format_with_rails + rails, version = Module.new, Module.new + version.const_set :STRING, "4.0.0" + rails.const_set :VERSION, version + Object.const_set :Rails, rails + + metric = ActiveSupport::Testing::Performance::Metrics[:time].new + benchmarker = ActiveSupport::Testing::Performance::Benchmarker.new(self, metric) + assert_equal "rails-4.0.0,#{RUBY_ENGINE}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL},#{RUBY_PLATFORM}", benchmarker.environment + ensure + Object.send :remove_const, :Rails + end end end end
\ No newline at end of file |