File: test_rake_rake_test_loader.rb

package info (click to toggle)
rake 13.0.1-4~bpo10%2B1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 956 kB
  • sloc: ruby: 9,596; sh: 19; ansic: 19; makefile: 11
file content (61 lines) | stat: -rw-r--r-- 1,281 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
require File.expand_path("../helper", __FILE__)

class TestRakeRakeTestLoader < Rake::TestCase # :nodoc:

  def setup
    super

    @loader = "rake/rake_test_loader.rb"
  end

  def test_pattern
    orig_loaded_features = $:.dup
    FileUtils.touch "foo.rb"
    FileUtils.touch "test_a.rb"
    FileUtils.touch "test_b.rb"

    ARGV.replace %w[foo.rb test_*.rb -v]

    load @loader

    assert_equal %w[-v], ARGV
  ensure
    $:.replace orig_loaded_features
  end

  def test_load_error_from_require
    out, err = capture_io do
      ARGV.replace %w[no_such_test_file.rb]

      assert_raises SystemExit do
        load @loader
      end
    end

    assert_empty out

    no_such_path = File.join @tempdir, "no_such_test_file"

    expected =
      /\A\n
       File\ does\ not\ exist:\ #{no_such_path}(\.rb)? # JRuby is different
       \n\n\Z/x

    assert_match expected, err
  end

  def test_load_error_raised_explicitly
    File.write("error_test.rb", "raise LoadError, 'explicitly raised'")
    out, err = capture_io do
      ARGV.replace %w[error_test.rb]

      exc = assert_raises(LoadError) do
        load @loader
      end
      assert_equal "explicitly raised", exc.message
    end
    assert_empty out
    assert_empty err
  end
end