aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/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/lib/active_support/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/lib/active_support/testing')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb41
1 files changed, 23 insertions, 18 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