test/test_helper.rb in newrelic_rpm-2.12.3 vs test/test_helper.rb in newrelic_rpm-2.13.0.beta3
- old
+ new
@@ -1,17 +1,36 @@
module NewRelic; TEST = true; end unless defined? NewRelic::TEST
-#ENV['NEWRELIC_ENABLE'] = 'true'
ENV['RAILS_ENV'] = 'test'
NEWRELIC_PLUGIN_DIR = File.expand_path(File.join(File.dirname(__FILE__),".."))
$LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"test")
$LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"ui/helpers")
$LOAD_PATH.uniq!
-require File.expand_path(File.join(NEWRELIC_PLUGIN_DIR, "..","..","..","config","environment"))
-
-require 'test_help'
-require 'mocha'
+require 'rubygems'
+# We can speed things up in tests that don't need to load rails.
+# You can also run the tests in a mode without rails. Many tests
+# will be skipped.
+if ENV['SKIP_RAILS']
+ dirs = File.dirname(__FILE__).split('/')
+ while dirs.any? && !File.directory?((dirs+%w[log]).join('/'))
+ dirs.pop
+ end
+ RAILS_ROOT = dirs.any? ? dirs.join("/") : "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+ $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR, "lib")
+ require File.join(NEWRELIC_PLUGIN_DIR, "lib/newrelic_rpm")
+else
+ begin
+ require File.expand_path("../../../config/environment", NEWRELIC_PLUGIN_DIR)
+ require 'test_help'
+ rescue LoadError
+ puts "Unable to load Rails for New Relic tests: try setting the environment variable SKIP_RAILS=false"
+ raise
+ end
+end
require 'test/unit'
+require 'mocha'
+require 'shoulda'
+require 'test_contexts'
def assert_between(floor, ceiling, value, message = nil)
assert floor <= value && value <= ceiling,
message || "expected #{floor} <= #{value} <= #{ceiling}"
end