From bd779b4f823a38baaab6c0e4de4050e29e629b2d Mon Sep 17 00:00:00 2001 From: Christian Ratz Date: Thu, 28 Mar 2013 10:34:05 +0100 Subject: [PATCH] enable testing plugins from OpenProject core - created rake task to run plugin specs - added config variable where plugins can register for tests - added after(:suite) block in spec_helper to check for wrong used before(:all) --- config/application.rb | 3 +++ lib/tasks/plugin_tests.rake | 36 ++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 6 ++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/tasks/plugin_tests.rake diff --git a/config/application.rb b/config/application.rb index 105a869ea9..a4a670326f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -72,6 +72,9 @@ module OpenProject # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + + # initialize variable for register plugin tests + config.plugins_to_test_paths = [] end def self.preload_circular_dependencies diff --git a/lib/tasks/plugin_tests.rake b/lib/tasks/plugin_tests.rake new file mode 100644 index 0000000000..424ef6c5a2 --- /dev/null +++ b/lib/tasks/plugin_tests.rake @@ -0,0 +1,36 @@ +# This task will run all plugin specs separated by plugin. +# A plugin must register for tests via config variable 'plugins_to_test_paths' +# +# e.g. +# class Engine < ::Rails::Engine +# initializer 'register_path_to_rspec' do |app| +# app.config.plugins_to_test_paths << self.root +# end +# end +# + +desc "Run plugin tests" +namespace :openproject do + namespace :plugins do + namespace :test do + desc "Run specs for all test registered plugins" + task :rspec => :environment do + get_plugins_to_test.each do |plugin_path| + puts "run specs for #{plugin_path.split('/').last} plugin" + ENV['SPEC'] = "#{plugin_path}/spec/" + Rake::Task["spec"].execute + end + end + end + end +end + +def get_plugins_to_test + plugin_paths = [] + Rails.application.config.plugins_to_test_paths.each do |dir| + if File.directory?( dir ) + plugin_paths << File.join(dir).to_s + end + end + plugin_paths +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e52db270ed..3e75827ce8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -81,6 +81,12 @@ Spork.prefork do config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true + + config.after(:suite) do + [User, Project, Issue].each do |cls| + raise "your specs leave a #{cls} in the DB\ndid you use before(:all) instead of before or forget to kill the instances in a after(:all)?" if cls.count > 0 + end + end end end