Sha256: 7182cc282f51396ed13bacf615c34b85363f340fad5ec3491b07dd7be9bdfa44

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 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') ||
           RUBY_ENGINE == 'jruby')
        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

9 entries across 9 versions & 1 rubygems

Version Path
rbx-require-relative-0.0.7-universal-ruby-1.8.7 test/test-rr.rb
rbx-require-relative-0.0.7-universal-ruby-1.9.3 test/test-rr.rb
rbx-require-relative-0.0.7 test/test-rr.rb
rbx-require-relative-0.0.7-universal-rubinius-1.2 test/test-rr.rb
rbx-require-relative-0.0.6 test/test-rr.rb
rbx-require-relative-0.0.6-universal-ruby-1.9.2 test/test-rr.rb
rbx-require-relative-0.0.6-universal-jruby-1.2 test/test-rr.rb
rbx-require-relative-0.0.6-universal-ruby-1.8.7 test/test-rr.rb
rbx-require-relative-0.0.6-universal-ruby-1.9.3 test/test-rr.rb