No such file to load only in ruby 1.9.2

I am making a gem and i have three files:

gem_name.rb
gem_name/
version.rb
server.rb

in gem_name.rb it requires the other two files but for some reason on
ruby 1.9.2 i can’t find server but on 1.8.7 it can. I am using rvm and
had a previously installed gem of the same name from when i was testing
things so i thought that might be the problem so i reinstalled ruby
1.9.2 on rvm but the problem still persists.

Any help would be much appreciated.

Thanks, James.

On Sat, May 14, 2011 at 12:24 AM, james b. [email protected]
wrote:

things so i thought that might be the problem so i reinstalled ruby
1.9.2 on rvm but the problem still persists.

Any help would be much appreciated.

Did you try
require_relative ‘server’

or alternatively

require ‘./server’

yet?


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

On May 13, 2011, at 15:24 , james b. wrote:

things so i thought that might be the problem so i reinstalled ruby
1.9.2 on rvm but the problem still persists.

Put everything in ‘lib’. Put the tests (that you need to write) in
‘test’.

lib/gem_name.rb should require like so:

require “gem_name/server”

when you run your tests (preferably via rake) make sure that “lib” is in
your load path.

ruby -Ilib test/gem_name/test_server.rb

and when you package this up as a gem, the “lib” dir should be in your
gemspec’s lib path.

Thanks for the replies

I am currently using this in my gem_name.rb file
require “gem_name/server”

I tried the other two suggestions but still no success

gem_name.rb is in the lib directory already and i’m not (gasp) using any
tests. The problem occurs when i install the gem using rake install
provided to me by bundler. I hope that it will work if you install it
through rubygems but i somehow doubt that.

I know i really should have tests so i guess now is as good a time as
ever to start so if you can suggest a test framework to use that would
be great.

Thanks

On May 13, 2011, at 16:50 , james b. wrote:

Thanks for the replies

I am currently using
require “gem_name/server”

I tried the other two suggestions but still no success

The last part you need to know is that 1.9 dropped ‘.’ from the default
load path. that’s why I say put it in lib and make sure lib is in your
path on BOTH 1.8 and 1.9.

gem_name.rb is in the lib directory already and i’m not (gasp) using any
tests. The problem occurs when i install the gem using rake install
provided to me by bundler. I hope that it will work if you install it
through rubygems but i somehow doubt that.

I know i really should have tests so i guess now is as good a time as
ever to start so if you can suggest a test framework to use that would
be great.

I use minitest for nearly everything. Ships with 1.9. I use Hoe with my
projects so it’s all integrated and happy.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs