1 require File.dirname(__FILE__) + '/plugin_test_helper'
3 uses_mocha "Plugin Locator Tests" do
5 class PluginLocatorTest < Test::Unit::TestCase
7 def test_should_require_subclasses_to_implement_the_plugins_method
8 assert_raises(RuntimeError) do
9 Rails::Plugin::Locator.new(nil).plugins
13 def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each
14 locator = Rails::Plugin::Locator.new(nil)
15 locator.stubs(:plugins).returns([:a, :b, :c])
16 plugin_consumer = mock
17 plugin_consumer.expects(:consume).with(:a)
18 plugin_consumer.expects(:consume).with(:b)
19 plugin_consumer.expects(:consume).with(:c)
21 locator.each do |plugin|
22 plugin_consumer.consume(plugin)
29 class PluginFileSystemLocatorTest < Test::Unit::TestCase
31 @configuration = Rails::Configuration.new
32 # We need to add our testing plugin directory to the plugin paths so
33 # the locator knows where to look for our plugins
34 @configuration.plugin_paths << plugin_fixture_root_path
35 @initializer = Rails::Initializer.new(@configuration)
36 @locator = Rails::Plugin::FileSystemLocator.new(@initializer)
37 @valid_plugin_path = plugin_fixture_path('default/stubby')
38 @empty_plugin_path = plugin_fixture_path('default/empty')
41 def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory
42 assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
45 def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
46 assert_nil @locator.send(:create_plugin, @empty_plugin_path)
49 def test_should_return_all_plugins_found_under_the_set_plugin_paths
50 assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name)
53 def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
54 @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
55 assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name)
57 @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
58 assert_equal ["a"], @locator.plugins.map(&:name)
61 def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist
62 @configuration.plugin_paths = ["some_missing_directory"]
63 assert_nothing_raised do
64 assert @locator.plugins.empty?