diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-04 11:22:09 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-04 11:22:09 -0800 |
commit | c24928c3add46e8d55bc246fbc6cdb6fd8f59d30 (patch) | |
tree | 3a31050c2e0977395ae3e587cee2ceb750c49b79 /activesupport/test | |
parent | 3134b467f0436da22d007659a667ac48c3c7ebb0 (diff) | |
parent | cfc467f73e801717325b4addef4fa05798462d5c (diff) | |
download | rails-c24928c3add46e8d55bc246fbc6cdb6fd8f59d30.tar.gz rails-c24928c3add46e8d55bc246fbc6cdb6fd8f59d30.tar.bz2 rails-c24928c3add46e8d55bc246fbc6cdb6fd8f59d30.zip |
Merge pull request #3845 from sumbach/test-return-value-from-require
Add tests for the return value of require
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/dependencies_test.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index fe8f51e11a..7039f90499 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -258,6 +258,85 @@ class DependenciesTest < Test::Unit::TestCase $:.replace(original_path) end + def test_require_returns_true_when_file_not_yet_required + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_loading do + assert_equal true, require('loaded_constant') + end + ensure + remove_constants(:LoadedConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_require_returns_true_when_file_not_yet_required_even_when_no_new_constants_added + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_loading do + Object.module_eval "module LoadedConstant; end" + assert_equal true, require('loaded_constant') + end + ensure + remove_constants(:LoadedConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_require_returns_false_when_file_already_required + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_loading do + require 'loaded_constant' + assert_equal false, require('loaded_constant') + end + ensure + remove_constants(:LoadedConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_require_raises_load_error_when_file_not_found + with_loading do + assert_raise(LoadError) { require 'this_file_dont_exist_dude' } + end + ensure + remove_constants(:LoadedConstant) + end + + def test_load_returns_true_when_file_found + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_loading do + assert_equal true, load('loaded_constant.rb') + assert_equal true, load('loaded_constant.rb') + end + ensure + remove_constants(:LoadedConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_load_raises_load_error_when_file_not_found + with_loading do + assert_raise(LoadError) { load 'this_file_dont_exist_dude.rb' } + end + ensure + remove_constants(:LoadedConstant) + end + def failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) |