aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-07-02 16:03:41 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-07-02 16:03:41 -0700
commit1d280e21a19aff74e1b35779be2633e6efa511f0 (patch)
tree6bc9775d4baf60270a154602ea39294feb03238a
parent940aad225af0b963f435a0bf015daece2218d502 (diff)
downloadrails-1d280e21a19aff74e1b35779be2633e6efa511f0.tar.gz
rails-1d280e21a19aff74e1b35779be2633e6efa511f0.tar.bz2
rails-1d280e21a19aff74e1b35779be2633e6efa511f0.zip
Adds support for def self.setup in isolation tests for setup that should be run only once in the parent
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb5
-rw-r--r--activesupport/test/isolation_test.rb17
-rw-r--r--railties/test/initializer/path_test.rb11
3 files changed, 26 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index 090e0c5c89..dd13abcd5d 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -21,6 +21,11 @@ module ActiveSupport::Testing
end
def run(result)
+ unless defined?(@@ran_class_setup)
+ self.class.setup
+ @@ran_class_setup = true
+ end
+
yield(Test::Unit::TestCase::STARTED, name)
@_result = result
diff --git a/activesupport/test/isolation_test.rb b/activesupport/test/isolation_test.rb
index b844bbb673..5a1f285476 100644
--- a/activesupport/test/isolation_test.rb
+++ b/activesupport/test/isolation_test.rb
@@ -5,6 +5,12 @@ if ENV['CHILD']
class ChildIsolationTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
+ def self.setup
+ File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "a") do |f|
+ f.puts "hello"
+ end
+ end
+
def setup
@instance = "HELLO"
end
@@ -64,6 +70,8 @@ if ENV['CHILD']
else
class ParentIsolationTest < ActiveSupport::TestCase
+ File.open(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"), "w") {}
+
ENV["CHILD"] = "1"
OUTPUT = `#{Gem.ruby} -I#{File.dirname(__FILE__)} #{File.expand_path(__FILE__)} -v`
ENV.delete("CHILD")
@@ -131,12 +139,17 @@ else
test "backtrace is printed for errors" do
assert_equal 'Error', @backtraces["test_captures_errors"][:type]
- assert_match %{isolation_test.rb:21:in `test_captures_errors'}, @backtraces["test_captures_errors"][:output]
+ assert_match %r{isolation_test.rb:\d+:in `test_captures_errors'}, @backtraces["test_captures_errors"][:output]
end
test "backtrace is printed for failures" do
assert_equal 'Failure', @backtraces["test_captures_failures"][:type]
- assert_match %{isolation_test.rb:25:in `test_captures_failures'}, @backtraces["test_captures_failures"][:output]
+ assert_match %r{isolation_test.rb:\d+:in `test_captures_failures'}, @backtraces["test_captures_failures"][:output]
+ end
+
+ test "self.setup is run only once" do
+ text = File.read(File.join(File.dirname(__FILE__), "fixtures", "isolation_test"))
+ assert_equal "hello\n", text
end
end
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index 8fbad24a73..db62796ea5 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -8,14 +8,15 @@ module Rails
def self.vendor_rails? ; false ; end
end
-# TODO: Can this be reset?
-Rails::Initializer.run do |config|
- config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
-end
-
class PathsTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
+ def self.setup
+ Rails::Initializer.run do |config|
+ config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
+ end
+ end
+
def setup
@paths = Rails::Initializer.default.config.paths
end