0

I'm trying to load `rack/test` into my application, but it's not working for some reason. When I do:

gem list rack-test

I get

rack-test (0.6.2)

So it's installed.

I can also get the path with:

gem which rack/test

which is

/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb

But then

ruby -e 'puts $LOAD_PATH.inspect; $LOAD_PATH << "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/"; require "rack/test"'

yields

["/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/i686-linux", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby/1.9.1/i686-linux", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux"]
/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack/test (LoadError)
    from /home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from -e:1:in `<main>'

What am I doing wrong?

Johnny
  • 7,073
  • 9
  • 46
  • 72
  • what is the result of `ruby -e 'require "rack/test"'` – Sayuj Nov 16 '12 at 17:09
  • `/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack/test (LoadError) from /home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from -e:1:in `
    '`
    – Johnny Nov 16 '12 at 18:07

2 Answers2

0

This could be a permissions issue with the gem files. I can reproduce what you’re seeing if I make the rack/test.rb file unreadable:

$ ls -l `gem which rack/test`
-rw-r--r--  1 matt  staff  9723  5 Nov 19:42 /Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/rack-test-0.6.2/lib/rack/test.rb
$ ruby -e 'p require "rack/test"'
true
$ chmod a-r `gem which rack/test`
$ ls -l `gem which rack/test`
--w-------  1 matt  staff  9723  5 Nov 19:42 /Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/rack-test-0.6.2/lib/rack/test.rb
$ ruby -e 'p require "rack/test"'
/Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require': cannot load such file -- rack/test (LoadError)
        from /Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
        from /Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
        from -e:1:in `<main>'

In other words, if the file exists but isn’t readable for some reason, then gem which will show the file, but trying to require it in Ruby means reading it, and so this will raise a LoadError.

Check the permissions with

$ ls -l `gem which rack/test`

They should look something like -rw-r--r--. If they don’t, this could be your problem. The simple fix would be to use chmod to correct the permissions, but you’ll want to look at the other files too, and try to determine why your permissions are wrong.

matt
  • 78,533
  • 8
  • 163
  • 197
  • Unfortunately, that's not it either. `ls -l /home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb` gives `-rw-r--r-- 1 jacky jacky 9723 2012-11-17 01:38 /home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb`. – Johnny Nov 17 '12 at 08:48
  • I'm also able to `require` it if I give the full path. But adding it's parent directory to `$LOAD_PATH` doesn't help. – Johnny Nov 17 '12 at 08:54
  • And one more thing: I though this might be an ownership issue since gems which I can load belong to `root:root` and gems which I can't belong to `jacky:jacky`, so I changed ownership of all files in the directory to root, but that didn't help either. It's interesting, though, because AFAIK all the gems which I can load are under root and the ones I can't are under jacky. Reinstalling rack-test with root doesn't help. – Johnny Nov 17 '12 at 09:12
0

Solved by reinstalling rvm. There was a superfluous ruby executable for some reason and it messed things up.

Johnny
  • 7,073
  • 9
  • 46
  • 72