This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 188653 - Unit test ('test/unit') does not work due to invalid $LOAD_PATH
Summary: Unit test ('test/unit') does not work due to invalid $LOAD_PATH
Status: NEW
Alias: None
Product: ruby
Classification: Unclassified
Component: Testing (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Assignee: issues@ruby
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-14 08:36 UTC by Josy
Modified: 2011-01-28 20:14 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Josy 2010-07-14 08:36:36 UTC
I have created a new Ruby Project containing just the following line of code:

puts $LOAD_PATH

Here the result:
C:/xxxxx/Prototype/RubyApplication4/lib-IC:/xxxxx/Prototype/RubyApplication4/test
C:/xxxxx/Prototype/RubyApplication4/spec
C:/Program Files/Netbeans 6.9/ruby/jruby-1.5.0/lib/ruby/site_ruby/1.8
C:/Program Files/Netbeans 6.9/ruby/jruby-1.5.0/lib/ruby/site_ruby/shared
C:/Program Files/Netbeans 6.9/ruby/jruby-1.5.0/lib/ruby/1.8
.

as seen above the load path to the "lib" and the "test" directory got connected by a "-I" ans thus became invalid. 

As workaround I have figured out the following solutions:
In the test_suite file add the path to the test directory by adding the line:
$:.unshift File.join(File.dirname(__FILE__),'..','test')

Example:
------------- begin --------------
require 'test/unit'

require File.join(File.dirname(__FILE__),'..','test', 'test_lib' )

# Workaround for Netbeans 6.9 LOAD_PATH problem
$:.unshift File.join(File.dirname(__FILE__),'..','test')

# Add your testcases here
require 'tc_1'
require 'tc_2'
--------------- end ---------------
In each file accessing the lib directory from the test directory, add the line:
$:.unshift File.join(File.dirname(__FILE__),'..','lib')


Example:
------------- begin --------------
$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'test/unit'

# For each file to be loaded from lib directory:
require File.join(File.dirname(__FILE__),'..','lib', 'xyz_node' )

class Tc_1 < Test::Unit::TestCase

  def setup
    # started before executing each test case
    puts("------------------------------------------------------------------")
  end


  def test_dump_database_node()
    create_node = XYZ_node.new()
  end
end
--------------- end ---------------

Please fix the loadpath.


Maybe the invalid load path is caused by this line:
rake aborted!
Command failed with status (1): [C:/jruby-1.5.1/bin/jruby.bat -I"lib" -r"C:...]
rake aborted!


Note:
Same error appears with build-in jruby and external jruby.
Comment 1 viphe 2010-08-28 13:46:07 UTC
I have the same problem.

It happens with JRuby, Ruby 1.8.7, Ruby 1.9.1 and Ruby 1.9.2, when running a specific test file. If I run the whole test suite of the project, it works fine because the path is built by Rake and not by NetBeans (I'm guessing).
I confirm that a guilty "-I" appears in the Ruby path.

The work-around proposed above works not only JRuby.
Comment 2 SpOOnman 2010-10-18 11:03:56 UTC
I had the same problem and workaround works for me.

In my opinion this defect is a blocker for Ruby/JRuby development. It's a shame that is made its way to public release.
Comment 3 SpOOnman 2010-10-18 12:46:15 UTC
I have found additional workaround: Go to Project properties and in Souces Tab add second "lib" entry to your source folders and second "test" entry to your test folders. You duplicate paths, -I error still occurs, but it works as expected.