From 935b2c86359da20c33ec728cb68445bb4daaba99 Mon Sep 17 00:00:00 2001 From: Jan Vlnas Date: Mon, 26 Mar 2012 10:32:48 +0200 Subject: [PATCH] Correct engine tests to work on Ruby 1.9 #952 #944 --- vendor/plugins/engines/Rakefile | 3 ++- vendor/plugins/engines/lib/engines/testing.rb | 4 ++-- .../engines/test/initializers/load_error.rb | 4 ++++ .../plugins/engines/test/unit/testing_test.rb | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 vendor/plugins/engines/test/initializers/load_error.rb diff --git a/vendor/plugins/engines/Rakefile b/vendor/plugins/engines/Rakefile index 6c621dee..21eb47b4 100644 --- a/vendor/plugins/engines/Rakefile +++ b/vendor/plugins/engines/Rakefile @@ -125,7 +125,7 @@ namespace :test do end.to_yaml) end out.puts " installing exception_notification plugin" - run "cd #{test_app_dir} && ./script/plugin install git://github.com/rails/exception_notification.git" + run "cd #{test_app_dir} && ./script/plugin install git://github.com/rails/exception_notification.git -r 'tag pre-2-3'" end end @@ -201,6 +201,7 @@ namespace :test do mirror_test_files('plugins', 'vendor') mirror_test_files('unit', 'test') mirror_test_files('functional', 'test') + mirror_test_files('initializers', 'config') end desc 'Prepare the engines test environment' diff --git a/vendor/plugins/engines/lib/engines/testing.rb b/vendor/plugins/engines/lib/engines/testing.rb index a2fe84f4..99998b21 100644 --- a/vendor/plugins/engines/lib/engines/testing.rb +++ b/vendor/plugins/engines/lib/engines/testing.rb @@ -54,7 +54,7 @@ require 'fileutils' # module Engines::Testing mattr_accessor :temporary_fixtures_directory - self.temporary_fixtures_directory = FileUtils.mkdir_p(File.join(Dir.tmpdir, "rails_fixtures")) + self.temporary_fixtures_directory = [*FileUtils.mkdir_p(File.join(Dir.tmpdir, "rails_fixtures"))].first # Copies fixtures from plugins and the application into a temporary directory # (Engines::Testing.temporary_fixtures_directory). @@ -99,4 +99,4 @@ module Engines::Testing test_kind, plugin_name, File.basename(filename))) load(override_file) if File.exist?(override_file) end -end \ No newline at end of file +end diff --git a/vendor/plugins/engines/test/initializers/load_error.rb b/vendor/plugins/engines/test/initializers/load_error.rb new file mode 100644 index 00000000..14afe827 --- /dev/null +++ b/vendor/plugins/engines/test/initializers/load_error.rb @@ -0,0 +1,4 @@ +#-- encoding: UTF-8 +# Fixes Rails 2.3 and Ruby 1.9.x incompatibility +# See https://groups.google.com/d/topic/rubyonrails-core/gb5woRkmDlk/discussion +MissingSourceFile::REGEXPS << [/^cannot load such file -- (.+)$/i, 1] \ No newline at end of file diff --git a/vendor/plugins/engines/test/unit/testing_test.rb b/vendor/plugins/engines/test/unit/testing_test.rb index ed420ade..7b28bbf5 100644 --- a/vendor/plugins/engines/test/unit/testing_test.rb +++ b/vendor/plugins/engines/test/unit/testing_test.rb @@ -10,6 +10,9 @@ class TestingTest < Test::Unit::TestCase def teardown File.delete(@filename) if File.exists?(@filename) + if File.directory?(Engines::Testing.temporary_fixtures_directory) + FileUtils.rm_r(Engines::Testing.temporary_fixtures_directory) + end end def test_should_copy_fixtures_files_to_tmp_directory @@ -17,4 +20,18 @@ class TestingTest < Test::Unit::TestCase Engines::Testing.setup_plugin_fixtures assert File.exists?(@filename) end -end \ No newline at end of file + + def test_creates_temporary_fixtures_directory + assert File.directory?(Engines::Testing.temporary_fixtures_directory) + end + + def test_set_fixture_path_doesnt_break_load_path + assert_nothing_raised "require has failed after call to Engines::Testing.set_fixture_path" do + require 'tmpdir' # XXX this can be anything, even loaded file + end + end + + def test_fixtures_are_in_load_path + assert $LOAD_PATH.include?(Engines::Testing.temporary_fixtures_directory) + end +end