Skip to content
Browse files

Adding a mechanism to override tests in engine plugins from within

the application, in a structured way.

In your engine tests, add the following line to the bottom of the
file:

  Engines::Testing.override_tests_from_app

This will check for files in the application's test directory, of the
name "test/{kind}/{plugin_name}/{test_name}, and load it to override
any tests. For example, if the test is in

  vendor/plugins/my_plugin/test/unit/stuff_test.rb

then the 'override_tests' method will load (if the file exists)

  test/unit/my_plugin/stuff_test.rb

Keeping these overrides namespaced by plugin should make it a bit
clearer what's going on.
  • Loading branch information...
1 parent 91dd065 commit 6f20d1f32ba91d036fed05921890bea53e085663 @lazyatom committed Apr 18, 2009
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/engines/testing.rb
View
10 lib/engines/testing.rb
@@ -88,4 +88,14 @@ def self.set_fixture_path
ActiveSupport::TestCase.fixture_path = self.temporary_fixtures_directory
$LOAD_PATH.unshift self.temporary_fixtures_directory
end
+
+ # overridden test should be in test/{unit,functional,integration}/{plugin_name}/{test_name}
+ def self.override_tests_from_app
+ filename = caller.first.split(":").first
+ plugin_name = filename.split("/")[-4]
+ test_kind = filename.split("/")[-2]
+ override_file = File.expand_path(File.join(File.dirname(filename), "..", "..", "..", "..", "..", "test",
+ test_kind, plugin_name, File.basename(filename)))
+ load(override_file) if File.exist?(override_file)
+ end
end

0 comments on commit 6f20d1f

Please sign in to comment.
Something went wrong with that request. Please try again.