# Require behavior change from 1.8.7 p299 to 1.9.2 p0

**URL:** <https://www.ruby-forum.com/t/require-behavior-change-from-1-8-7-p299-to-1-9-2-p0/197596>\
**Category:** Ruby\
**Created:** [October 17, 2010, 12:31am UTC](https://www.ruby-forum.com/t/require-behavior-change-from-1-8-7-p299-to-1-9-2-p0/197596 "2010-10-17T00:31:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [October 17, 2010, 12:31am UTC](https://www.ruby-forum.com/t/require-behavior-change-from-1-8-7-p299-to-1-9-2-p0/197596/1 "2010-10-17T00:31:01Z")

</div>

requiring a file is causing problems for me in Ruby 1.9.2 p0. This  
issue did not happen in Ruby 1.8.7 p299.

Here is a ruby file hello\_world.rb

→ cat hello\_world.rb

require ‘sinatra’

get ‘/’ do  
“Hello world #{params[:name]}”.strip  
end

In Ruby 1.8.7, I get into irb and type the following:

→ rvm use ruby-1.8.7-p299

info: Using ruby 1.8.7 p299

bruparel:~/temp/sin\_test  
→ irb  
ruby-1.8.7-p299 \> require ‘rubygems’  
=\> true  
ruby-1.8.7-p299 \> require ‘hello\_world’  
=\> true

Now I switch to Ruby 1.9.2 as follows:

bruparel:~/temp/sin\_test  
→ rvm use ruby-1.9.2-p0

info: Using ruby 1.9.2 p0

bruparel:~/temp/sin\_test  
→ irb  
ruby-1.9.2-p0 \> require ‘rubygems’  
=\> true  
ruby-1.9.2-p0 \> require ‘hello\_world’  
LoadError: no such file to load – hello\_world  
from internal:lib/rubygems/custom\_require:29:in `require' from <internal:lib/rubygems/custom_require>:29:in`require’  
from (irb):2  
from /home/bruparel/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `’

However, if I issue a slightly different require command at irb prompt  
as shown below:

ruby-1.9.2-p0 \> require ‘./hello\_world’  
=\> true

Then it works!

But this is causing all the “old” Ruby 1.8.x programs to break. Is  
there an environment setting in Ruby 1.9.2 that will restore the old  
behavior?

Bharat

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [October 17, 2010, 3:05am UTC](https://www.ruby-forum.com/t/require-behavior-change-from-1-8-7-p299-to-1-9-2-p0/197596/2 "2010-10-17T03:05:45Z")

</div>

On Oct 16, 7:31 pm, Bharat R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> requiring a file is causing problems for me in Ruby 1.9.2 p0. This  
> issue did not happen in Ruby 1.8.7 p299.

[http://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9-2-is-released/](http://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9-2-is-released/)

“$: no longer includes the current directory.”

That means “.” is not included and thus you can’t require things in  
the same folder (is a security measure)

> from internal:lib/rubygems/custom\_require:29:in `require’
> 
> But this is causing all the “old” Ruby 1.8.x programs to break. Is  
> there an environment setting in Ruby 1.9.2 that will restore the old  
> behavior?

severals:

ruby -I. my\_script.rb

require\_relative ‘hello\_world’

or play with $: adding the current directory which I would recommend  
not to.

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [October 17, 2010, 3:55am UTC](https://www.ruby-forum.com/t/require-behavior-change-from-1-8-7-p299-to-1-9-2-p0/197596/3 "2010-10-17T03:55:05Z")

</div>

Thanks Luis. I did some reading on Sinatra/rack-testing plus Ruby 1.9.2  
upgrade. I was really trying to get tests to work in my Sinatra  
application. I was successful in being able to run the tests. Here is  
how:

I have a file called sharpener.rb in my project base directory. I  
created a test directory and a file called test\_shortener.rb in it.  
Here is a snippet of require statements in it:

require ‘rubygems’  
require ‘sinatra’  
require ‘test/unit’  
require ‘rack/test’

require File.join(Dir.pwd, ‘shortener’)

ENV[‘RACK\_ENV’] = ‘test’

class TestShortener \< Test::Unit::TestCase

…

end

Note that I am running the tests from the base directory as follows:

ruby test/test\_shortener.rb

It works fine.

I am curious though. How is including the current directory in the path  
a security risk?

Appreciate your time.

Bharat
