Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
Because engines can contain functionality that is a part of an
Browse files Browse the repository at this point in the history
application in a strong sense, we sometimes want to run tests for
those engines as part of the application test suite.

The new test:engines:* tasks will only run tests from 'engine'
plugins (those containing an 'app' directory), as running tests
for all plugins can often interact badly with the application
tests (i.e. the often expect to be run independently, with their
own schema, etc, or in even more esoteric ways, like the tests
in the engines plugin itself).

We should be able to test that these tests can be overridable.

Clean up fixtures created by test:engines:all
  • Loading branch information
lazyatom committed Apr 18, 2009
1 parent 6f20d1f commit 15ebe4b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -182,6 +182,8 @@ namespace :test do

insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')

insert_line("task :test => ['test:engines:all']", :into => 'Rakefile')

puts "> Mirroring test application files into #{test_app_dir}"
mirror_test_files('app')
mirror_test_files('lib')
Expand Down
28 changes: 28 additions & 0 deletions tasks/engines.rake
Expand Up @@ -217,6 +217,34 @@ Report any issues on http://dev.rails-engines.org. Thanks!
-~===============( ... as you were ... )============================~-}
end

namespace :engines do

def engine_plugins
Dir["vendor/plugins/*"].select { |f| File.directory?(File.join(f, "app")) }.map { |f| File.basename(f) }.join(",")
end

desc "Run tests from within engines plugins (plugins with an 'app' directory)"
task :all => [:units, :functionals, :integration]

desc "Run unit tests from within engines plugins (plugins with an 'app' directory)"
Rake::TestTask.new(:units => "test:plugins:setup_plugin_fixtures") do |t|
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/unit/**/*_test.rb"
t.verbose = true
end

desc "Run functional tests from within engines plugins (plugins with an 'app' directory)"
Rake::TestTask.new(:functionals => "test:plugins:setup_plugin_fixtures") do |t|
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/functional/**/*_test.rb"
t.verbose = true
end

desc "Run integration tests from within engines plugins (plugins with an 'app' directory)"
Rake::TestTask.new(:integration => "test:plugins:setup_plugin_fixtures") do |t|
t.pattern = "vendor/plugins/{#{ENV['PLUGIN'] || engine_plugins}}/test/integration/**/*_test.rb"
t.verbose = true
end
end

namespace :plugins do

desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
Expand Down
13 changes: 13 additions & 0 deletions test/plugins/test_testing/test/unit/override_test.rb
@@ -0,0 +1,13 @@
require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. .. .. .. test test_helper]))

class OverrideTest < ActiveSupport::TestCase
def test_overrides_from_the_application_should_work
flunk "this test should be overridden by the app"
end

def test_tests_within_the_plugin_should_still_run
assert true, "non-overridden plugin tests should still run"
end
end

Engines::Testing.override_tests_from_app
7 changes: 7 additions & 0 deletions test/unit/test_testing/override_test.rb
@@ -0,0 +1,7 @@
require File.join(File.dirname(__FILE__), *%w[.. .. test_helper])

class OverrideTest < ActiveSupport::TestCase
def test_overrides_from_the_application_should_work
assert true, "overriding plugin tests from the application should work"
end
end
3 changes: 2 additions & 1 deletion test/unit/testing_test.rb
Expand Up @@ -4,9 +4,10 @@ class TestingTest < Test::Unit::TestCase
def setup
Engines::Testing.set_fixture_path
@filename = File.join(Engines::Testing.temporary_fixtures_directory, 'testing_fixtures.yml')
File.delete(@filename) if File.exists?(@filename)
end

def teardown
def teardown
File.delete(@filename) if File.exists?(@filename)
end

Expand Down

0 comments on commit 15ebe4b

Please sign in to comment.