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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
######################################################################
# This file is imported from the rubygems project.
# DO NOT make modifications in this repo. They _will_ be reverted!
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
######################################################################
require "test/rubygems/gemutilities"
require 'rubygems/indexer'
require 'rubygems/commands/generate_index_command'
class TestGemCommandsGenerateIndexCommand < RubyGemTestCase
def setup
super
@cmd = Gem::Commands::GenerateIndexCommand.new
@cmd.options[:directory] = @gemhome
end
def test_execute
use_ui @ui do
@cmd.execute
end
marshal = File.join @gemhome, 'Marshal.4.8'
marshal_z = File.join @gemhome, 'Marshal.4.8.Z'
assert File.exist?(marshal), marshal
assert File.exist?(marshal_z), marshal_z
end
def test_execute_rss_update
@cmd.options[:update] = true
@cmd.options[:rss_host] = 'example.com'
@cmd.options[:rss_gems_host] = 'gems.example.com'
use_ui @ui do
assert_raises MockGemUi::TermError do
@cmd.execute
end
end
assert_equal "ERROR: --update not compatible with RSS generation\n",
@ui.error
assert_empty @ui.output
end
def test_handle_options_directory
return if 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 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_invalid
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--no-modern --no-legacy]
end
assert_equal 'invalid option: --no-legacy no indicies will be built',
e.message
@cmd = Gem::Commands::GenerateIndexCommand.new
e = assert_raises OptionParser::InvalidOption do
@cmd.handle_options %w[--no-legacy --no-modern]
end
assert_equal 'invalid option: --no-modern no indicies will be built',
e.message
end
def test_handle_options_legacy
@cmd.handle_options %w[--legacy]
assert @cmd.options[:build_legacy]
assert @cmd.options[:build_modern], ':build_modern not set'
end
def test_handle_options_modern
@cmd.handle_options %w[--modern]
assert @cmd.options[:build_legacy]
assert @cmd.options[:build_modern], ':build_modern not set'
end
def test_handle_options_no_legacy
@cmd.handle_options %w[--no-legacy]
refute @cmd.options[:build_legacy]
assert @cmd.options[:build_modern]
end
def test_handle_options_no_modern
@cmd.handle_options %w[--no-modern]
assert @cmd.options[:build_legacy]
refute @cmd.options[:build_modern]
end
def test_handle_options_rss_gems_host
@cmd.handle_options %w[--rss-gems-host gems.example.com]
assert_equal 'gems.example.com', @cmd.options[:rss_gems_host]
end
def test_handle_options_rss_host
@cmd.handle_options %w[--rss-host example.com]
assert_equal 'example.com', @cmd.options[:rss_host]
end
def test_handle_options_rss_title
@cmd.handle_options %w[--rss-title Example\ Gems]
assert_equal 'Example Gems', @cmd.options[:rss_title]
end
def test_handle_options_update
@cmd.handle_options %w[--update]
assert @cmd.options[:update]
end
end if ''.respond_to? :to_xs
|