#27 ✓resolved
Si

Switch to Nokogiri prevents JRuby use of Webrat

Reported by Si | November 9th, 2008 @ 11:18 AM

The Hpricot gem could run under JRuby, so that Webrat worked fine, but the switch to Nokogiri prevents this.

Looks like there is no support for JRuby in Nokogiri, and the Nokogiri gem silently fails to build native extensions on my OSX box. I had hoped this meant that alternative non-native code would be used, but sadly no:

jruby -S gem install nokogiri Building native extensions. This could take a while... Successfully installed nokogiri-1.0.3 1 gem installed Installing ri documentation for nokogiri-1.0.3... Installing RDoc documentation for nokogiri-1.0.3...

The problem is hit when starting cucumber, which requires Webrat. The requiring of nokogiri fails to include the native code, and there's no JRuby platform alternative:

jruby -S cucumber ..... lib/cucumber/cli.rb:131:in require_files': no such file to load -- nokogiri/native (MissingSourceFile) Failed to load features/steps/env.rb

It would be great to use Webrat alongside Celerity under JRuby, so I hope a solution can be found. I'm really keen to use Webrat with my feature steps instead of going directly to celerity.

Comments and changes to this ticket

  • Bryan Helmkamp

    Bryan Helmkamp November 13th, 2008 @ 11:28 PM

    Hey Si,

    Thanks for the ticket. I agree.

    I worked on this a little this week and wanted to let you know it's a priority. If you checkout the latest code, it should fall back to Hpricot for parsing and searching if nokogiri doesn't load. I haven't tested it under JRuby yet though, so there might still be some issues.

    Cheers,

    -Bryan

  • Si

    Si November 14th, 2008 @ 12:18 PM

    Hi Bryan,

    Thanks for checking this issue out. The only thing I needed to change in order to get Webrat working with Celerity on JRuby as of Webrat edge was removing the require of "nokogiri/css". My understand is that this is currently needed for the Webrat "core" processing, using the Rails integration testing framework, but isn't used in the plugin implementations. I tested using the Celerity plugin spike found here:

    http://github.com/johnnyt/webrat...

    and modified it slightly to quick-fix what might be a version mismatch. Worked just fine.

    Can / does Nokogiri distribute their css libs separately from the rest of Nokogiri? Nice if so, and it would work with your current webrat.rb initialisation, but I imagine it's reliant on Nokogiri core.

    If so I think the require of "nokogiri/css" ought to depend on the successful requiring of core Nokogiri, mirroring Nokogiri's internal dependency. It would at least enable plugin use when no nokogiri gem exists. When the css libs exist, the core libs will too (I think), so the rescue code path will be avoided entirely anyway. Or perhaps the css require can be deferred until the use of Webrat core sessions? (require it when it's really needed)

    Thanks again!

  • gaffo

    gaffo November 14th, 2008 @ 12:22 PM

    Yes, I just upgraded on my linux box and didn't have nokogiri either and I got the same issue, so the failover isn't yet working.

    Unfortunatly I just threw nokogiri on all of my machines so to test it you're going to have to remove the nokogiri method or mock out require :).

  • Bryan Helmkamp

    Bryan Helmkamp November 17th, 2008 @ 12:06 AM

    • State changed from “new” to “resolved”

    I believe I've resolved the issues with Webrat on JRuby.

    Si -- Nokogiri doesn't distribute the CSS part of the library separately, but there is a Nokogiri gem for JRuby. At the moment, it's good for using the CSS part of the library (which works on JRuby), but not the main Nokogiri stuff (which only works on MRI). nokogiri/css is not (or at least shouldn't be) dependent on the nokogiri core.

    So Webrat requires Nokogiri when run on either MRI or JRuby. On MRI, it uses Nokogiri for everything. On JRuby it uses Nokogiri's CSS support, and then Hpricot + REXML for XML parsing and searching. The hope is that Nokogiri will support JRuby fully soon, and then we can stop using Hpricot and REXML entirely.

    Here's how the code looks now:

    
    if RUBY_PLATFORM =~ /java/
      # We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
      require "nokogiri/css"
      require "hpricot"
      require "rexml/document"
    else
      require "nokogiri"
      require "webrat/core/nokogiri"
    end
    

    Let me know if you run into any further issues with this. Also, please keep me posted on your use of Webrat with Celerity. If it's workable, I'd like to get it into Webrat proper.

    Cheers,

    -Bryan

  • Si

    Si November 17th, 2008 @ 04:44 AM

    It's a winner, thanks Bryan! I'll let you know how I get on with Celerity.

  • Clemens

    Clemens December 2nd, 2008 @ 01:49 AM

    Hi Bryan, you say:

    Nokogiri doesn't distribute the CSS part of the library separately, but there is a Nokogiri gem for JRuby

    where do I find this gem?

    Thx Clemens

  • Bryan Helmkamp

    Bryan Helmkamp December 2nd, 2008 @ 01:50 AM

    Clemens -- Try:

    sudo jgem install nokogiri

  • Clemens

    Clemens December 2nd, 2008 @ 05:58 AM

    getting: C:\Documents and Settings\wys>jruby -S jgem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri:

        ERROR: Failed to build gem native extension.
    
    

    rake RUBYARCHDIR=D:/NetBeans/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/nokogiri-1 .0.6/lib RUBYLIBDIR=D:/NetBeans/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/nokogir i-1.0.6/lib (in D:/NetBeans/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/nokogiri-1.0.6) checking for xmlParseDoc() in xml2.lib... no checking for xsltParseStylesheetDoc() in xslt.lib... no checking for #include <libxml/xmlversion.h> ... no need libxml extconf.rb failed Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

    Provided configuration options:

        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --srcdir=.
        --curdir
        --ruby=D:/InstantRails/ruby/bin/ruby
        --with-xml2lib
        --without-xml2lib
        --with-xsltlib
        --without-xsltlib
    
    

    rake aborted! Command failed with status (1): [D:/InstantRails/ruby/bin/ruby extconf.rb...]

    (See full trace by running task with --trace)

    Gem files will remain installed in D:/NetBeans/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/nokogiri-1.0.6 for inspection. Results logged to D:/NetBeans/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/nokogiri-1.0.6/gem_make.out

  • Bryan Helmkamp

    Bryan Helmkamp December 2nd, 2008 @ 01:24 PM

    Haven't seen or heard of that issue before. It would be best to open a ticket on the Nokogiri ticket tracker, as they'd be better able to help with the install issue:

    http://nokogiri.lighthouseapp.com

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Pages