aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/testing
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-06-05 20:39:26 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2012-06-05 20:43:41 +0100
commit870310db6a9f3c4ef70831cbc31271d567c90137 (patch)
tree43f517de355c68369d583885f0c34de187204bed /activesupport/test/testing
parent9b742fd64d17072a2e76e73d4967aeef8eb442dd (diff)
downloadrails-870310db6a9f3c4ef70831cbc31271d567c90137.tar.gz
rails-870310db6a9f3c4ef70831cbc31271d567c90137.tar.bz2
rails-870310db6a9f3c4ef70831cbc31271d567c90137.zip
Eliminate dependency on Rails::VERSION::STRING
To facilitate the use of ActiveSupport::Testing::Performance outside of a Rails application conditionally check for the presence of Rails::VERSION::STRING before including it in the environment string.
Diffstat (limited to 'activesupport/test/testing')
-rw-r--r--activesupport/test/testing/performance_test.rb23
1 files changed, 21 insertions, 2 deletions
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