command_kit 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.rubocop.yml +7 -1
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +2 -0
  6. data/README.md +3 -0
  7. data/Rakefile +2 -0
  8. data/command_kit.gemspec +8 -6
  9. data/lib/command_kit/arguments/argument.rb +3 -1
  10. data/lib/command_kit/arguments/argument_value.rb +2 -0
  11. data/lib/command_kit/arguments.rb +5 -5
  12. data/lib/command_kit/bug_report.rb +4 -2
  13. data/lib/command_kit/colors.rb +2 -2
  14. data/lib/command_kit/command.rb +13 -11
  15. data/lib/command_kit/command_name.rb +3 -1
  16. data/lib/command_kit/commands/auto_load/subcommand.rb +3 -1
  17. data/lib/command_kit/commands/auto_load.rb +3 -3
  18. data/lib/command_kit/commands/auto_require.rb +5 -3
  19. data/lib/command_kit/commands/command.rb +4 -2
  20. data/lib/command_kit/commands/help.rb +2 -2
  21. data/lib/command_kit/commands/parent_command.rb +2 -0
  22. data/lib/command_kit/commands/subcommand.rb +2 -0
  23. data/lib/command_kit/commands.rb +8 -8
  24. data/lib/command_kit/completion/install.rb +277 -0
  25. data/lib/command_kit/description.rb +3 -1
  26. data/lib/command_kit/edit.rb +1 -1
  27. data/lib/command_kit/env/home.rb +1 -1
  28. data/lib/command_kit/env/path.rb +1 -1
  29. data/lib/command_kit/env/prefix.rb +41 -0
  30. data/lib/command_kit/env/shell.rb +58 -0
  31. data/lib/command_kit/env.rb +2 -0
  32. data/lib/command_kit/examples.rb +4 -2
  33. data/lib/command_kit/exception_handler.rb +4 -2
  34. data/lib/command_kit/file_utils.rb +2 -0
  35. data/lib/command_kit/help/man.rb +4 -4
  36. data/lib/command_kit/help.rb +2 -0
  37. data/lib/command_kit/interactive.rb +1 -1
  38. data/lib/command_kit/main.rb +2 -0
  39. data/lib/command_kit/open_app.rb +4 -2
  40. data/lib/command_kit/options/option.rb +3 -1
  41. data/lib/command_kit/options/option_value.rb +2 -2
  42. data/lib/command_kit/options/parser.rb +3 -3
  43. data/lib/command_kit/options/quiet.rb +3 -1
  44. data/lib/command_kit/options/verbose.rb +3 -1
  45. data/lib/command_kit/options/version.rb +3 -1
  46. data/lib/command_kit/options.rb +5 -3
  47. data/lib/command_kit/os/linux.rb +3 -1
  48. data/lib/command_kit/os.rb +2 -0
  49. data/lib/command_kit/package_manager.rb +6 -4
  50. data/lib/command_kit/pager.rb +4 -4
  51. data/lib/command_kit/printing/fields.rb +3 -1
  52. data/lib/command_kit/printing/indent.rb +2 -0
  53. data/lib/command_kit/printing/lists.rb +1 -1
  54. data/lib/command_kit/printing/tables/border_style.rb +2 -0
  55. data/lib/command_kit/printing/tables/row_builder.rb +3 -1
  56. data/lib/command_kit/printing/tables/style.rb +1 -1
  57. data/lib/command_kit/printing/tables/table_builder.rb +3 -1
  58. data/lib/command_kit/printing/tables.rb +4 -4
  59. data/lib/command_kit/printing.rb +1 -1
  60. data/lib/command_kit/program_name.rb +2 -0
  61. data/lib/command_kit/stdio.rb +2 -0
  62. data/lib/command_kit/sudo.rb +1 -1
  63. data/lib/command_kit/terminal.rb +4 -2
  64. data/lib/command_kit/usage.rb +4 -2
  65. data/lib/command_kit/version.rb +3 -1
  66. data/lib/command_kit/xdg.rb +4 -2
  67. data/lib/command_kit.rb +4 -2
  68. metadata +5 -65
  69. data/spec/arguments/argument_spec.rb +0 -133
  70. data/spec/arguments/argument_value_spec.rb +0 -66
  71. data/spec/arguments_spec.rb +0 -279
  72. data/spec/bug_report_spec.rb +0 -266
  73. data/spec/colors_spec.rb +0 -771
  74. data/spec/command_kit_spec.rb +0 -8
  75. data/spec/command_name_spec.rb +0 -130
  76. data/spec/command_spec.rb +0 -123
  77. data/spec/commands/auto_load/subcommand_spec.rb +0 -82
  78. data/spec/commands/auto_load_spec.rb +0 -159
  79. data/spec/commands/auto_require_spec.rb +0 -142
  80. data/spec/commands/fixtures/test_auto_load/cli/commands/test1.rb +0 -10
  81. data/spec/commands/fixtures/test_auto_load/cli/commands/test2.rb +0 -10
  82. data/spec/commands/fixtures/test_auto_require/lib/test_auto_require/cli/commands/test1.rb +0 -10
  83. data/spec/commands/help_spec.rb +0 -66
  84. data/spec/commands/parent_command_spec.rb +0 -40
  85. data/spec/commands/subcommand_spec.rb +0 -99
  86. data/spec/commands_spec.rb +0 -865
  87. data/spec/description_spec.rb +0 -179
  88. data/spec/edit_spec.rb +0 -72
  89. data/spec/env/home_spec.rb +0 -46
  90. data/spec/env/path_spec.rb +0 -84
  91. data/spec/env_spec.rb +0 -123
  92. data/spec/examples_spec.rb +0 -211
  93. data/spec/exception_handler_spec.rb +0 -103
  94. data/spec/file_utils_spec.rb +0 -59
  95. data/spec/fixtures/template.erb +0 -5
  96. data/spec/help/man_spec.rb +0 -345
  97. data/spec/help_spec.rb +0 -94
  98. data/spec/inflector_spec.rb +0 -166
  99. data/spec/interactive_spec.rb +0 -415
  100. data/spec/main_spec.rb +0 -179
  101. data/spec/man_spec.rb +0 -46
  102. data/spec/open_app_spec.rb +0 -85
  103. data/spec/options/option_spec.rb +0 -343
  104. data/spec/options/option_value_spec.rb +0 -171
  105. data/spec/options/parser_spec.rb +0 -274
  106. data/spec/options/quiet_spec.rb +0 -51
  107. data/spec/options/verbose_spec.rb +0 -51
  108. data/spec/options/version_spec.rb +0 -146
  109. data/spec/options_spec.rb +0 -465
  110. data/spec/os/linux_spec.rb +0 -164
  111. data/spec/os_spec.rb +0 -233
  112. data/spec/package_manager_spec.rb +0 -806
  113. data/spec/pager_spec.rb +0 -217
  114. data/spec/printing/fields_spec.rb +0 -167
  115. data/spec/printing/indent_spec.rb +0 -132
  116. data/spec/printing/lists_spec.rb +0 -99
  117. data/spec/printing/tables/border_style.rb +0 -43
  118. data/spec/printing/tables/cell_builer_spec.rb +0 -135
  119. data/spec/printing/tables/row_builder_spec.rb +0 -165
  120. data/spec/printing/tables/style_spec.rb +0 -377
  121. data/spec/printing/tables/table_builder_spec.rb +0 -252
  122. data/spec/printing/tables/table_formatter_spec.rb +0 -1190
  123. data/spec/printing/tables_spec.rb +0 -1069
  124. data/spec/printing_spec.rb +0 -106
  125. data/spec/program_name_spec.rb +0 -70
  126. data/spec/spec_helper.rb +0 -3
  127. data/spec/stdio_spec.rb +0 -264
  128. data/spec/sudo_spec.rb +0 -51
  129. data/spec/terminal_spec.rb +0 -231
  130. data/spec/usage_spec.rb +0 -237
  131. data/spec/xdg_spec.rb +0 -191
@@ -1,231 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/terminal'
3
-
4
- require 'stringio'
5
-
6
- describe CommandKit::Terminal do
7
- module TestTerminal
8
- class TestCommand
9
- include CommandKit::Terminal
10
- end
11
- end
12
-
13
- let(:command_class) { TestTerminal::TestCommand }
14
- subject { command_class.new }
15
-
16
- describe "#terminal?" do
17
- context "when stdout is connected to a TTY" do
18
- subject { command_class.new(stdout: STDOUT) }
19
-
20
- it do
21
- skip "STDOUT is not a TTY" unless STDOUT.tty?
22
-
23
- expect(subject.terminal?).to be(true)
24
- end
25
- end
26
-
27
- context "when stdout is not connected to a TTY" do
28
- subject { command_class.new(stdout: StringIO.new) }
29
-
30
- it do
31
- expect(subject.terminal?).to be(false)
32
- end
33
- end
34
-
35
- context "when IO.console is missing" do
36
- before do
37
- expect(IO).to receive(:respond_to?).with(:console).and_return(false)
38
- end
39
-
40
- it do
41
- expect(subject.terminal?).to be(false)
42
- end
43
- end
44
- end
45
-
46
- describe "#tty?" do
47
- context "when stdout is connected to a TTY" do
48
- subject { command_class.new(stdout: STDOUT) }
49
-
50
- it do
51
- skip "STDOUT is not a TTY" unless STDOUT.tty?
52
-
53
- expect(subject.tty?).to be(true)
54
- end
55
- end
56
-
57
- context "when stdout is not connected to a TTY" do
58
- subject { command_class.new(stdout: StringIO.new) }
59
-
60
- it do
61
- expect(subject.tty?).to be(false)
62
- end
63
- end
64
-
65
- context "when IO.console is missing" do
66
- before do
67
- expect(IO).to receive(:respond_to?).with(:console).and_return(false)
68
- end
69
-
70
- it do
71
- expect(subject.tty?).to be(false)
72
- end
73
- end
74
- end
75
-
76
- describe "#terminal" do
77
- context "when stdout is connected to a TTY" do
78
- subject { command_class.new(stdout: STDOUT) }
79
-
80
- it do
81
- skip "STDOUT is not a TTY" unless STDOUT.tty?
82
-
83
- expect(subject.terminal).to eq(IO.console)
84
- end
85
- end
86
-
87
- context "when stdout is not connected to a TTY" do
88
- subject { command_class.new(stdout: StringIO.new) }
89
-
90
- it do
91
- expect(subject.terminal).to eq(nil)
92
- end
93
- end
94
-
95
- context "when IO.console is missing" do
96
- before do
97
- expect(IO).to receive(:respond_to?).with(:console).and_return(false)
98
- end
99
-
100
- it do
101
- expect(subject.terminal).to be(nil)
102
- end
103
- end
104
- end
105
-
106
- describe "#terminal_height" do
107
- context "when stdout is connected to a TTY" do
108
- subject { command_class.new(stdout: STDOUT) }
109
-
110
- it do
111
- skip "STDOUT is not a TTY" unless STDOUT.tty?
112
-
113
- expect(subject.terminal_height).to eq(STDOUT.winsize[0])
114
- end
115
- end
116
-
117
- context "when stdout is not connected to a TTY" do
118
- subject { command_class.new(stdout: StringIO.new) }
119
-
120
- it "must fallback to DEFAULT_TERMINAL_HEIGHT" do
121
- expect(subject.terminal_height).to eq(described_class::DEFAULT_TERMINAL_HEIGHT)
122
- end
123
-
124
- context "but the LINES env variable was set" do
125
- let(:lines) { 10 }
126
- let(:env) { {'LINES' => lines.to_s} }
127
-
128
- subject { command_class.new(stdout: StringIO.new, env: env) }
129
-
130
- it "must fallback to the LINES environment variable" do
131
- expect(subject.terminal_height).to eq(lines)
132
- end
133
- end
134
- end
135
- end
136
-
137
- describe "#terminal_width" do
138
- context "when stdout is connected to a TTY" do
139
- subject { command_class.new(stdout: STDOUT) }
140
-
141
- it do
142
- skip "STDOUT is not a TTY" unless STDOUT.tty?
143
-
144
- expect(subject.terminal_width).to eq(STDOUT.winsize[1])
145
- end
146
- end
147
-
148
- context "when stdout is not connected to a TTY" do
149
- subject { command_class.new(stdout: StringIO.new) }
150
-
151
- it "must fallback to DEFAULT_TERMINAL_WIDTH" do
152
- expect(subject.terminal_width).to eq(described_class::DEFAULT_TERMINAL_WIDTH)
153
- end
154
-
155
- context "but the COLUMNS env variable was set" do
156
- let(:columns) { 50 }
157
- let(:env) { {'COLUMNS' => columns.to_s} }
158
-
159
- subject { command_class.new(stdout: StringIO.new, env: env) }
160
-
161
- it "must fallback to the COLUMNS environment variable" do
162
- expect(subject.terminal_width).to eq(columns)
163
- end
164
- end
165
- end
166
- end
167
-
168
- describe "#terminal_size" do
169
- context "when stdout is connected to a TTY" do
170
- subject { command_class.new(stdout: STDOUT) }
171
-
172
- it do
173
- skip "STDOUT is not a TTY" unless STDOUT.tty?
174
-
175
- expect(subject.terminal_size).to eq(STDOUT.winsize)
176
- end
177
- end
178
-
179
- context "when stdout is not connected to a TTY" do
180
- subject { command_class.new(stdout: StringIO.new) }
181
-
182
- it "must fallback to [DEFAULT_TERMINAL_HEIGHT, DEFAULT_TERMINAL_WIDTH]" do
183
- expect(subject.terminal_size).to eq(
184
- [described_class::DEFAULT_TERMINAL_HEIGHT, described_class::DEFAULT_TERMINAL_WIDTH]
185
- )
186
- end
187
-
188
- context "but the LINES env variable was set" do
189
- let(:lines) { 10 }
190
- let(:env) { {'LINES' => lines.to_s} }
191
-
192
- subject { command_class.new(stdout: StringIO.new, env: env) }
193
-
194
- it "must fallback to the [$LINES, DEFAULT_TERMINAL_WIDTH]" do
195
- expect(subject.terminal_size).to eq(
196
- [lines, described_class::DEFAULT_TERMINAL_WIDTH]
197
- )
198
- end
199
- end
200
-
201
- context "but the COLUMNS env variable was set" do
202
- let(:columns) { 50 }
203
- let(:env) { {'COLUMNS' => columns.to_s} }
204
-
205
- subject { command_class.new(stdout: StringIO.new, env: env) }
206
-
207
- it "must fallback to the [DEFAULT_TERMINAL_HEIGHT, COLUMNS]" do
208
- expect(subject.terminal_size).to eq(
209
- [described_class::DEFAULT_TERMINAL_HEIGHT, columns]
210
- )
211
- end
212
- end
213
-
214
- context "but the LINES and COLUMNS env variable was set" do
215
- let(:lines) { 10 }
216
- let(:columns) { 50 }
217
- let(:env) do
218
- {'LINES' => lines.to_s, 'COLUMNS' => columns.to_s}
219
- end
220
-
221
- subject { command_class.new(stdout: StringIO.new, env: env) }
222
-
223
- it "must fallback to the [LINES, COLUMNS]" do
224
- expect(subject.terminal_size).to eq(
225
- [lines, columns]
226
- )
227
- end
228
- end
229
- end
230
- end
231
- end
data/spec/usage_spec.rb DELETED
@@ -1,237 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/usage'
3
-
4
- describe CommandKit::Usage do
5
- module TestUsage
6
- class ImplicitCmd
7
- include CommandKit::Usage
8
- end
9
- end
10
-
11
- let(:command_class) { TestUsage::ImplicitCmd }
12
-
13
- describe ".included" do
14
- it { expect(command_class).to include(CommandKit::CommandName) }
15
- it { expect(command_class).to include(CommandKit::Help) }
16
- end
17
-
18
- describe ".usage" do
19
- subject { TestUsage::ImplicitCmd }
20
-
21
- context "when no usage has been set" do
22
- it "should default to nil" do
23
- expect(subject.usage).to be_nil
24
- end
25
- end
26
-
27
- context "when a usage is explicitly set" do
28
- module TestUsage
29
- class ExplicitCmd
30
- include CommandKit::Usage
31
- usage 'EXPLICIT'
32
- end
33
- end
34
-
35
- subject { TestUsage::ExplicitCmd }
36
-
37
- it "must return the explicitly set usage" do
38
- expect(subject.usage).to eq("EXPLICIT")
39
- end
40
- end
41
-
42
- context "when the command class inherites from another class" do
43
- context "but no usage is set" do
44
- module TestUsage
45
- class BaseCmd
46
- include CommandKit::Usage
47
- end
48
-
49
- class InheritedCmd < BaseCmd
50
- end
51
- end
52
-
53
- subject { TestUsage::InheritedCmd }
54
-
55
- it "must search each class then return nil "do
56
- expect(subject.usage).to be_nil
57
- end
58
- end
59
-
60
- module TestUsage
61
- class ExplicitBaseCmd
62
- include CommandKit::Usage
63
- usage 'EXPLICIT'
64
- end
65
- end
66
-
67
- context "when the superclass defines an explicit usage" do
68
- module TestUsage
69
- class ImplicitInheritedCmd < ExplicitBaseCmd
70
- end
71
- end
72
-
73
- let(:super_subject) { TestUsage::ExplicitBaseCmd }
74
- subject { TestUsage::ImplicitInheritedCmd }
75
-
76
- it "must inherit the superclass'es usage" do
77
- expect(subject.usage).to eq(super_subject.usage)
78
- end
79
-
80
- it "must not change the superclass'es usage" do
81
- expect(super_subject.usage).to eq("EXPLICIT")
82
- end
83
- end
84
-
85
- context "when the subclass defines an explicit usage" do
86
- module TestUsage
87
- class ImplicitBaseCmd
88
- include CommandKit::Usage
89
- end
90
-
91
- class ExplicitInheritedCmd < ImplicitBaseCmd
92
- usage 'EXPLICIT'
93
- end
94
- end
95
-
96
- let(:super_subject) { TestUsage::ImplicitBaseCmd }
97
- subject { TestUsage::ExplicitInheritedCmd }
98
-
99
- it "must return the subclass'es usage" do
100
- expect(subject.usage).to eq("EXPLICIT")
101
- end
102
-
103
- it "must not change the superclass'es usage" do
104
- expect(super_subject.usage).to be_nil
105
- end
106
- end
107
-
108
- context "when both the subclass overrides the superclass's usages" do
109
- module TestUsage
110
- class ExplicitOverridingInheritedCmd < ExplicitBaseCmd
111
- usage 'EXPLICIT_OVERRIDE'
112
- end
113
- end
114
-
115
- let(:super_subject) { TestUsage::ExplicitBaseCmd }
116
- subject { TestUsage::ExplicitOverridingInheritedCmd }
117
-
118
- it "must return the subclass'es usage" do
119
- expect(subject.usage).to eq("EXPLICIT_OVERRIDE")
120
- end
121
-
122
- it "must not change the superclass'es usage" do
123
- expect(super_subject.usage).to eq("EXPLICIT")
124
- end
125
- end
126
- end
127
- end
128
-
129
- module TestUsage
130
- class NoUsage
131
- include CommandKit::Usage
132
- end
133
- end
134
-
135
- module TestUsage
136
- class SingleUsage
137
- include CommandKit::Usage
138
-
139
- usage 'ONE USAGE'
140
- end
141
- end
142
-
143
- module TestUsage
144
- class MultipleUsage
145
- include CommandKit::Usage
146
-
147
- usage [
148
- 'ONE USAGE',
149
- 'TWO USAGE',
150
- 'THREE USAGE'
151
- ]
152
- end
153
- end
154
-
155
- subject { command_class.new }
156
-
157
- describe "#usage" do
158
- context "when .usage is nil" do
159
- let(:command_class) { TestUsage::NoUsage }
160
- subject { command_class.new }
161
-
162
- it "must not print anything" do
163
- expect(subject.usage).to be(nil)
164
- end
165
- end
166
-
167
- context "when .usage is a String" do
168
- let(:command_class) { TestUsage::SingleUsage }
169
- subject { command_class.new }
170
-
171
- it "must return .usage, but with #command_name prepended" do
172
- expect(subject.usage).to eq("#{subject.command_name} #{command_class.usage}")
173
- end
174
- end
175
-
176
- context "when #usage is an Array of Strings" do
177
- let(:command_class) { TestUsage::MultipleUsage }
178
- subject { command_class.new }
179
-
180
- it "must return .usage, but with #command_name prepended to each element" do
181
- expect(subject.usage).to eq(
182
- [
183
- "#{subject.command_name} #{command_class.usage[0]}",
184
- "#{subject.command_name} #{command_class.usage[1]}",
185
- "#{subject.command_name} #{command_class.usage[2]}"
186
- ]
187
- )
188
- end
189
- end
190
- end
191
-
192
- describe "#help_usage" do
193
- context "when #usage is nil" do
194
- let(:command_class) { TestUsage::NoUsage }
195
- subject { command_class.new }
196
-
197
- it "must not print anything" do
198
- expect { subject.help_usage }.to_not output.to_stdout
199
- end
200
- end
201
-
202
- context "when #usage is a String" do
203
- let(:command_class) { TestUsage::SingleUsage }
204
- subject { command_class.new }
205
-
206
- it "must print out 'usage:' and only one usage" do
207
- expect { subject.help_usage }.to output(
208
- "usage: #{subject.usage}#{$/}"
209
- ).to_stdout
210
- end
211
- end
212
-
213
- context "when #usage is an Array of Strings" do
214
- let(:command_class) { TestUsage::MultipleUsage }
215
- subject { command_class.new }
216
-
217
- it "must print out the 'usage:' and all usage Strings" do
218
- expect { subject.help_usage }.to output(
219
- [
220
- "usage: #{subject.usage[0]}",
221
- " #{subject.usage[1]}",
222
- " #{subject.usage[2]}",
223
- ''
224
- ].join($/)
225
- ).to_stdout
226
- end
227
- end
228
- end
229
-
230
- describe "#help" do
231
- it "must call #help_usage" do
232
- expect(subject).to receive(:help_usage)
233
-
234
- subject.help
235
- end
236
- end
237
- end
data/spec/xdg_spec.rb DELETED
@@ -1,191 +0,0 @@
1
- require 'spec_helper'
2
- require 'command_kit/xdg'
3
-
4
- describe CommandKit::XDG do
5
- module TestXDG
6
- class TestCommand
7
- include CommandKit::XDG
8
- end
9
- end
10
-
11
- let(:command_class) { TestXDG::TestCommand }
12
- subject { command_class.new }
13
-
14
- describe ".xdg_namespace" do
15
- subject { command_class }
16
-
17
- context "when no xdg_namespace has been defined" do
18
- it "must default to the .command_name" do
19
- expect(subject.xdg_namespace).to eq(subject.command_name)
20
- end
21
- end
22
-
23
- context "when an xdg_namespace has been defined in a super-class" do
24
- module TestXDG
25
- class SuperClassWithXDGNamespace
26
- include CommandKit::XDG
27
-
28
- xdg_namespace 'foo'
29
- end
30
-
31
- class SubClassWithoutXDGNamespace < SuperClassWithXDGNamespace
32
- end
33
- end
34
-
35
- let(:command_superclass) { TestXDG::SuperClassWithXDGNamespace }
36
- let(:command_class) { TestXDG::SubClassWithoutXDGNamespace }
37
-
38
- it "must default to the superclass'es .xdg_namespace" do
39
- expect(subject.xdg_namespace).to eq(command_superclass.xdg_namespace)
40
- end
41
-
42
- context "but the sub-class also defines an .xdg_namespace" do
43
- module TestXDG
44
- class SubClassWithXDGNamespace < SuperClassWithXDGNamespace
45
-
46
- xdg_namespace 'bar'
47
-
48
- end
49
- end
50
-
51
- let(:command_class) { TestXDG::SubClassWithXDGNamespace }
52
-
53
- it "must return the subclass'es .xdg_namespace" do
54
- expect(command_class.xdg_namespace).to eq('bar')
55
- end
56
-
57
- it "must not override the superclass'es .xdg_namespace" do
58
- expect(command_superclass.xdg_namespace).to eq('foo')
59
- end
60
- end
61
- end
62
- end
63
-
64
- describe "#xdg_namespace" do
65
- it "must return .xdg_namespace" do
66
- expect(subject.xdg_namespace).to eq(command_class.xdg_namespace)
67
- end
68
- end
69
-
70
- let(:xdg_config_home) { '/path/to/.config' }
71
- let(:xdg_data_home) { '/path/to/.local/share' }
72
- let(:xdg_cache_home) { '/path/to/.cache' }
73
-
74
- describe "#initialize" do
75
- let(:xdg_namespace) { subject.xdg_namespace }
76
-
77
- context "when env: contains 'XDG_CONFIG_HOME'" do
78
- let(:env) do
79
- {'XDG_CONFIG_HOME' => xdg_config_home}
80
- end
81
-
82
- subject { command_class.new(env: env) }
83
-
84
- it "must initialize #config_dir to '$XDG_CONFIG_HOME/<xdg_namespace>'" do
85
- expect(subject.config_dir).to eq(
86
- File.join(xdg_config_home,xdg_namespace)
87
- )
88
- end
89
- end
90
-
91
- context "when env: does not contains 'XDG_DATA_HOME'" do
92
- it "must initialize #config_dir to '$HOME/.config/<xdg_namespace>'" do
93
- expect(subject.config_dir).to eq(
94
- File.join(subject.home_dir,'.config',subject.xdg_namespace)
95
- )
96
- end
97
- end
98
-
99
- context "when env: contains 'XDG_DATA_HOME'" do
100
- let(:env) do
101
- {'XDG_DATA_HOME' => xdg_data_home}
102
- end
103
-
104
- subject { command_class.new(env: env) }
105
-
106
- it "must initialize #local_share_dir to '$XDG_DATA_HOME/<xdg_namespace>'" do
107
- expect(subject.local_share_dir).to eq(
108
- File.join(xdg_data_home,xdg_namespace)
109
- )
110
- end
111
- end
112
-
113
- context "when env: does not contains 'XDG_DATA_HOME'" do
114
- it "must initialize #local_share_dir to '$HOME/.local/share/<xdg_namespace>'" do
115
- expect(subject.local_share_dir).to eq(
116
- File.join(subject.home_dir,'.local','share',xdg_namespace)
117
- )
118
- end
119
- end
120
-
121
- context "when env: contains 'XDG_CACHE_HOME'" do
122
- let(:env) do
123
- {'XDG_CACHE_HOME' => xdg_cache_home}
124
- end
125
-
126
- subject { command_class.new(env: env) }
127
-
128
- it "must initialize #cache_dir to '$XDG_CACHE_HOME/<xdg_namespace>'" do
129
- expect(subject.cache_dir).to eq(
130
- File.join(xdg_cache_home,xdg_namespace)
131
- )
132
- end
133
- end
134
-
135
- context "when env: does not contains 'XDG_CACHE_HOME'" do
136
- it "must initialize #cache_dir to '$HOME/.cache/<xdg_namespace>'" do
137
- expect(subject.cache_dir).to eq(
138
- File.join(subject.home_dir,'.cache',xdg_namespace)
139
- )
140
- end
141
- end
142
- end
143
-
144
- describe "#config_dir" do
145
- let(:env) do
146
- {'XDG_CONFIG_HOME' => xdg_config_home}
147
- end
148
-
149
- subject { command_class.new(env: env) }
150
-
151
- let(:xdg_namespace) { subject.xdg_namespace }
152
-
153
- it "must return the initialized #config_dir" do
154
- expect(subject.config_dir).to eq(
155
- File.join(xdg_config_home,xdg_namespace)
156
- )
157
- end
158
- end
159
-
160
- describe "#local_share_dir" do
161
- let(:env) do
162
- {'XDG_DATA_HOME' => xdg_data_home}
163
- end
164
-
165
- subject { command_class.new(env: env) }
166
-
167
- let(:xdg_namespace) { subject.xdg_namespace }
168
-
169
- it "must return the initialized #local_share_dir" do
170
- expect(subject.local_share_dir).to eq(
171
- File.join(xdg_data_home,xdg_namespace)
172
- )
173
- end
174
- end
175
-
176
- describe "#cache_dir" do
177
- let(:env) do
178
- {'XDG_CACHE_HOME' => xdg_cache_home}
179
- end
180
-
181
- subject { command_class.new(env: env) }
182
-
183
- let(:xdg_namespace) { subject.xdg_namespace }
184
-
185
- it "must return the initialized #cache_dir" do
186
- expect(subject.cache_dir).to eq(
187
- File.join(xdg_cache_home,xdg_namespace)
188
- )
189
- end
190
- end
191
- end