From 93580f49361210903a4e9cfa34a89da8ddb15815 Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 3 Dec 2011 09:41:03 -0500 Subject: Test return value of ActiveSupport::Dependencies::Loadable#require - Add tests to protect from regressions in require's return value behavior - See a10606c490471d8e1483acb3b31d7f2d51e9ebbe (require needs to return true or false) for the original bug fix --- activesupport/test/dependencies_test.rb | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'activesupport/test/dependencies_test.rb') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index fe8f51e11a..6dc303ea86 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -258,6 +258,53 @@ 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('autoloading_fixtures/load_path') 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('autoloading_fixtures/load_path') 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('autoloading_fixtures/load_path') do + require 'loaded_constant' + assert_equal false, require('loaded_constant') + end + ensure + remove_constants(:LoadedConstant) + $".replace(original_features) + $:.replace(original_path) + end + def failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) -- cgit v1.2.3 From 0a485309a03bdf290d3c42186916dac5e900db65 Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 3 Dec 2011 12:58:31 -0500 Subject: Test return value of ActiveSupport::Dependencies::Loadable#load --- activesupport/test/dependencies_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activesupport/test/dependencies_test.rb') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 6dc303ea86..94e7e118ff 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -305,6 +305,22 @@ class DependenciesTest < Test::Unit::TestCase $:.replace(original_path) 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('autoloading_fixtures/load_path') 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 failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) -- cgit v1.2.3 From 2a9f0630822f60adfb418c34ec9cea30a2a716ed Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 3 Dec 2011 13:08:18 -0500 Subject: Test that require and load raise LoadError if file not found --- activesupport/test/dependencies_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activesupport/test/dependencies_test.rb') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 94e7e118ff..3a7922d219 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -305,6 +305,14 @@ class DependenciesTest < Test::Unit::TestCase $:.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 @@ -321,6 +329,14 @@ class DependenciesTest < Test::Unit::TestCase $:.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) -- cgit v1.2.3 From cfc467f73e801717325b4addef4fa05798462d5c Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 3 Dec 2011 13:10:58 -0500 Subject: Simplify load and require tests - These tests don't use autoloading so there's no need to add anything to autoload_paths --- activesupport/test/dependencies_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport/test/dependencies_test.rb') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 3a7922d219..7039f90499 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -264,7 +264,7 @@ class DependenciesTest < Test::Unit::TestCase original_features = $".dup $:.push(path) - with_loading('autoloading_fixtures/load_path') do + with_loading do assert_equal true, require('loaded_constant') end ensure @@ -279,7 +279,7 @@ class DependenciesTest < Test::Unit::TestCase original_features = $".dup $:.push(path) - with_loading('autoloading_fixtures/load_path') do + with_loading do Object.module_eval "module LoadedConstant; end" assert_equal true, require('loaded_constant') end @@ -295,7 +295,7 @@ class DependenciesTest < Test::Unit::TestCase original_features = $".dup $:.push(path) - with_loading('autoloading_fixtures/load_path') do + with_loading do require 'loaded_constant' assert_equal false, require('loaded_constant') end @@ -319,7 +319,7 @@ class DependenciesTest < Test::Unit::TestCase original_features = $".dup $:.push(path) - with_loading('autoloading_fixtures/load_path') do + with_loading do assert_equal true, load('loaded_constant.rb') assert_equal true, load('loaded_constant.rb') end -- cgit v1.2.3