views:

1743

answers:

4

I'm trying to look at cucumber for Jruby on Rails. One of the pre-requesites is webrat which has as pre-requisite hpricot.

I've installed the gem with hpricot using:

gem install hpricot --source http://code.whytheluckystiff.net --version 0.6.1 --platform java

This installs the java version of hpricot. I add the hpricot_scan.jar to the CLASSPATH but when I run:

cucumber features -n

I get the following output:

HpricotScanService.java:931:in `hpricot_scan': java.lang.NoSuchMethodError:
org.jruby.runtime.builtin.IRubyObject.getInstanceVariable(Ljava/lang/String;)Lorg/jruby/runtime/builtin/IRubyObject;
from HpricotScanService.java:1324:in `__hpricot_scan'
from null:-1:in `call'
from InvocationCallback.java:67:in `execute'
from FullFunctionCallbackMethod.java:69:in `call'
from DynamicMethod.java:243:in `call'
from CachingCallSite.java:283:in `cacheAndCall'
from CachingCallSite.java:121:in `callBlock'

etc.

If I compile the HpricotScanService.java file and add the resulting .class file to the classpath, I get:

Then I should see "Run"
private method `scan' called for Hpricot:Module (NoMethodError)
features/step_definitions/webrat_steps.rb:94:in `/^I should see "([^\"]*)"$/'
features/manage_activity.feature:9:in `Then I should see "Run"'

If I try to install later versions of the hpricot, then I get:

ERROR: Failed to build gem native extension.
C:/Program Files/Ruby/jruby-1.2.0/bin/../bin/jruby.bat extconf.rb install hpricot --platform java
C:/Program Files/Ruby/jruby-1.2.0/bin/../lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (Not
ImplementedError)
from C:/Program Files/Ruby/jruby-1.2.0/bin/../lib/ruby/1.8/mkmf.rb:1:in `require'
from extconf.rb:1

Does anyone have any clues as to what I'm doing wrong/not doing/where I'm being stupid.?

Using Windows XP, JRuby 1.2.0

A: 

HPricot uses native C extensions and it not FFI compliant. Therefore it cannot be used under JRuby.

Rob
But there is a java version available, are you saying that that uses native code as well?
MatthieuF
Sorry MatthieuF, I didn't realise you were using the older version. That should be fine.
Rob
+6  A: 

I don't know about cucumber but Hpricot can definitely be used from JRuby 1.2.0 (though not the latest version of Hpricot). Which version of Hpricot have you got installed? Maybe it is incompatible with the other libraries?

The following command worked for me:

jruby -S gem install hpricot --version '~>0.6.1'
Pankrat
+4  A: 

Since Ola Bini's rewrite of hpricot jruby support last month, the git head of hpricot can be installed with jruby. Just download the head, then use

jruby -S rake package_jruby
cd pkg
sudo jgem install ./hpricot-0.8.1-jruby.gem

and you should be golden.

Josh Matthews
It is worth noting that hpricot requires Ragel to build. If you're running JRuby because you're not cool enough to have a C compiler in your target environment, you'll have to assemble the gem on another system. And apparently HTML links aren't allowed in comments: http://complang.org/ragel/
Ed Brannin
A: 

FYI, version 1.4 of JRuby now supports version 0.7 of HPricot.

http://jruby.org/2009/11/02/jruby-1-4-0.html

Samuel Holloway