h1. jettywrapper This gem is designed to make it easier to run automated tests against jetty. Solr comes bundled in a jetty instance, and the hydra project has taken a similar approach with hydra-jetty, an instance of jetty pre-configured to load fedora, solr, and various other java servlets of use to the hydra project. h2. Instructions for the impatient: bc.. require 'jettywrapper' desc "Hudson build" task :hudson do if (ENV['RAILS_ENV'] == "test") jetty_params = { :jetty_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty'), :quiet => false, :jetty_port => 8983, :solr_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty/solr/test-core'), :fedora_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty/fedora/default'), :startup_wait => 30 } Rake::Task["db:drop"].invoke Rake::Task["db:migrate"].invoke Rake::Task["db:migrate:plugins"].invoke error = Jettywrapper.wrap(jetty_params) do Rake::Task["libra_oa:default_fixtures:refresh"].invoke Rake::Task["hydra:fixtures:refresh"].invoke Rake::Task["spec"].invoke Rake::Task["cucumber"].invoke end raise "test failures: #{error}" if error else system("rake hudson RAILS_ENV=test") fail unless $?.success? end end h2. Important note on creating nested rake tasks: When creating your rake tasks, keep in mind that rake does not by default propogate up errors raised from system commands. If you use system(), the return value will be false for any exit codes other than 0. If you use backticks or %x(), you must use $? to check the exit status code after the call. Failure to do so could result in false successes. h3. Example 1: Checking return value from system() bc.. #retval should return false for non-zero exit codes retval = system("rake hudson RAILS_ENV=test") fail unless retval h3. Example 2: Checking $? with system() bc.. system("rake hudson RAILS_ENV=test") raise "rake hudson encoutered errors" unless $?.success? h3. Example 3: An alternative method: using %x[] or backticks with $? bc.. # %x[] or `` will return everything sent to stdout from the command puts %x[cucumber --tags ~@pending --tags ~@overwritten features] raise "Cucumber failed." unless $?.success? h2. Testing the gem If you haven't already, clone the git repository
git clone git@github.com:projecthydra/jettywrapper.git cd jettywrapperIf you're using RVM (recommended), use the .rvmrc
source .rvmrc rvm list gemsetsInstall the gems and pull the submodules
bundle install git submodule init git submodule updateRun the tests
rake