Sha256: eb992730dfabe00a8fa233b6e81a30f8566ebbcfc24165ca1932e94f38810269

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 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.2-head-nframe"
        '.'
      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

2 entries across 2 versions & 2 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rbx-require-relative-0.0.9/test/test-rr.rb
rbx-require-relative-0.0.9 test/test-rr.rb