require 'rbconfig' include Config require 'rake' require 'rake/tasklib' require 'rapt/test_observer' module RaPT # The RaPT::TestTask is a specially augmented version of the standard # Rake::TestTask, which will attempt to submit test results to the # Rails Plugin Repository for the benefit of the community. class TestTask < Rake::TestTask # A flag to indicate whether or not test data should be submitted attr_accessor :submit_test_results #-- # All that the RaPT::TestTask overrides (beyond providing helper # methods) is the addition of a single required file on the command # line (rapt/test_runner), and the additional test submission hook # once the tests are complete. # The rapt/test_runner file overrides the default test/unit # running mechanisms to ensure that the test result data is collected # and stored, and that the rake process doesn't immediately quit # after the tests have run. #++ def define lib_path = @libs.join(File::PATH_SEPARATOR) desc "Run tests" + (@name==:test ? "" : " for #{@name}") task @name do @plugin_name = @name.keys[0] run_code = '' RakeFileUtils.verbose(@verbose) do run_code = case @loader when :direct "-e 'ARGV.each{|f| load f}'" when :testrb "-S testrb #{fix}" when :rake rake_loader end @ruby_opts.unshift( "-I#{lib_path}" ) # @ruby_opts.unshift("-r lib/rapt/test_runner") @ruby_opts.unshift( "-w" ) if @warning ruby @ruby_opts.join(" ") + " \"#{run_code}\" " + file_list.collect { |fn| "\"#{fn}\"" }.join(' ') + " #{option_list}" # Here's the second difference. puts "Tests for plugin '#{@plugin_name}' complete." submit if @submit_test_results end end self end # Collect the result information into a hash and send it to the repository def submit data = {:plugin_name => @plugin_name}.update(environment) data[:plugin_revision] = plugin_revision # load the stored test result data test_results = RaPT::TestObserver.load_data data[:tests] = test_results.tests data[:failures] = test_results.total_failures # send the data off send_to_repository(data) end #-- # Currently does no transmission, until we figure out the API #++ def send_to_repository(test_data) puts "Submitting: " puts test_data.to_yaml end #-- # current unused... #++ def prompt_for_result_submission print 'Submit these results to the Rails Plugin Repository? [Yn]: '; STDOUT.flush unless STDIN.gets.downcase =~ /\A[n]/ submit_results end end private def load_about_data @plugin_about_data = if File.exist?("vendor/plugins/#{@plugin_name}/about.yml") YAML.load(File.open("vendor/plugins/#{@plugin_name}/about.yml")) else {} end end def plugin_revision load_about_data @plugin_about_data[:revision] || if File.exist?("vendor/plugins/#{@plugin_name}/.svn") YAML.load(`svn info vendor/plugins/#{@plugin_name}}`) svn_info.is_a?(Hash) ? svn_info['Revision'] : nil else nil end end def environment { :ruby_version => [CONFIG['MAJOR'],CONFIG['MINOR'],CONFIG['TEENY']].join('.'), :rails_version => Rails::VERSION::STRING, :architecture => CONFIG['arch'] } end end end