aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/load_error_test.rb
blob: 5f804c749b8b192a8bb8aa8b3094c6a5cf0dd35a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'abstract_unit'
require 'active_support/core_ext/load_error'

class TestMissingSourceFile < ActiveSupport::TestCase
  def test_with_require
    assert_raise(MissingSourceFile) { require 'no_this_file_don\'t_exist' }
  end
  def test_with_load
    assert_raise(MissingSourceFile) { load 'nor_does_this_one' }
  end
  def test_path
    begin load 'nor/this/one.rb'
    rescue MissingSourceFile => e
      assert_equal 'nor/this/one.rb', e.path
    end
  end

  def test_is_missing
    begin load 'nor_does_this_one'
    rescue MissingSourceFile => e
      assert e.is_missing?('nor_does_this_one')
      assert e.is_missing?('nor_does_this_one.rb')
      assert_not e.is_missing?('some_other_file')
    end
  end
end

class TestLoadError < ActiveSupport::TestCase
  def test_with_require
    assert_raise(LoadError) { require 'no_this_file_don\'t_exist' }
  end
  def test_with_load
    assert_raise(LoadError) { load 'nor_does_this_one' }
  end
  def test_path
    begin load 'nor/this/one.rb'
    rescue LoadError => e
      assert_equal 'nor/this/one.rb', e.path
    end
  end
end