Upgraded Rails
[monkeycharger.git] / vendor / rails / railties / test / plugin_locator_test.rb
blobccd270dd10a0a8d48946bb5852dff3c0e5d40aa8
1 require File.dirname(__FILE__) + '/plugin_test_helper'
3 uses_mocha "Plugin Locator Tests" do
5   class PluginLocatorTest < Test::Unit::TestCase
6   
7     def test_should_require_subclasses_to_implement_the_plugins_method
8       assert_raises(RuntimeError) do
9         Rails::Plugin::Locator.new(nil).plugins
10       end
11     end
12   
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)
20     
21       locator.each do |plugin|
22         plugin_consumer.consume(plugin)
23       end
24     end
25   
26   end
29   class PluginFileSystemLocatorTest < Test::Unit::TestCase
30     def setup
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')
39     end
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)  
43     end
44   
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)  
47     end
48   
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)
51     end
52   
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)
56     
57       @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
58       assert_equal ["a"], @locator.plugins.map(&:name)
59     end
60   
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?
65       end
66     end
67   end
69 end # uses_mocha