diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-02-06 02:25:55 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-02-06 02:25:55 +0000 |
commit | b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb (patch) | |
tree | 491c3ce7d406a723e5c06e3bccf4559a0de86199 /railties/test | |
parent | 97612394672203eefd04e3b1947273a3ab4ec930 (diff) | |
parent | 96d610553e5fdaabc923835ab1f194070ddb4477 (diff) | |
download | rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.gz rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.tar.bz2 rails-b9ba2fe55059a6d9f141d1d502e16bdfd46f26cb.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/guides/files/javascripts/code_highlighter.js
railties/guides/files/javascripts/guides.js
railties/guides/files/javascripts/highlighters.js
railties/guides/files/stylesheets/main.css
railties/guides/files/stylesheets/print.css
railties/guides/files/stylesheets/reset.css
railties/guides/files/stylesheets/style.css
railties/guides/files/stylesheets/syntax.css
railties/guides/rails_guides/indexer.rb
railties/guides/source/2_2_release_notes.textile
railties/guides/source/2_3_release_notes.textile
railties/guides/source/action_controller_overview.textile
railties/guides/source/action_mailer_basics.textile
railties/guides/source/active_record_basics.textile
railties/guides/source/activerecord_validations_callbacks.textile
railties/guides/source/association_basics.textile
railties/guides/source/caching_with_rails.textile
railties/guides/source/command_line.textile
railties/guides/source/debugging_rails_applications.textile
railties/guides/source/form_helpers.textile
railties/guides/source/getting_started.textile
railties/guides/source/i18n.textile
railties/guides/source/layout.html.erb
railties/guides/source/layouts_and_rendering.textile
railties/guides/source/migrations.textile
railties/guides/source/performance_testing.textile
railties/guides/source/plugins.textile
railties/guides/source/rails_on_rack.textile
railties/guides/source/routing.textile
railties/guides/source/security.textile
railties/guides/source/testing.textile
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/abstract_unit.rb | 12 | ||||
-rw-r--r-- | railties/test/boot_test.rb | 5 | ||||
-rw-r--r-- | railties/test/console_app_test.rb | 22 | ||||
-rw-r--r-- | railties/test/gem_dependency_test.rb | 230 | ||||
-rw-r--r-- | railties/test/generators/rails_scaffold_generator_test.rb | 24 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 416 | ||||
-rw-r--r-- | railties/test/plugin_locator_test.rb | 107 | ||||
-rw-r--r-- | railties/test/plugin_test.rb | 271 |
8 files changed, 527 insertions, 560 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index b6edc03391..43736ee7ec 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -3,20 +3,18 @@ $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +require 'stringio' require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.3' + +gem 'mocha', '>= 0.9.5' require 'mocha' -require 'stringio' + require 'active_support' require 'active_support/test_case' -def uses_mocha(test_name) - yield -end - if defined?(RAILS_ROOT) RAILS_ROOT.replace File.dirname(__FILE__) else RAILS_ROOT = File.dirname(__FILE__) -end
\ No newline at end of file +end diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 7736a8f4c0..16776af098 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -2,8 +2,6 @@ require 'abstract_unit' require 'initializer' require "#{File.dirname(__FILE__)}/../environments/boot" -uses_mocha 'boot tests' do - class BootTest < Test::Unit::TestCase def test_boot_returns_if_booted Rails.expects(:booted?).returns(true) @@ -121,9 +119,6 @@ class GemBootTest < Test::Unit::TestCase end end -end # uses_mocha - - class ParseGemVersionTest < Test::Unit::TestCase def test_should_return_nil_if_no_lines_are_passed assert_equal nil, parse('') diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb index f419fe0d8d..7a5de5af8f 100644 --- a/railties/test/console_app_test.rb +++ b/railties/test/console_app_test.rb @@ -23,20 +23,18 @@ class ConsoleAppTest < Test::Unit::TestCase end end - uses_mocha 'console reload test' do - def test_reload_should_fire_preparation_callbacks - a = b = c = nil + def test_reload_should_fire_preparation_callbacks + a = b = c = nil - Dispatcher.to_prepare { a = b = c = 1 } - Dispatcher.to_prepare { b = c = 2 } - Dispatcher.to_prepare { c = 3 } - ActionController::Routing::Routes.expects(:reload) + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + ActionController::Routing::Routes.expects(:reload) - reload! + reload! - assert_equal 1, a - assert_equal 2, b - assert_equal 3, c - end + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c end end diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 6c1f0961a1..9cb02fcd06 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -6,141 +6,139 @@ end Rails::VendorGemSourceIndex.silence_spec_warnings = true -uses_mocha "Plugin Tests" do - class GemDependencyTest < Test::Unit::TestCase - def setup - @gem = Rails::GemDependency.new "xhpricotx" - @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" - @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" - @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" - @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false - end +class GemDependencyTest < Test::Unit::TestCase + def setup + @gem = Rails::GemDependency.new "xhpricotx" + @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" + @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" + @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" + @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false + end - def test_configuration_adds_gem_dependency - config = Rails::Configuration.new - config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" - assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) - end + def test_configuration_adds_gem_dependency + config = Rails::Configuration.new + config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" + assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) + end - def test_gem_creates_install_command - assert_equal %w(install xhpricotx), @gem.install_command - end + def test_gem_creates_install_command + assert_equal %w(install xhpricotx), @gem.install_command + end - def test_gem_with_source_creates_install_command - assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command - end + def test_gem_with_source_creates_install_command + assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command + end - def test_gem_with_version_creates_install_command - assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command - end + def test_gem_with_version_creates_install_command + assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command + end - def test_gem_creates_unpack_command - assert_equal %w(unpack xhpricotx), @gem.unpack_command - end + def test_gem_creates_unpack_command + assert_equal %w(unpack xhpricotx), @gem.unpack_command + end - def test_gem_with_version_unpack_install_command - # stub out specification method, or else test will fail if hpricot 0.6 isn't installed - mock_spec = mock() - mock_spec.stubs(:version).returns('0.6') - @gem_with_version.stubs(:specification).returns(mock_spec) - assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command - end + def test_gem_with_version_unpack_install_command + # stub out specification method, or else test will fail if hpricot 0.6 isn't installed + mock_spec = mock() + mock_spec.stubs(:version).returns('0.6') + @gem_with_version.stubs(:specification).returns(mock_spec) + assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command + end - def test_gem_adds_load_paths - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) - @gem.add_load_paths - end + def test_gem_adds_load_paths + @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.add_load_paths + end - def test_gem_with_version_adds_load_paths - @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s)) - @gem_with_version.add_load_paths - end + def test_gem_with_version_adds_load_paths + @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s)) + @gem_with_version.add_load_paths + end - def test_gem_loading - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) - @gem.expects(:require).with(@gem.name) - @gem.add_load_paths - @gem.load - end + def test_gem_loading + @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.expects(:require).with(@gem.name) + @gem.add_load_paths + @gem.load + end - def test_gem_with_lib_loading - @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil)) - @gem_with_lib.expects(:require).with(@gem_with_lib.lib) - @gem_with_lib.add_load_paths - @gem_with_lib.load - end + def test_gem_with_lib_loading + @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil)) + @gem_with_lib.expects(:require).with(@gem_with_lib.lib) + @gem_with_lib.add_load_paths + @gem_with_lib.load + end - def test_gem_without_lib_loading - @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil)) - @gem_without_load.expects(:require).with(@gem_without_load.lib).never - @gem_without_load.add_load_paths - @gem_without_load.load - end + def test_gem_without_lib_loading + @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil)) + @gem_without_load.expects(:require).with(@gem_without_load.lib).never + @gem_without_load.add_load_paths + @gem_without_load.load + end - def test_gem_dependencies_compare_for_uniq - gem1 = Rails::GemDependency.new "gem1" - gem1a = Rails::GemDependency.new "gem1" - gem2 = Rails::GemDependency.new "gem2" - gem2a = Rails::GemDependency.new "gem2" - gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem4 = Rails::GemDependency.new "gem3" - gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4] - assert_equal 4, gems.uniq.size - end + def test_gem_dependencies_compare_for_uniq + gem1 = Rails::GemDependency.new "gem1" + gem1a = Rails::GemDependency.new "gem1" + gem2 = Rails::GemDependency.new "gem2" + gem2a = Rails::GemDependency.new "gem2" + gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1" + gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1" + gem4 = Rails::GemDependency.new "gem3" + gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4] + assert_equal 4, gems.uniq.size + end - def test_gem_load_frozen - dummy_gem = Rails::GemDependency.new "dummy-gem-a" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_A_VERSION - end + def test_gem_load_frozen + dummy_gem = Rails::GemDependency.new "dummy-gem-a" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_A_VERSION + end - def test_gem_load_frozen_specific_version - dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_B_VERSION - assert_equal '0.4.0', DUMMY_GEM_B_VERSION - end + def test_gem_load_frozen_specific_version + dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0' + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_B_VERSION + assert_equal '0.4.0', DUMMY_GEM_B_VERSION + end - def test_gem_load_frozen_minimum_version - dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_C_VERSION - assert_equal '0.6.0', DUMMY_GEM_C_VERSION - end + def test_gem_load_frozen_minimum_version + dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0' + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_C_VERSION + assert_equal '0.6.0', DUMMY_GEM_C_VERSION + end - def test_gem_load_missing_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-d" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_D_VERSION - assert_equal '1.0.0', DUMMY_GEM_D_VERSION - assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files - end + def test_gem_load_missing_specification + dummy_gem = Rails::GemDependency.new "dummy-gem-d" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_D_VERSION + assert_equal '1.0.0', DUMMY_GEM_D_VERSION + assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files + end - def test_gem_load_bad_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_E_VERSION - assert_equal '1.0.0', DUMMY_GEM_E_VERSION - end + def test_gem_load_bad_specification + dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_E_VERSION + assert_equal '1.0.0', DUMMY_GEM_E_VERSION + end - def test_gem_handle_missing_dependencies - dummy_gem = Rails::GemDependency.new "dummy-gem-g" - dummy_gem.add_load_paths - dummy_gem.load - assert dummy_gem.loaded? - assert_equal 2, dummy_gem.dependencies.size - assert_nothing_raised do - dummy_gem.dependencies.each do |g| - g.dependencies - end + def test_gem_handle_missing_dependencies + dummy_gem = Rails::GemDependency.new "dummy-gem-g" + dummy_gem.add_load_paths + dummy_gem.load + assert dummy_gem.loaded? + assert_equal 2, dummy_gem.dependencies.size + assert_nothing_raised do + dummy_gem.dependencies.each do |g| + g.dependencies end end - end + end diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index 926607f55c..70829a77fd 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -19,7 +19,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_controller_for :products do |f| assert_has_method f, :index do |name, m| - assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + assert_match /@products = Product\.all/, m, "#{name} should query products table" end assert_has_method f, :show, :edit, :update, :destroy do |name, m| @@ -71,7 +71,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_controller_for :products do |f| assert_has_method f, :index do |name, m| - assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + assert_match /@products = Product\.all/, m, "#{name} should query products table" end assert_has_method f, :show, :edit, :update, :destroy do |name, m| @@ -107,17 +107,15 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_added_route_for :products end - uses_mocha("scaffold_force_plural_names") do - def test_scaffolded_plural_names - Rails::Generator::Base.logger.expects(:warning) - g = Rails::Generator::Base.instance('scaffold', %w(ProductLines)) - assert_equal "ProductLines", g.controller_name - assert_equal "ProductLines", g.controller_class_name - assert_equal "ProductLine", g.controller_singular_name - assert_equal "product_lines", g.controller_plural_name - assert_equal "product_lines", g.controller_file_name - assert_equal "product_lines", g.controller_table_name - end + def test_scaffolded_plural_names + Rails::Generator::Base.logger.expects(:warning) + g = Rails::Generator::Base.instance('scaffold', %w(ProductLines)) + assert_equal "ProductLines", g.controller_name + assert_equal "ProductLines", g.controller_class_name + assert_equal "ProductLine", g.controller_singular_name + assert_equal "product_lines", g.controller_plural_name + assert_equal "product_lines", g.controller_file_name + assert_equal "product_lines", g.controller_table_name end def test_scaffold_plural_model_name_without_force_plural_generates_singular_model diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index dad9e55e61..39372dc5ab 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -47,268 +47,260 @@ class Initializer_eager_loading_Test < Test::Unit::TestCase end end -uses_mocha 'Initializer after_initialize' do - class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase - def setup - config = ConfigurationMock.new("") - config.after_initialize do - $test_after_initialize_block1 = "success" - end - config.after_initialize do - $test_after_initialize_block2 = "congratulations" - end - assert_nil $test_after_initialize_block1 - assert_nil $test_after_initialize_block2 - - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) - Rails::Initializer.run(:after_initialize, config) +class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" end - - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil + config.after_initialize do + $test_after_initialize_block2 = "congratulations" end + assert_nil $test_after_initialize_block1 + assert_nil $test_after_initialize_block2 - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1 - end + Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + Rails::Initializer.run(:after_initialize, config) + end - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 - end + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil end - class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase - def setup - config = ConfigurationMock.new("") - config.after_initialize do - $test_after_initialize_block1 = "success" - end - config.after_initialize # don't pass a block, this is what we're testing! - config.after_initialize do - $test_after_initialize_block2 = "congratulations" - end - assert_nil $test_after_initialize_block1 - - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) - Rails::Initializer.run(:after_initialize, config) - end + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1 + end - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil - end + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end +end - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1, "should still get set" +class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" end - - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 + config.after_initialize # don't pass a block, this is what we're testing! + config.after_initialize do + $test_after_initialize_block2 = "congratulations" end + assert_nil $test_after_initialize_block1 + + Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + Rails::Initializer.run(:after_initialize, config) end -end -uses_mocha 'framework paths' do - class ConfigurationFrameworkPathsTests < Test::Unit::TestCase - def setup - @config = Rails::Configuration.new - @config.frameworks.clear + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end - File.stubs(:directory?).returns(true) - @config.stubs(:framework_root_path).returns('') - end + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1, "should still get set" + end - def test_minimal - expected = %w( - /railties - /railties/lib - /activesupport/lib - ) - assert_equal expected, @config.framework_paths - end + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end +end - def test_actioncontroller_or_actionview_add_actionpack - @config.frameworks << :action_controller - assert_framework_path '/actionpack/lib' +class ConfigurationFrameworkPathsTests < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks.clear - @config.frameworks = [:action_view] - assert_framework_path '/actionpack/lib' - end + File.stubs(:directory?).returns(true) + @config.stubs(:framework_root_path).returns('') + end - def test_paths_for_ar_ares_and_mailer - [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| - @config.frameworks = [framework] - assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" - end - end + def test_minimal + expected = %w( + /railties + /railties/lib + /activesupport/lib + ) + assert_equal expected, @config.framework_paths + end + + def test_actioncontroller_or_actionview_add_actionpack + @config.frameworks << :action_controller + assert_framework_path '/actionpack/lib' - def test_unknown_framework_raises_error - @config.frameworks << :action_foo - initializer = Rails::Initializer.new @config - initializer.expects(:require).raises(LoadError) + @config.frameworks = [:action_view] + assert_framework_path '/actionpack/lib' + end - assert_raise RuntimeError do - initializer.send :require_frameworks - end + def test_paths_for_ar_ares_and_mailer + [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| + @config.frameworks = [framework] + assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" end + end - def test_action_mailer_load_paths_set_only_if_action_mailer_in_use - @config.frameworks = [:action_controller] - initializer = Rails::Initializer.new @config - initializer.send :require_frameworks + def test_unknown_framework_raises_error + @config.frameworks << :action_foo + initializer = Rails::Initializer.new @config + initializer.expects(:require).raises(LoadError) - assert_nothing_raised NameError do - initializer.send :load_view_paths - end + assert_raise RuntimeError do + initializer.send :require_frameworks end + end - def test_action_controller_load_paths_set_only_if_action_controller_in_use - @config.frameworks = [] - initializer = Rails::Initializer.new @config - initializer.send :require_frameworks + def test_action_mailer_load_paths_set_only_if_action_mailer_in_use + @config.frameworks = [:action_controller] + initializer = Rails::Initializer.new @config + initializer.send :require_frameworks - assert_nothing_raised NameError do - initializer.send :load_view_paths - end + assert_nothing_raised NameError do + initializer.send :load_view_paths end - - protected - def assert_framework_path(path) - assert @config.framework_paths.include?(path), - "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" - end end -end -uses_mocha "Initializer plugin loading tests" do - require File.dirname(__FILE__) + '/plugin_test_helper' + def test_action_controller_load_paths_set_only_if_action_controller_in_use + @config.frameworks = [] + initializer = Rails::Initializer.new @config + initializer.send :require_frameworks - 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') + assert_nothing_raised NameError do + initializer.send :load_view_paths end + 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 + protected + def assert_framework_path(path) + assert @config.framework_paths.include?(path), + "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" end +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 +require File.dirname(__FILE__) + '/plugin_test_helper' - 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, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip - end +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_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, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip - 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_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, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip - 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_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_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, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @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_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, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + 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] + 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, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + end - @initializer.add_plugin_load_paths + 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 - 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')) + 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] - private + @initializer.add_plugin_load_paths - def load_plugins! - @initializer.add_plugin_load_paths - @initializer.load_plugins - end + 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 -end -uses_mocha 'i18n settings' do - class InitializerSetupI18nTests < Test::Unit::TestCase - def test_no_config_locales_dir_present_should_return_empty_load_path - File.stubs(:exist?).returns(false) - assert_equal [], Rails::Configuration.new.i18n.load_path - end - def test_config_locales_dir_present_should_be_added_to_load_path - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path + private + + def load_plugins! + @initializer.add_plugin_load_paths + @initializer.load_plugins end - - def test_config_defaults_should_be_added_with_config_settings - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) +end + +class InitializerSetupI18nTests < Test::Unit::TestCase + def test_no_config_locales_dir_present_should_return_empty_load_path + File.stubs(:exist?).returns(false) + assert_equal [], Rails::Configuration.new.i18n.load_path + end - config = Rails::Configuration.new - config.i18n.load_path << "my/other/locale.yml" + def test_config_locales_dir_present_should_be_added_to_load_path + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) + assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path + end + + def test_config_defaults_should_be_added_with_config_settings + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path - end - - def test_config_defaults_and_settings_should_be_added_to_i18n_defaults - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - - config = Rails::Configuration.new - config.i18n.load_path << "my/other/locale.yml" - - # To bring in AV's i18n load path. - require 'action_view' - - Rails::Initializer.run(:initialize_i18n, config) - assert_equal [ - File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), - File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), - "my/test/locale.yml", - "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } - end - - def test_setting_another_default_locale - config = Rails::Configuration.new - config.i18n.default_locale = :de - Rails::Initializer.run(:initialize_i18n, config) - assert_equal :de, I18n.default_locale - end + config = Rails::Configuration.new + config.i18n.load_path << "my/other/locale.yml" + + assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path + end + + def test_config_defaults_and_settings_should_be_added_to_i18n_defaults + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) + + config = Rails::Configuration.new + config.i18n.load_path << "my/other/locale.yml" + + # To bring in AV's i18n load path. + require 'action_view' + + Rails::Initializer.run(:initialize_i18n, config) + assert_equal [ + File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), + File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), + "my/test/locale.yml", + "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } + end + + def test_setting_another_default_locale + config = Rails::Configuration.new + config.i18n.default_locale = :de + Rails::Initializer.run(:initialize_i18n, config) + assert_equal :de, I18n.default_locale end end @@ -320,4 +312,4 @@ class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_should_be_a_pathname assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s end -end
\ No newline at end of file +end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 5a8c651e5a..c8404e126e 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -1,69 +1,62 @@ require 'plugin_test_helper' -uses_mocha "Plugin Locator Tests" do - - class PluginLocatorTest < Test::Unit::TestCase - - def test_should_require_subclasses_to_implement_the_plugins_method - assert_raises(RuntimeError) do - Rails::Plugin::Locator.new(nil).plugins - end +class PluginLocatorTest < Test::Unit::TestCase + def test_should_require_subclasses_to_implement_the_plugins_method + assert_raises(RuntimeError) do + Rails::Plugin::Locator.new(nil).plugins end + 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) - 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 + locator.each do |plugin| + plugin_consumer.consume(plugin) end - end +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 - 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_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_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory - assert_nil @locator.send(:create_plugin, @empty_plugin_path) - end - - def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort - 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", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort - - @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] - assert_equal ["a"], @locator.plugins.map(&:name) - 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_should_return_all_plugins_found_under_the_set_plugin_paths + assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + 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", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort - 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 + @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] + assert_equal ["a"], @locator.plugins.map(&:name) end -end # uses_mocha + 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 diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb index 50124240a5..5500711df8 100644 --- a/railties/test/plugin_test.rb +++ b/railties/test/plugin_test.rb @@ -1,167 +1,162 @@ require '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') + @gemlike_plugin_path = plugin_fixture_path('default/gemlike') + end - class PluginTest < Test::Unit::TestCase + 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 setup - @initializer = Rails::Initializer.new(Rails::Configuration.new) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') - @gemlike_plugin_path = plugin_fixture_path('default/gemlike') - end + def test_should_not_be_loaded_when_created + assert !plugin_for(@valid_plugin_path).loaded? + 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 + 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_not_be_loaded_when_created - assert !plugin_for(@valid_plugin_path).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_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? + 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 - 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 + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).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 + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').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 - - 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 path is fine so nothing is raised - assert_nothing_raised do - plugin = plugin_for(@gemlike_plugin_path) - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end + # This path is fine so nothing is raised + assert_nothing_raised do + plugin = plugin_for(@gemlike_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 + # 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 - - 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) + assert_raises(LoadError) do + plugin = plugin_for('this_is_not_a_plugin_directory') + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) 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 + + 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 - - def test_should_only_be_loaded_once - plugin = plugin_for(@valid_plugin_path) - assert !plugin.loaded? - plugin.expects(:evaluate_init_rb) - assert_nothing_raised do - plugin.send(:load, @initializer) - plugin.send(:load, @initializer) - end - assert plugin.loaded? + + # This is an empty path so it raises + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).load_paths end - - def test_should_make_about_yml_available_as_about_method_on_plugin - plugin = plugin_for(@valid_plugin_path) - assert_equal "Plugin Author", plugin.about['author'] - assert_equal "1.0.0", plugin.about['version'] + + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').load_paths end - - def test_should_return_empty_hash_for_about_if_about_yml_is_missing - assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about) + 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 - - def test_should_return_empty_hash_for_about_if_about_yml_is_malformed - assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about) + 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 + + def test_should_only_be_loaded_once + plugin = plugin_for(@valid_plugin_path) + assert !plugin.loaded? + plugin.expects(:evaluate_init_rb) + assert_nothing_raised do + plugin.send(:load, @initializer) + plugin.send(:load, @initializer) end + assert plugin.loaded? + end - private + def test_should_make_about_yml_available_as_about_method_on_plugin + plugin = plugin_for(@valid_plugin_path) + assert_equal "Plugin Author", plugin.about['author'] + assert_equal "1.0.0", plugin.about['version'] + end - def about_yml_plugin_path(name) - File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name) - end + def test_should_return_empty_hash_for_about_if_about_yml_is_missing + assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about) + end - def plugin_for(path) - Rails::Plugin.new(path) - end + def test_should_return_empty_hash_for_about_if_about_yml_is_malformed + assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about) end -end # uses_mocha + private + + def about_yml_plugin_path(name) + File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name) + end + + def plugin_for(path) + Rails::Plugin.new(path) + end +end |