Running Rspec tests with JRuby fails

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:

[email protected]:~/Development/rspec_jruby$ jruby -S rspec spec
NameError: cannot load Java class com.models.Calculator
for_name at org/jruby/javasupport/
get_proxy_class at org/jruby/javasupport/
java_import at
map at org/jruby/
java_import at
(root) at
load at org/jruby/
(root) at
map at org/jruby/
load_spec_files at
load_spec_files at
run at
run at
[email protected]:~/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

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

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

Any idea? Thank you in advance.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service