Unit tests fail because imported Java class names are not recognised

I have a Ruby class that draws graphs for a Rails project, using JRuby
to
access Java functionality, and it works fine. However, the unit tests
fail,
objecting that I have an uninitialized constant for an imported Java
class
name:

C:/jruby-1.3.0RC2/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in
`const_missing’: uninitialized constant Graph::Color (NameError)

Here is a stripped down version of the class:
include Java

class Graph

import java.awt.Color
FOREGROUND = Color.new 0.2, 0.2, 0.2

def trivial
10
end

end

And a unit test:
require ‘test_helper’

class GraphTest < ActiveSupport::TestCase
def test_trivial
assert 10, Graph.trivial
end
end

Using JRuby 1.3.0RC2 by the way, with NetBeans 6.5.1 and Java 1.6.0_13.

On Thu, Jun 11, 2009 at 4:09 AM, F2Andy[email protected]
wrote:

I have a Ruby class that draws graphs for a Rails project, using JRuby to
access Java functionality, and it works fine. However, the unit tests fail,
objecting that I have an uninitialized constant for an imported Java class
name:

Try using “java_import”. There’s a historical conflict with Rake’s own
top-level “import” that’s probably causing issues for you.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email