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.
Instructions for the impatient:
require 'jettywrapper'
desc "Hudson build"
task :hudson do
if (ENV['RAILS_ENV'] == "test")
jetty_params = {
:jetty_home => File.(File.dirname(__FILE__) + '/../../jetty'),
:quiet => false,
:jetty_port => 8983,
:solr_home => File.(File.dirname(__FILE__) + '/../../jetty/solr/test-core'),
:fedora_home => File.(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
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.
Example 1: Checking return value from system()
#retval should return false for non-zero exit codes
retval = system("rake hudson RAILS_ENV=test")
fail unless retval
Example 2: Checking $? with system()
system("rake hudson RAILS_ENV=test")
raise "rake hudson encoutered errors" unless $?.success?
Example 3: An alternative method: using %x[] or backticks with $?
# %x[] or `` will return everything sent to stdout from the command
puts %x[cucumber --tags ~@pending --tags ~@overwritten features]
raise "Cucumber failed." unless $?.success?
Testing the gem
If you haven’t already, clone the git repository
git clone git@github.com:projecthydra/jettywrapper.git
cd jettywrapper
If you’re using RVM (recommended), use the .rvmrc
source .rvmrc
rvm list gemsets
Install the gems and pull the submodules
bundle install
git submodule init
git submodule update
Run the tests
rake