Running Rspec tests with JRuby fails


#1

How to run RSpec tests with JRuby in a Java project? I tried to run it
with JRuby 1.7.0.preview1,
rspec (2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
rspec-mocks (2.10.1)
rspec-rails (2.10.1)

as follows:

jruby -S rspec and got the error:

javix@ubuntu:~/Development/rspec_jruby$ jruby -S rspec spec
NameError: cannot load Java class com.models.Calculator
for_name at org/jruby/javasupport/JavaClass.java:1206
get_proxy_class at org/jruby/javasupport/JavaUtilities.java:34
java_import at
file:/home/javix/.rvm/rubies/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/java/core_ext/object.rb:45
map at org/jruby/RubyArray.java:2350
java_import at
file:/home/javix/.rvm/rubies/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/java/core_ext/object.rb:41
(root) at
/home/javix/Development/rspec_jruby/spec/com/models/calculator_spec.rb:3
load at org/jruby/RubyKernel.java:1017
(root) at
/home/javix/.rvm/gems/jruby-1.7.0.preview1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:1
map at org/jruby/RubyArray.java:2350
load_spec_files at
/home/javix/.rvm/gems/jruby-1.7.0.preview1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746
load_spec_files at
/home/javix/.rvm/gems/jruby-1.7.0.preview1/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746
run at
/home/javix/.rvm/gems/jruby-1.7.0.preview1/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22
run at
/home/javix/.rvm/gems/jruby-1.7.0.preview1/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69
javix@ubuntu:~/Development/rspec_jruby$

Here is the java class, too simple just to be able to test if all works:
in [project_root-src-com-models]:
package com.models;

public class Calculator {

public int sum(int x, int y){
    return x+y;
}

}

Here is the rspec file in
[project_root-spec-com-models-calculator_spec.rb]:

require ‘java’
require ‘rubygems’
java_import ‘com.models.Calculator’

describe “Calculator” do
it “should add numbers correctly” do
calc = Calculator.new
calc.sum(1,3).should == 4
end
end

Any idea? Thank you in advance.