aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-11-08 05:29:44 +0000
committerRick Olson <technoweenie@gmail.com>2007-11-08 05:29:44 +0000
commitf1b1af88b530c101dc4bf6157bbd1f9c39a670d7 (patch)
tree76fc9e3e3ed72d6867ab5408decfd8651f5a49e8 /railties/test
parentc443a6199a9245047f8f4f114b933c785bd3fa55 (diff)
downloadrails-f1b1af88b530c101dc4bf6157bbd1f9c39a670d7.tar.gz
rails-f1b1af88b530c101dc4bf6157bbd1f9c39a670d7.tar.bz2
rails-f1b1af88b530c101dc4bf6157bbd1f9c39a670d7.zip
Refactor Plugin Loader. Add plugin lib paths early, and add lots of tests. Closes #9795 [lazyatom]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8115 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/initializer_test.rb81
-rw-r--r--railties/test/plugin_loader_test.rb198
-rw-r--r--railties/test/plugin_locator_test.rb106
-rw-r--r--railties/test/plugin_test.rb130
-rw-r--r--railties/test/plugin_test_helper.rb23
5 files changed, 409 insertions, 129 deletions
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 5707a63258..156f670e87 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -135,3 +135,84 @@ uses_mocha 'framework paths' do
end
end
end
+
+uses_mocha "Initializer plugin loading tests" do
+ require File.dirname(__FILE__) + '/plugin_test_helper'
+
+ class InitializerPluginLoadingTests < Test::Unit::TestCase
+ def setup
+ @configuration = Rails::Configuration.new
+ @configuration.plugin_paths << plugin_fixture_root_path
+ @initializer = Rails::Initializer.new(@configuration)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
+
+ def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
+ only_load_the_following_plugins! []
+ @initializer.load_plugins
+ assert_equal [], @initializer.loaded_plugins
+ end
+
+ def test_only_the_specified_plugins_are_located_in_the_order_listed
+ plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ assert_plugins plugin_names, @initializer.loaded_plugins
+ end
+
+ def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ load_plugins!
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
+ end
+
+ def test_all_plugins_loaded_when_all_is_used
+ plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
+ end
+
+ def test_all_plugins_loaded_after_all
+ plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip
+ end
+
+ def test_plugin_names_may_be_strings
+ plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ only_load_the_following_plugins! plugin_names
+ load_plugins!
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip
+ end
+
+ def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
+ only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
+ assert_raises(LoadError) do
+ load_plugins!
+ end
+ end
+
+ def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
+
+ @initializer.add_plugin_load_paths
+
+ assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
+ end
+
+ private
+
+ def load_plugins!
+ @initializer.add_plugin_load_paths
+ @initializer.load_plugins
+ end
+ end
+
+end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 3c2c37e794..fe77de4474 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -1,90 +1,140 @@
require File.dirname(__FILE__) + '/plugin_test_helper'
-class TestPluginLoader < Test::Unit::TestCase
- def setup
- @initializer = Rails::Initializer.new(Rails::Configuration.new)
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
- end
-
- def test_determining_if_the_plugin_order_has_been_explicitly_set
- loader = loader_for(@valid_plugin_path)
- assert !loader.send(:explicit_plugin_loading_order?)
- only_load_the_following_plugins! %w(stubby acts_as_chunky_bacon)
- assert loader.send(:explicit_plugin_loading_order?)
- end
-
- def test_enabled_if_not_named_explicitly
- stubby_loader = loader_for(@valid_plugin_path)
- acts_as_loader = loader_for('acts_as/acts_as_chunky_bacon')
+uses_mocha "Plugin Loader Tests" do
+
+ class TestPluginLoader < Test::Unit::TestCase
+ ORIGINAL_LOAD_PATH = $LOAD_PATH.dup
- only_load_the_following_plugins! ['stubby', :all]
- assert stubby_loader.send(:enabled?)
- assert acts_as_loader.send(:enabled?)
+ def setup
+ reset_load_path!
+
+ @configuration = Rails::Configuration.new
+ @configuration.plugin_paths << plugin_fixture_root_path
+ @initializer = Rails::Initializer.new(@configuration)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+
+ @loader = Rails::Plugin::Loader.new(@initializer)
+ end
+
+ def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result
+ locator_1 = stub(:plugins => [:a, :b, :c])
+ locator_2 = stub(:plugins => [:d, :e, :f])
+ locator_class_1 = stub(:new => locator_1)
+ locator_class_2 = stub(:new => locator_2)
+ @configuration.plugin_locators = [locator_class_1, locator_class_2]
+ assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins)
+ end
- assert stubby_loader.send(:explicitly_enabled?)
- assert !acts_as_loader.send(:explicitly_enabled?)
- end
-
- def test_determining_whether_a_given_plugin_is_loaded
- plugin_loader = loader_for(@valid_plugin_path)
- assert !plugin_loader.loaded?
- assert_nothing_raised do
- plugin_loader.send(:register_plugin_as_loaded)
- end
- assert plugin_loader.loaded?
- end
-
- def test_if_a_path_is_a_plugin_path
- # This is a plugin path, with a lib dir
- assert loader_for(@valid_plugin_path).plugin_path?
- # This just has an init.rb and no lib dir
- assert loader_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).plugin_path?
- # This would be a plugin path, but the directory is empty
- assert !loader_for(plugin_fixture_path('default/empty')).plugin_path?
- # This is a non sense path
- assert !loader_for(plugin_fixture_path('default/this_directory_does_not_exist')).plugin_path?
- end
-
- def test_if_you_try_to_load_a_non_plugin_path_you_get_a_load_error
- # This path is fine so nothing is raised
- assert_nothing_raised do
- loader_for(@valid_plugin_path).send(:report_nonexistant_or_empty_plugin!)
+ def test_should_memoize_the_result_of_locate_plugins_as_all_plugins
+ plugin_list = [:a, :b, :c]
+ @loader.expects(:locate_plugins).once.returns(plugin_list)
+ assert_equal plugin_list, @loader.all_plugins
+ assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again
end
- # This is an empty path so it raises
- assert_raises(LoadError) do
- loader_for(@empty_plugin_path).send(:report_nonexistant_or_empty_plugin!)
+ def test_should_return_empty_array_if_configuration_plugins_is_empty
+ @configuration.plugins = []
+ assert_equal [], @loader.plugins
end
- assert_raises(LoadError) do
- loader_for('this_is_not_a_plugin_directory').send(:report_nonexistant_or_empty_plugin!)
+ def test_should_find_all_availble_plugins_and_return_as_all_plugins
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins, failure_tip
end
- end
-
- def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs
- failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already."
- assert !defined?(StubbyMixin), failure_tip
- assert !added_to_load_path?(@valid_plugin_path)
- # The init.rb of this plugin raises if it doesn't have access to all the things it needs
- assert_nothing_raised do
- loader_for(@valid_plugin_path).load
- end
- assert added_to_load_path?(@valid_plugin_path)
- assert defined?(StubbyMixin)
- end
-
- private
- def loader_for(path, initializer = @initializer)
- Rails::Plugin::Loader.new(initializer, path)
+
+ def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip
+ end
+
+ def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil
+ @configuration.plugins = nil
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip
+ end
+
+ def test_should_return_specific_plugins_named_in_config_plugins_array_if_set
+ plugin_names = [:acts_as_chunky_bacon, :stubby]
+ only_load_the_following_plugins! plugin_names
+ assert_plugins plugin_names, @loader.plugins
+ end
+
+ def test_should_respect_the_order_of_plugins_given_in_configuration
+ plugin_names = [:stubby, :acts_as_chunky_bacon]
+ only_load_the_following_plugins! plugin_names
+ assert_plugins plugin_names, @loader.plugins
+ end
+
+ def test_should_load_all_plugins_in_natural_order_when_all_is_used
+ only_load_the_following_plugins! [:all]
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip
end
- def plugin_fixture_path(path)
- File.join(plugin_fixture_root_path, path)
+ def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all]
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, failure_tip
end
- def added_to_load_path?(path)
- $LOAD_PATH.grep(/#{path}/).size == 1
+ def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all
+ only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon]
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, failure_tip
+ end
+
+ def test_should_accept_plugin_names_given_as_strings
+ only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, failure_tip
+ end
+
+ def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
+ stubbed_application_lib_index_in_LOAD_PATHS = 5
+ @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS)
+
+ @loader.add_plugin_load_paths
+
+ assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
+ assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
+ end
+
+ def test_should_add_plugin_load_paths_to_Dependencies_load_paths
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
+
+ @loader.add_plugin_load_paths
+
+ assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
end
+ def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
+
+ @loader.add_plugin_load_paths
+
+ assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
+ end
+
+ def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array
+ plugin_load_paths = ["a", "b"]
+ plugin = stub(:load_paths => plugin_load_paths)
+ @loader.stubs(:plugins).returns([plugin])
+
+ @loader.add_plugin_load_paths
+
+ plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) }
+ end
+
+ private
+
+ def reset_load_path!
+ $LOAD_PATH.clear
+ ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path }
+ end
+ end
+
end \ No newline at end of file
diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb
index 3ac4493d47..ccd270dd10 100644
--- a/railties/test/plugin_locator_test.rb
+++ b/railties/test/plugin_locator_test.rb
@@ -1,61 +1,69 @@
require File.dirname(__FILE__) + '/plugin_test_helper'
-class TestPluginFileSystemLocator < Test::Unit::TestCase
- def setup
- configuration = Rails::Configuration.new
- # We need to add our testing plugin directory to the plugin paths so
- # the locator knows where to look for our plugins
- configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.new(configuration)
- @locator = new_locator
- end
+uses_mocha "Plugin Locator Tests" do
+
+ class PluginLocatorTest < Test::Unit::TestCase
- def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
- only_load_the_following_plugins! []
- assert_equal [], @locator.plugins
- end
+ def test_should_require_subclasses_to_implement_the_plugins_method
+ assert_raises(RuntimeError) do
+ Rails::Plugin::Locator.new(nil).plugins
+ end
+ end
- def test_only_the_specified_plugins_are_located_in_the_order_listed
- plugin_names = [:stubby, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- assert_equal plugin_names, @locator.plugin_names
- end
+ def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each
+ locator = Rails::Plugin::Locator.new(nil)
+ locator.stubs(:plugins).returns([:a, :b, :c])
+ plugin_consumer = mock
+ plugin_consumer.expects(:consume).with(:a)
+ plugin_consumer.expects(:consume).with(:b)
+ plugin_consumer.expects(:consume).with(:c)
+
+ locator.each do |plugin|
+ plugin_consumer.consume(plugin)
+ end
+ end
- def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_equal [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @locator.plugin_names, failure_tip
end
+
+
+ class PluginFileSystemLocatorTest < Test::Unit::TestCase
+ def setup
+ @configuration = Rails::Configuration.new
+ # We need to add our testing plugin directory to the plugin paths so
+ # the locator knows where to look for our plugins
+ @configuration.plugin_paths << plugin_fixture_root_path
+ @initializer = Rails::Initializer.new(@configuration)
+ @locator = Rails::Plugin::FileSystemLocator.new(@initializer)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
+
+ def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory
+ assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
+ end
- def test_all_plugins_loaded_when_all_is_used
- plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
- only_load_the_following_plugins! plugin_names
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip
- end
+ def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
+ assert_nil @locator.send(:create_plugin, @empty_plugin_path)
+ end
- def test_all_plugins_loaded_after_all
- plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_equal [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @locator.plugin_names, failure_tip
- end
+ def test_should_return_all_plugins_found_under_the_set_plugin_paths
+ assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name)
+ end
- def test_plugin_names_may_be_strings
- plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- only_load_the_following_plugins! plugin_names
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip
- end
+ def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
+ @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
+ assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name)
+
+ @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
+ assert_equal ["a"], @locator.plugins.map(&:name)
+ end
- def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
- only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
- assert_raises(LoadError) do
- @initializer.load_plugins
+ def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist
+ @configuration.plugin_paths = ["some_missing_directory"]
+ assert_nothing_raised do
+ assert @locator.plugins.empty?
+ end
end
end
-
- private
- def new_locator(initializer = @initializer)
- Rails::Plugin::FileSystemLocator.new(initializer)
- end
-end \ No newline at end of file
+
+end # uses_mocha \ No newline at end of file
diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb
new file mode 100644
index 0000000000..a791e42ae8
--- /dev/null
+++ b/railties/test/plugin_test.rb
@@ -0,0 +1,130 @@
+require File.dirname(__FILE__) + '/plugin_test_helper'
+
+uses_mocha "Plugin Tests" do
+
+ class PluginTest < Test::Unit::TestCase
+
+ def setup
+ @initializer = Rails::Initializer.new(Rails::Configuration.new)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
+
+ def test_should_determine_plugin_name_from_the_directory_of_the_plugin
+ assert_equal 'stubby', plugin_for(@valid_plugin_path).name
+ assert_equal 'empty', plugin_for(@empty_plugin_path).name
+ end
+
+ def test_should_not_be_loaded_when_created
+ assert !plugin_for(@valid_plugin_path).loaded?
+ end
+
+ def test_should_be_marked_as_loaded_when_load_is_called
+ plugin = plugin_for(@valid_plugin_path)
+ assert !plugin.loaded?
+ plugin.stubs(:evaluate_init_rb)
+ assert_nothing_raised do
+ plugin.send(:load, anything)
+ end
+ assert plugin.loaded?
+ end
+
+ def test_should_determine_validity_of_given_path
+ # This is a plugin path, with a lib dir
+ assert plugin_for(@valid_plugin_path).valid?
+ # This just has an init.rb and no lib dir
+ assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid?
+ # This would be a plugin path, but the directory is empty
+ assert !plugin_for(plugin_fixture_path('default/empty')).valid?
+ # This is a non sense path
+ assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid?
+ end
+
+ def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory
+ assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths
+ end
+
+ def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory
+ expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib')
+ assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin
+ assert_nothing_raised do
+ plugin_for(@valid_plugin_path).load_paths
+ end
+
+ assert_raises(LoadError) do
+ plugin_for(@empty_plugin_path).load_paths
+ end
+
+ assert_raises(LoadError) do
+ plugin_for('this_is_not_a_plugin_directory').load_paths
+ end
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ plugin = plugin_for(@valid_plugin_path)
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
+ end
+
+ # This is an empty path so it raises
+ assert_raises(LoadError) do
+ plugin = plugin_for(@empty_plugin_path)
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
+ end
+
+ assert_raises(LoadError) do
+ plugin = plugin_for('this_is_not_a_plugin_directory')
+ plugin.stubs(:evaluate_init_rb)
+ plugin.send(:load, @initializer)
+ end
+ end
+
+ def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ plugin_for(@valid_plugin_path).load_paths
+ end
+
+ # This is an empty path so it raises
+ assert_raises(LoadError) do
+ plugin_for(@empty_plugin_path).load_paths
+ end
+
+ assert_raises(LoadError) do
+ plugin_for('this_is_not_a_plugin_directory').load_paths
+ end
+ end
+
+ def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs
+ failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already."
+ assert !defined?(StubbyMixin), failure_tip
+ plugin = plugin_for(@valid_plugin_path)
+ plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) }
+ # The init.rb of this plugin raises if it doesn't have access to all the things it needs
+ assert_nothing_raised do
+ plugin.load(@initializer)
+ end
+ assert defined?(StubbyMixin)
+ end
+
+ def test_should_sort_naturally_by_name
+ a = plugin_for("path/a")
+ b = plugin_for("path/b")
+ z = plugin_for("path/z")
+ assert_equal [a, b, z], [b, z, a].sort
+ end
+
+ private
+
+ def plugin_for(path)
+ Rails::Plugin.new(path)
+ end
+ end
+
+end # uses_mocha \ No newline at end of file
diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb
index 0b065a5444..f8c094d19f 100644
--- a/railties/test/plugin_test_helper.rb
+++ b/railties/test/plugin_test_helper.rb
@@ -4,15 +4,26 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib"
require 'test/unit'
require 'active_support'
require 'initializer'
+require File.join(File.dirname(__FILE__), 'abstract_unit')
# We need to set RAILS_ROOT if it isn't already set
RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
+
class Test::Unit::TestCase
- def plugin_fixture_root_path
- File.join(File.dirname(__FILE__), 'fixtures', 'plugins')
- end
+ private
+ def plugin_fixture_root_path
+ File.join(File.dirname(__FILE__), 'fixtures', 'plugins')
+ end
+
+ def only_load_the_following_plugins!(plugins)
+ @initializer.configuration.plugins = plugins
+ end
- def only_load_the_following_plugins!(plugins)
- @initializer.configuration.plugins = plugins
- end
+ def plugin_fixture_path(path)
+ File.join(plugin_fixture_root_path, path)
+ end
+
+ def assert_plugins(list_of_names, array_of_plugins, message=nil)
+ assert_equal list_of_names.map(&:to_s), array_of_plugins.map(&:name), message
+ end
end \ No newline at end of file