command_kit 0.1.0.pre1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +15 -0
- data/.rubocop.yml +138 -0
- data/ChangeLog.md +34 -2
- data/Gemfile +3 -0
- data/README.md +135 -214
- data/Rakefile +3 -2
- data/command_kit.gemspec +4 -4
- data/examples/colors.rb +30 -0
- data/examples/command.rb +65 -0
- data/examples/pager.rb +30 -0
- data/gemspec.yml +10 -2
- data/lib/command_kit/arguments/argument.rb +16 -44
- data/lib/command_kit/arguments/argument_value.rb +3 -30
- data/lib/command_kit/arguments.rb +66 -20
- data/lib/command_kit/colors.rb +253 -45
- data/lib/command_kit/command.rb +50 -3
- data/lib/command_kit/command_name.rb +9 -0
- data/lib/command_kit/commands/auto_load/subcommand.rb +3 -0
- data/lib/command_kit/commands/auto_load.rb +16 -0
- data/lib/command_kit/commands/auto_require.rb +16 -0
- data/lib/command_kit/commands/command.rb +3 -0
- data/lib/command_kit/commands/help.rb +2 -0
- data/lib/command_kit/commands/parent_command.rb +7 -0
- data/lib/command_kit/commands/subcommand.rb +15 -0
- data/lib/command_kit/commands.rb +40 -4
- data/lib/command_kit/description.rb +15 -2
- data/lib/command_kit/env/home.rb +9 -0
- data/lib/command_kit/env/path.rb +15 -0
- data/lib/command_kit/env.rb +4 -0
- data/lib/command_kit/examples.rb +15 -2
- data/lib/command_kit/exception_handler.rb +4 -0
- data/lib/command_kit/help/man.rb +74 -47
- data/lib/command_kit/help.rb +10 -1
- data/lib/command_kit/inflector.rb +49 -17
- data/lib/command_kit/interactive.rb +239 -0
- data/lib/command_kit/main.rb +20 -9
- data/lib/command_kit/man.rb +44 -0
- data/lib/command_kit/open_app.rb +69 -0
- data/lib/command_kit/options/option.rb +36 -9
- data/lib/command_kit/options/option_value.rb +42 -3
- data/lib/command_kit/options/parser.rb +44 -17
- data/lib/command_kit/options/quiet.rb +3 -0
- data/lib/command_kit/options/verbose.rb +5 -0
- data/lib/command_kit/options/version.rb +6 -0
- data/lib/command_kit/options.rb +59 -10
- data/lib/command_kit/os/linux.rb +157 -0
- data/lib/command_kit/os.rb +165 -11
- data/lib/command_kit/package_manager.rb +200 -0
- data/lib/command_kit/pager.rb +84 -9
- data/lib/command_kit/printing/indent.rb +25 -2
- data/lib/command_kit/printing.rb +23 -0
- data/lib/command_kit/program_name.rb +7 -0
- data/lib/command_kit/stdio.rb +24 -0
- data/lib/command_kit/sudo.rb +40 -0
- data/lib/command_kit/terminal.rb +159 -0
- data/lib/command_kit/usage.rb +14 -0
- data/lib/command_kit/version.rb +1 -1
- data/lib/command_kit/xdg.rb +21 -1
- data/lib/command_kit.rb +1 -0
- data/spec/arguments/argument_spec.rb +5 -41
- data/spec/arguments/argument_value_spec.rb +1 -61
- data/spec/arguments_spec.rb +8 -25
- data/spec/colors_spec.rb +277 -13
- data/spec/command_name_spec.rb +1 -1
- data/spec/command_spec.rb +4 -1
- data/spec/commands/auto_load/subcommand_spec.rb +1 -1
- data/spec/commands/auto_load_spec.rb +1 -1
- data/spec/commands/auto_require_spec.rb +2 -2
- data/spec/commands/help_spec.rb +1 -1
- data/spec/commands/parent_command_spec.rb +1 -1
- data/spec/commands/subcommand_spec.rb +1 -1
- data/spec/commands_spec.rb +2 -2
- data/spec/description_spec.rb +1 -25
- data/spec/env/home_spec.rb +1 -1
- data/spec/env/path_spec.rb +1 -1
- data/spec/examples_spec.rb +1 -25
- data/spec/exception_handler_spec.rb +1 -1
- data/spec/help/man_spec.rb +316 -0
- data/spec/help_spec.rb +0 -25
- data/spec/inflector_spec.rb +71 -9
- data/spec/interactive_spec.rb +415 -0
- data/spec/main_spec.rb +7 -7
- data/spec/man_spec.rb +46 -0
- data/spec/open_app_spec.rb +85 -0
- data/spec/options/option_spec.rb +48 -9
- data/spec/options/option_value_spec.rb +53 -4
- data/spec/options_spec.rb +1 -1
- data/spec/os/linux_spec.rb +154 -0
- data/spec/os_spec.rb +201 -14
- data/spec/package_manager_spec.rb +806 -0
- data/spec/pager_spec.rb +78 -15
- data/spec/printing/indent_spec.rb +1 -1
- data/spec/printing_spec.rb +10 -2
- data/spec/program_name_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/sudo_spec.rb +51 -0
- data/spec/{console_spec.rb → terminal_spec.rb} +65 -35
- data/spec/usage_spec.rb +2 -2
- data/spec/xdg_spec.rb +1 -1
- metadata +32 -13
- data/lib/command_kit/arguments/usage.rb +0 -6
- data/lib/command_kit/console.rb +0 -141
- data/lib/command_kit/options/usage.rb +0 -6
data/spec/pager_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'command_kit/pager'
|
|
3
3
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
|
-
describe Pager do
|
6
|
+
describe CommandKit::Pager do
|
7
7
|
module TestPager
|
8
8
|
class TestCommand
|
9
9
|
include CommandKit::Pager
|
@@ -19,8 +19,8 @@ describe Pager do
|
|
19
19
|
|
20
20
|
subject { command_class.new(env: {'PAGER' => pager}) }
|
21
21
|
|
22
|
-
it "must set @
|
23
|
-
expect(subject.instance_variable_get('@
|
22
|
+
it "must set @pager_command to the PAGER env variable" do
|
23
|
+
expect(subject.instance_variable_get('@pager_command')).to eq(pager)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ describe Pager do
|
|
29
29
|
subject { command_class.new(env: {'PATH' => ENV['PATH']}) }
|
30
30
|
|
31
31
|
it "must search PATH for one of the pagers" do
|
32
|
-
expect(subject.instance_variable_get('@
|
32
|
+
expect(subject.instance_variable_get('@pager_command')).to eq("less -r")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -46,9 +46,9 @@ describe Pager do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context "when @
|
49
|
+
context "when @pager_command isn't initialized" do
|
50
50
|
before do
|
51
|
-
subject.instance_variable_set('@
|
51
|
+
subject.instance_variable_set('@pager_command',nil)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "must yield stdout" do
|
@@ -58,7 +58,7 @@ describe Pager do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context "when stdout is a TTY and @
|
61
|
+
context "when stdout is a TTY and @pager_command is initialized" do
|
62
62
|
let(:pager) { 'less -r' }
|
63
63
|
|
64
64
|
subject { command_class.new(env: {'PAGER' => pager}) }
|
@@ -67,6 +67,8 @@ describe Pager do
|
|
67
67
|
let(:pager_pid) { double('pid') }
|
68
68
|
|
69
69
|
before do
|
70
|
+
expect(subject.stdout).to receive(:tty?).and_return(true)
|
71
|
+
|
70
72
|
expect(IO).to receive(:popen).with(pager,'w').and_return(pager_io)
|
71
73
|
expect(pager_io).to receive(:pid).and_return(pager_pid)
|
72
74
|
|
@@ -75,8 +77,6 @@ describe Pager do
|
|
75
77
|
end
|
76
78
|
|
77
79
|
it "must spawn a new process and yield an IO object" do
|
78
|
-
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
79
|
-
|
80
80
|
expect { |b|
|
81
81
|
subject.pager(&b)
|
82
82
|
}.to yield_with_args(pager_io)
|
@@ -84,8 +84,6 @@ describe Pager do
|
|
84
84
|
|
85
85
|
context "when Errno::EPIPE is raised" do
|
86
86
|
it "must return gracefully" do
|
87
|
-
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
88
|
-
|
89
87
|
expect {
|
90
88
|
subject.pager do
|
91
89
|
raise(Errno::EPIPE,"pipe broken")
|
@@ -97,10 +95,10 @@ describe Pager do
|
|
97
95
|
end
|
98
96
|
|
99
97
|
describe "#print_or_page" do
|
100
|
-
let(:
|
98
|
+
let(:terminal_height) { 10 }
|
101
99
|
|
102
100
|
before do
|
103
|
-
expect(subject).to receive(:
|
101
|
+
expect(subject).to receive(:terminal_height).and_return(terminal_height)
|
104
102
|
end
|
105
103
|
|
106
104
|
context "when given a String" do
|
@@ -115,7 +113,7 @@ describe Pager do
|
|
115
113
|
end
|
116
114
|
|
117
115
|
context "and the number of lines is greater than the console's height" do
|
118
|
-
let(:string) { "foo#{$/}bar#{$/}" *
|
116
|
+
let(:string) { "foo#{$/}bar#{$/}" * terminal_height }
|
119
117
|
|
120
118
|
it "must spawn a pager and puts the String to the pager" do
|
121
119
|
pager = double('pager')
|
@@ -139,7 +137,7 @@ describe Pager do
|
|
139
137
|
end
|
140
138
|
|
141
139
|
context "and the number of lines is greater than the console's height" do
|
142
|
-
let(:array) { ['foo', 'bar'] *
|
140
|
+
let(:array) { ['foo', 'bar'] * terminal_height }
|
143
141
|
|
144
142
|
it "must spawn a pager and puts the Array of Strings to the pager" do
|
145
143
|
pager = double('pager')
|
@@ -151,4 +149,69 @@ describe Pager do
|
|
151
149
|
end
|
152
150
|
end
|
153
151
|
end
|
152
|
+
|
153
|
+
describe "#pipe_to_pager" do
|
154
|
+
context "when @pager_command is initialized" do
|
155
|
+
let(:pager) { 'less' }
|
156
|
+
|
157
|
+
subject do
|
158
|
+
command_class.new(env: {'PAGER' => pager})
|
159
|
+
end
|
160
|
+
|
161
|
+
context "and when given a single String" do
|
162
|
+
let(:command) { "find ." }
|
163
|
+
|
164
|
+
it "must run the command but piped into the pager" do
|
165
|
+
expect(subject).to receive(:system).with("#{command} | #{pager}")
|
166
|
+
|
167
|
+
subject.pipe_to_pager(command)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "and when given a String and additional arguments" do
|
172
|
+
let(:command) { 'find' }
|
173
|
+
let(:arguments) { %[. -name *.md] }
|
174
|
+
|
175
|
+
let(:escaped_command) do
|
176
|
+
Shellwords.shelljoin([command,*arguments])
|
177
|
+
end
|
178
|
+
|
179
|
+
it "must shell escape the command and arguments" do
|
180
|
+
expect(subject).to receive(:system).with(
|
181
|
+
"#{escaped_command} | #{pager}"
|
182
|
+
)
|
183
|
+
|
184
|
+
subject.pipe_to_pager(command,*arguments)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "when @pager_command is not initialized" do
|
190
|
+
before do
|
191
|
+
subject.instance_variable_set('@pager_command',nil)
|
192
|
+
end
|
193
|
+
|
194
|
+
let(:command) { 'find' }
|
195
|
+
let(:arguments) { %[. -name *.md] }
|
196
|
+
|
197
|
+
it "must pass the command and any additional arguments to #system" do
|
198
|
+
expect(subject).to receive(:system).with(command,*arguments)
|
199
|
+
|
200
|
+
subject.pipe_to_pager(command,*arguments)
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when one of the arguments is not a String" do
|
204
|
+
let(:command) { :find }
|
205
|
+
let(:arguments) { ['.', :"-name", "*.md"] }
|
206
|
+
|
207
|
+
it "must convert the command to a String before calling #system" do
|
208
|
+
expect(subject).to receive(:system).with(
|
209
|
+
command.to_s, *arguments.map(&:to_s)
|
210
|
+
)
|
211
|
+
|
212
|
+
subject.pipe_to_pager(command,*arguments)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
154
217
|
end
|
data/spec/printing_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'command_kit/printing'
|
|
3
3
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
|
-
describe Printing do
|
6
|
+
describe CommandKit::Printing do
|
7
7
|
module TestPrinting
|
8
8
|
class TestCmd
|
9
9
|
|
@@ -14,11 +14,19 @@ describe Printing do
|
|
14
14
|
|
15
15
|
let(:command_class) { TestPrinting::TestCmd }
|
16
16
|
subject { command_class.new }
|
17
|
+
|
18
|
+
describe "EOL" do
|
19
|
+
subject { described_class::EOL }
|
20
|
+
|
21
|
+
it "must equal $/" do
|
22
|
+
expect(subject).to eq($/)
|
23
|
+
end
|
24
|
+
end
|
17
25
|
|
18
26
|
describe ".included" do
|
19
27
|
subject { command_class }
|
20
28
|
|
21
|
-
it { expect(command_class).to include(Stdio) }
|
29
|
+
it { expect(command_class).to include(CommandKit::Stdio) }
|
22
30
|
end
|
23
31
|
|
24
32
|
let(:nl) { $/ }
|
data/spec/program_name_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/sudo_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_kit/sudo'
|
3
|
+
|
4
|
+
describe CommandKit::Sudo do
|
5
|
+
module TestSudo
|
6
|
+
class TestCommand
|
7
|
+
include CommandKit::Sudo
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:command_class) { TestSudo::TestCommand }
|
12
|
+
subject { command_class.new }
|
13
|
+
|
14
|
+
describe "#sudo" do
|
15
|
+
let(:command) { "ls" }
|
16
|
+
let(:arguments) { ["-la", "~root"] }
|
17
|
+
let(:status) { double(:status) }
|
18
|
+
|
19
|
+
context "on UNIX" do
|
20
|
+
context "when the UID is 0" do
|
21
|
+
before { allow(Process).to receive(:uid).and_return(0) }
|
22
|
+
|
23
|
+
it "must execute the command without sudo" do
|
24
|
+
expect(subject).to receive(:system).with(command,*arguments).and_return(status)
|
25
|
+
|
26
|
+
expect(subject.sudo(command,*arguments)).to be(status)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the UID is not 0" do
|
31
|
+
before { allow(Process).to receive(:uid).and_return(1000) }
|
32
|
+
|
33
|
+
it "must execute the command with 'sudo ...'" do
|
34
|
+
expect(subject).to receive(:system).with('sudo',command,*arguments).and_return(status)
|
35
|
+
|
36
|
+
expect(subject.sudo(command,*arguments)).to be(status)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "on Windows" do
|
42
|
+
subject { command_class.new(os: :windows) }
|
43
|
+
|
44
|
+
it "must execute the command with 'runas /user:administrator ...'" do
|
45
|
+
expect(subject).to receive(:system).with('runas','/user:administrator',command,*arguments).and_return(status)
|
46
|
+
|
47
|
+
expect(subject.sudo(command,*arguments)).to be(status)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'command_kit/
|
2
|
+
require 'command_kit/terminal'
|
3
3
|
|
4
4
|
require 'stringio'
|
5
5
|
|
6
|
-
describe
|
7
|
-
module
|
6
|
+
describe CommandKit::Terminal do
|
7
|
+
module TestTerminal
|
8
8
|
class TestCommand
|
9
|
-
include CommandKit::
|
9
|
+
include CommandKit::Terminal
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:command_class) {
|
13
|
+
let(:command_class) { TestTerminal::TestCommand }
|
14
14
|
subject { command_class.new }
|
15
15
|
|
16
|
-
describe "#
|
16
|
+
describe "#terminal?" do
|
17
17
|
context "when stdout is connected to a TTY" do
|
18
18
|
subject { command_class.new(stdout: STDOUT) }
|
19
19
|
|
20
20
|
it do
|
21
21
|
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
22
22
|
|
23
|
-
expect(subject.
|
23
|
+
expect(subject.terminal?).to be(true)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,7 +28,7 @@ describe Console do
|
|
28
28
|
subject { command_class.new(stdout: StringIO.new) }
|
29
29
|
|
30
30
|
it do
|
31
|
-
expect(subject.
|
31
|
+
expect(subject.terminal?).to be(false)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -38,19 +38,19 @@ describe Console do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it do
|
41
|
-
expect(subject.
|
41
|
+
expect(subject.terminal?).to be(false)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe "#
|
46
|
+
describe "#tty?" do
|
47
47
|
context "when stdout is connected to a TTY" do
|
48
48
|
subject { command_class.new(stdout: STDOUT) }
|
49
49
|
|
50
50
|
it do
|
51
51
|
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
52
52
|
|
53
|
-
expect(subject.
|
53
|
+
expect(subject.tty?).to be(true)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -58,7 +58,7 @@ describe Console do
|
|
58
58
|
subject { command_class.new(stdout: StringIO.new) }
|
59
59
|
|
60
60
|
it do
|
61
|
-
expect(subject.
|
61
|
+
expect(subject.tty?).to be(false)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -68,27 +68,57 @@ describe Console do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it do
|
71
|
-
expect(subject.
|
71
|
+
expect(subject.tty?).to be(false)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe "#
|
76
|
+
describe "#terminal" do
|
77
77
|
context "when stdout is connected to a TTY" do
|
78
78
|
subject { command_class.new(stdout: STDOUT) }
|
79
79
|
|
80
80
|
it do
|
81
81
|
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
82
82
|
|
83
|
-
expect(subject.
|
83
|
+
expect(subject.terminal).to eq(IO.console)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
context "when stdout is not connected to a TTY" do
|
88
88
|
subject { command_class.new(stdout: StringIO.new) }
|
89
89
|
|
90
|
-
it
|
91
|
-
expect(subject.
|
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)
|
92
122
|
end
|
93
123
|
|
94
124
|
context "but the LINES env variable was set" do
|
@@ -98,28 +128,28 @@ describe Console do
|
|
98
128
|
subject { command_class.new(stdout: StringIO.new, env: env) }
|
99
129
|
|
100
130
|
it "must fallback to the LINES environment variable" do
|
101
|
-
expect(subject.
|
131
|
+
expect(subject.terminal_height).to eq(lines)
|
102
132
|
end
|
103
133
|
end
|
104
134
|
end
|
105
135
|
end
|
106
136
|
|
107
|
-
describe "#
|
137
|
+
describe "#terminal_width" do
|
108
138
|
context "when stdout is connected to a TTY" do
|
109
139
|
subject { command_class.new(stdout: STDOUT) }
|
110
140
|
|
111
141
|
it do
|
112
142
|
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
113
143
|
|
114
|
-
expect(subject.
|
144
|
+
expect(subject.terminal_width).to eq(STDOUT.winsize[1])
|
115
145
|
end
|
116
146
|
end
|
117
147
|
|
118
148
|
context "when stdout is not connected to a TTY" do
|
119
149
|
subject { command_class.new(stdout: StringIO.new) }
|
120
150
|
|
121
|
-
it "must fallback to
|
122
|
-
expect(subject.
|
151
|
+
it "must fallback to DEFAULT_TERMINAL_WIDTH" do
|
152
|
+
expect(subject.terminal_width).to eq(described_class::DEFAULT_TERMINAL_WIDTH)
|
123
153
|
end
|
124
154
|
|
125
155
|
context "but the COLUMNS env variable was set" do
|
@@ -129,29 +159,29 @@ describe Console do
|
|
129
159
|
subject { command_class.new(stdout: StringIO.new, env: env) }
|
130
160
|
|
131
161
|
it "must fallback to the COLUMNS environment variable" do
|
132
|
-
expect(subject.
|
162
|
+
expect(subject.terminal_width).to eq(columns)
|
133
163
|
end
|
134
164
|
end
|
135
165
|
end
|
136
166
|
end
|
137
167
|
|
138
|
-
describe "#
|
168
|
+
describe "#terminal_size" do
|
139
169
|
context "when stdout is connected to a TTY" do
|
140
170
|
subject { command_class.new(stdout: STDOUT) }
|
141
171
|
|
142
172
|
it do
|
143
173
|
skip "STDOUT is not a TTY" unless STDOUT.tty?
|
144
174
|
|
145
|
-
expect(subject.
|
175
|
+
expect(subject.terminal_size).to eq(STDOUT.winsize)
|
146
176
|
end
|
147
177
|
end
|
148
178
|
|
149
179
|
context "when stdout is not connected to a TTY" do
|
150
180
|
subject { command_class.new(stdout: StringIO.new) }
|
151
181
|
|
152
|
-
it "must fallback to [
|
153
|
-
expect(subject.
|
154
|
-
[described_class::
|
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]
|
155
185
|
)
|
156
186
|
end
|
157
187
|
|
@@ -161,9 +191,9 @@ describe Console do
|
|
161
191
|
|
162
192
|
subject { command_class.new(stdout: StringIO.new, env: env) }
|
163
193
|
|
164
|
-
it "must fallback to the [$LINES,
|
165
|
-
expect(subject.
|
166
|
-
[lines, described_class::
|
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]
|
167
197
|
)
|
168
198
|
end
|
169
199
|
end
|
@@ -174,9 +204,9 @@ describe Console do
|
|
174
204
|
|
175
205
|
subject { command_class.new(stdout: StringIO.new, env: env) }
|
176
206
|
|
177
|
-
it "must fallback to the [
|
178
|
-
expect(subject.
|
179
|
-
[described_class::
|
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]
|
180
210
|
)
|
181
211
|
end
|
182
212
|
end
|
@@ -191,7 +221,7 @@ describe Console do
|
|
191
221
|
subject { command_class.new(stdout: StringIO.new, env: env) }
|
192
222
|
|
193
223
|
it "must fallback to the [LINES, COLUMNS]" do
|
194
|
-
expect(subject.
|
224
|
+
expect(subject.terminal_size).to eq(
|
195
225
|
[lines, columns]
|
196
226
|
)
|
197
227
|
end
|