aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/dependencies_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-23 21:31:51 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-23 21:31:51 +0000
commitb94d6c06549b83aa2e97fa80d86f99ee81729775 (patch)
treece729d0b044b0c85a13b24d9f4ef4b5bf2181d05 /activesupport/test/dependencies_test.rb
parentc66ac2102be2d7a53872c7bb96939f616275010e (diff)
downloadrails-b94d6c06549b83aa2e97fa80d86f99ee81729775.tar.gz
rails-b94d6c06549b83aa2e97fa80d86f99ee81729775.tar.bz2
rails-b94d6c06549b83aa2e97fa80d86f99ee81729775.zip
Enable warnings on first load only. File which are loaded but raise an exception are not added to loaded set.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/dependencies_test.rb')
-rw-r--r--activesupport/test/dependencies_test.rb67
1 files changed, 60 insertions, 7 deletions
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 767795f6ac..a59b0284a9 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -7,23 +7,76 @@ class DependenciesTest < Test::Unit::TestCase
Dependencies.clear
end
- def test_require_dependency
+ def test_tracking_loaded_files
require_dependency(File.dirname(__FILE__) + "/dependencies/service_one")
require_dependency(File.dirname(__FILE__) + "/dependencies/service_two")
assert_equal 2, Dependencies.loaded.size
end
-
- def test_require_dependency_two_times
+
+ def test_tracking_identical_loaded_files
require_dependency(File.dirname(__FILE__) + "/dependencies/service_one")
require_dependency(File.dirname(__FILE__) + "/dependencies/service_one")
assert_equal 1, Dependencies.loaded.size
end
- def test_require_missing_dependency
+ def test_missing_dependency_raises_missing_source_file
assert_raises(MissingSourceFile) { require_dependency("missing_service") }
end
-
- def test_require_missing_association
+
+ def test_missing_association_raises_nothing
assert_nothing_raised { require_association("missing_model") }
end
-end \ No newline at end of file
+
+ def test_dependency_which_raises_exception_isnt_added_to_loaded_set
+ old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load
+
+ filename = "#{File.dirname(__FILE__)}/dependencies/raises_exception"
+ $raises_exception_load_count = 0
+
+ 5.times do |count|
+ assert_raises(RuntimeError) { require_dependency filename }
+ assert_equal count + 1, $raises_exception_load_count
+
+ assert !Dependencies.loaded.include?(filename)
+ assert !Dependencies.history.include?(filename)
+ end
+ ensure
+ Dependencies.mechanism = old_mechanism
+ end
+
+ def test_warnings_should_be_enabled_on_first_load
+ old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load
+
+ filename = "#{File.dirname(__FILE__)}/dependencies/check_warnings"
+ $check_warnings_load_count = 0
+
+ assert !Dependencies.loaded.include?(filename)
+ assert !Dependencies.history.include?(filename)
+
+ silence_warnings { require_dependency filename }
+ assert_equal 1, $check_warnings_load_count
+ assert_equal true, $checked_verbose, 'On first load warnings should be enabled.'
+
+ assert Dependencies.loaded.include?(filename)
+ Dependencies.clear
+ assert !Dependencies.loaded.include?(filename)
+ assert Dependencies.history.include?(filename)
+
+ silence_warnings { require_dependency filename }
+ assert_equal 2, $check_warnings_load_count
+ assert_equal nil, $checked_verbose, 'After first load warnings should be left alone.'
+
+ assert Dependencies.loaded.include?(filename)
+ Dependencies.clear
+ assert !Dependencies.loaded.include?(filename)
+ assert Dependencies.history.include?(filename)
+
+ enable_warnings { require_dependency filename }
+ assert_equal 3, $check_warnings_load_count
+ assert_equal true, $checked_verbose, 'After first load warnings should be left alone.'
+
+ assert Dependencies.loaded.include?(filename)
+ ensure
+ Dependencies.mechanism = old_mechanism
+ end
+end