Sha256: 324b5ccff1de942dfcc63bccee1e12a40976903f21adb82dfc971abb6a232b78

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

require 'test/unit'

# require_relative the old-fashioned way...
# Note that it's important there be no chdir before this require.
file = File.expand_path(File.join(File.dirname(__FILE__), 
                                  '../lib/require_relative'))
require file

class TestRR < Test::Unit::TestCase
  require 'tmpdir'
  def test_basic
    dir = 
      if RUBY_VERSION.start_with?('1.8') && 
          RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto')
        puts "Note: require_relative doesn't work with Dir.chdir as it does on Rubinius or 1.9"
        '.'
      else
        Dir.tmpdir
      end
    abs_file = RequireRelative.abs_file
    # The chdir is to make things harder for those platforms that 
    # truly support require_relative.
    Dir.chdir(dir) do 
      cur_dir  = File.basename(File.expand_path(File.dirname(abs_file)))
      ['./foo', "../#{cur_dir}/bar"].each_with_index do |suffix, i|
        assert_equal(true, require_relative(suffix), 
                     "check require_relative(#{suffix})")
        # Check that the require_relative worked by checking to see of the
        # class from each file was imported.
        assert_equal(Class, (0 == i ? Foo : Bar).class)
        assert_equal(false, require_relative(suffix), 
                     "require_relative(#{suffix}) second time should be false")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rbx-require-relative-0.0.5 test/test-rr.rb
rbx-require-relative-0.0.5-universal-ruby-1.9.2 test/test-rr.rb
rbx-require-relative-0.0.5-universal-ruby-1.8.7 test/test-rr.rb
rbx-require-relative-0.0.5-universal-rubinius-1.2 test/test-rr.rb