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

Commit

Permalink
Adding a mechanism to override tests in engine plugins from within
Browse files Browse the repository at this point in the history
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
lazyatom committed Apr 18, 2009
1 parent 91dd065 commit 6f20d1f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/engines/testing.rb
Expand Up @@ -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.