summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_commands_generate_index_command.rb
blob: 7e719a5f60c2147bd6f2f098f9c22a50e1bf5436 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true

require_relative "helper"
require "rubygems/indexer"
require "rubygems/commands/generate_index_command"

class TestGemCommandsGenerateIndexCommand < Gem::TestCase
  def setup
    super

    @cmd = Gem::Commands::GenerateIndexCommand.new
    @cmd.options[:directory] = @gemhome
  end

  def test_execute
    use_ui @ui do
      @cmd.execute
    end

    specs = File.join @gemhome, "specs.4.8.gz"

    assert File.exist?(specs), specs
  end

  def test_execute_no_modern
    @cmd.options[:modern] = false

    use_ui @ui do
      @cmd.execute
    end

    specs = File.join @gemhome, "specs.4.8.gz"

    assert File.exist?(specs), specs
  end

  def test_handle_options_directory
    return if Gem.win_platform?
    refute_equal "/nonexistent", @cmd.options[:directory]

    @cmd.handle_options %w[--directory /nonexistent]

    assert_equal "/nonexistent", @cmd.options[:directory]
  end

  def test_handle_options_directory_windows
    return unless Gem.win_platform?

    refute_equal "/nonexistent", @cmd.options[:directory]

    @cmd.handle_options %w[--directory C:/nonexistent]

    assert_equal "C:/nonexistent", @cmd.options[:directory]
  end

  def test_handle_options_update
    @cmd.handle_options %w[--update]

    assert @cmd.options[:update]
  end

  def test_handle_options_modern
    use_ui @ui do
      @cmd.handle_options %w[--modern]
    end

    assert_equal \
      "WARNING:  The \"--modern\" option has been deprecated and will be removed in Rubygems 4.0. Modern indexes (specs, latest_specs, and prerelease_specs) are always generated, so this option is not needed.\n",
      @ui.error
  end

  def test_handle_options_no_modern
    use_ui @ui do
      @cmd.handle_options %w[--no-modern]
    end

    assert_equal \
      "WARNING:  The \"--no-modern\" option has been deprecated and will be removed in Rubygems 4.0. The `--no-modern` option is currently ignored. Modern indexes (specs, latest_specs, and prerelease_specs) are always generated.\n",
      @ui.error
  end
end