For testing a JRuby + (Jruby) Rack + Sinatra app, in my Rakefile I have:
—start Rakefile—
raise “Rake must be called with JRuby: try again with `jruby -S rake’”
unless defined?(JRUBY_VERSION)
#raise “Read the README. You need to run runtests.sh to setup the
classpath” unless defined?(RUN_TESTS_CALLED)
Thanks to Nick S. for this line
Dir[“#{File.expand_path ‘lib’}/*.jar”].each {|j| $CLASSPATH << j }
require ‘rubygems’
require ‘rake’
require ‘rake/testtask’
desc “Default: run all tests”
task :default => :test
desc “Run tests”
task :test => %w(test:units test:acceptance)
namespace :test do
desc “Run unit tests”
Rake::TestTask.new(:units) do |t|
t.test_files = FileList[“test/unit/*_test.rb”]
end
desc “Run acceptance tests”
Rake::TestTask.new(:acceptance) do |t|
t.test_files = FileList[“test/acceptance/*_test.rb”]
end
end
—end Rakefile—
Then in test/unit/my_controller_test.rb I have:
—start test/unit/my_controller_test.rb—
log = File.new(“my_controller_test.log”, “w”)
STDOUT.reopen(log)
STDERR.reopen(log)
require ‘my_controller’
require ‘test/unit’
require ‘rack/test’
set :environment, :test
class DcControllerTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
SomeModule::Controller
end
…
end
—end test/unit/my_controller_test.rb—
When the my_controller.rb file was missing (because I’d renamed it and
forgot to change the test) when I called jruby -S rake test I got:
$ jr rake test --trace
(in /path/to/projectname)
** Invoke test (first_time)
** Invoke test:units (first_time)
** Execute test:units
rake aborted!
Command failed with status (1): [/path/to/jruby/bin/jruby -I"lib"
“/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb”
“test/unit/dmws_test.rb” ]
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:995:in sh' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in
call’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1010:in
sh' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1098:in
sh’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1029:in
ruby' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1098:in
ruby’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:117:in
define' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1112:in
verbose’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/testtask.rb:102:in
define' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
call’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
execute' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
each’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
execute' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in
invoke_with_call_chain’
/Users/garyweaver/jruby/lib/ruby/1.8/monitor.rb:191:in mon_synchronize' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
invoke_with_call_chain’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in
invoke_prerequisites' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in
each’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in
invoke_prerequisites' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in
invoke_with_call_chain’
/Users/garyweaver/jruby/lib/ruby/1.8/monitor.rb:191:in mon_synchronize' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
invoke_with_call_chain’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in
invoke' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in
invoke_task’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
top_level' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
each’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
top_level' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in
top_level' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in
run’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
standard_exception_handling' /path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in
run’
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:19:in `load’
/path/to/jruby/bin/rake:19
This wasn’t very useful, so I’d seen that others had a similar hack for
sinatra logging to go to a log, and decided to add the following above
the requires and everything else in my test file:
log = File.new(“name_of_my_test.log”, “w”)
STDOUT.reopen(log)
STDERR.reopen(log)
And now I have a name_of_my_test.log that contains the error causing
this mess!:
test/unit/my_controller_test.rb:5:in require': no such file to load -- my_controller (LoadError) from test/unit/my_controller_test.rb:5 from test/unit/my_controller_test.rb:5:in
load’
from
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
from
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in
`each’
from
/path/to/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
So the question is- shouldn’t rake be displaying this error when I run
it at command line without having to redirect stdout and stderr?
Using jruby from trunk from a few days ago +
jruby-openssl (0.5)
rack (1.0.0)
rack-test (0.3.0)
rake (0.8.7)
rest-client (1.0)
sinatra (0.9.2)
sources (0.0.1)
warbler (0.9.13)
Thanks in advance,
Gary
http://stufftohelpyouout.blogspot.com/2009/06/how-to-find-errors-in-your-test-when.html
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email