tty 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -1
- data/.travis.yml +3 -6
- data/README.md +232 -134
- data/lib/tty/plugins/plugin.rb +56 -0
- data/lib/tty/plugins.rb +75 -0
- data/lib/tty/shell/suggestion.rb +102 -0
- data/lib/tty/shell.rb +41 -14
- data/lib/tty/system/editor.rb +111 -0
- data/lib/tty/system/which.rb +13 -1
- data/lib/tty/system.rb +44 -28
- data/lib/tty/table/border/null.rb +0 -9
- data/lib/tty/table/border/row_line.rb +21 -0
- data/lib/tty/table/border.rb +63 -32
- data/lib/tty/table/border_dsl.rb +1 -1
- data/lib/tty/table/column_set.rb +16 -17
- data/lib/tty/table/field.rb +27 -7
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/operation/alignment_set.rb +20 -25
- data/lib/tty/table/operation/escape.rb +30 -0
- data/lib/tty/table/operation/filter.rb +36 -0
- data/lib/tty/table/operation/truncation.rb +22 -11
- data/lib/tty/table/operation/wrapped.rb +21 -10
- data/lib/tty/table/operations.rb +10 -8
- data/lib/tty/table/orientation/horizontal.rb +1 -1
- data/lib/tty/table/renderer/ascii.rb +3 -3
- data/lib/tty/table/renderer/basic.rb +135 -65
- data/lib/tty/table/renderer/color.rb +1 -4
- data/lib/tty/table/renderer/unicode.rb +3 -3
- data/lib/tty/table/renderer.rb +48 -61
- data/lib/tty/table/row.rb +30 -3
- data/lib/tty/table/transformation.rb +38 -0
- data/lib/tty/table/validatable.rb +7 -5
- data/lib/tty/table.rb +78 -99
- data/lib/tty/terminal/color.rb +2 -2
- data/lib/tty/terminal/echo.rb +1 -1
- data/lib/tty/terminal/pager/basic.rb +52 -0
- data/lib/tty/terminal/pager/system.rb +39 -0
- data/lib/tty/terminal/pager.rb +95 -0
- data/lib/tty/terminal.rb +30 -1
- data/lib/tty/version.rb +1 -1
- data/lib/tty.rb +41 -1
- data/spec/spec_helper.rb +20 -0
- data/spec/tty/plugins/find_spec.rb +28 -0
- data/spec/tty/plugins/load_spec.rb +20 -0
- data/spec/tty/plugins/plugin/load_spec.rb +30 -0
- data/spec/tty/plugins/plugin/new_spec.rb +18 -0
- data/spec/tty/shell/suggest_spec.rb +50 -0
- data/spec/tty/support/conversion_spec.rb +3 -3
- data/spec/tty/support/delegatable_spec.rb +1 -1
- data/spec/tty/support/equatable_spec.rb +6 -9
- data/spec/tty/system/editor/available_spec.rb +40 -0
- data/spec/tty/system/editor/build_spec.rb +40 -0
- data/spec/tty/system/editor/command_spec.rb +16 -0
- data/spec/tty/system/editor/executables_spec.rb +13 -0
- data/spec/tty/system/editor/invoke_spec.rb +38 -0
- data/spec/tty/system/editor/open_spec.rb +27 -0
- data/spec/tty/system/platform_spec.rb +4 -6
- data/spec/tty/system/which/which_spec.rb +48 -0
- data/spec/tty/system/which_spec.rb +8 -34
- data/spec/tty/table/border/ascii/rendering_spec.rb +19 -5
- data/spec/tty/table/border/new_spec.rb +1 -1
- data/spec/tty/table/border/null/rendering_spec.rb +24 -8
- data/spec/tty/table/border/unicode/rendering_spec.rb +19 -5
- data/spec/tty/table/column_set/extract_widths_spec.rb +4 -15
- data/spec/tty/table/column_set/total_width_spec.rb +15 -0
- data/spec/tty/table/data_spec.rb +14 -0
- data/spec/tty/table/each_spec.rb +17 -4
- data/spec/tty/table/each_with_index_spec.rb +34 -6
- data/spec/tty/table/field/length_spec.rb +21 -0
- data/spec/tty/table/field/lines_spec.rb +21 -0
- data/spec/tty/table/filter_spec.rb +23 -0
- data/spec/tty/table/header/call_spec.rb +1 -1
- data/spec/tty/table/header/height_spec.rb +27 -0
- data/spec/tty/table/initialize_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/call_spec.rb +39 -0
- data/spec/tty/table/operation/escape/call_spec.rb +16 -0
- data/spec/tty/table/operation/filter/call_spec.rb +17 -0
- data/spec/tty/table/operation/truncation/call_spec.rb +15 -10
- data/spec/tty/table/operation/truncation/truncate_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/call_spec.rb +15 -10
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +1 -1
- data/spec/tty/table/operations/new_spec.rb +4 -4
- data/spec/tty/table/options_spec.rb +0 -28
- data/spec/tty/table/orientation_spec.rb +5 -6
- data/spec/tty/table/properties_spec.rb +1 -4
- data/spec/tty/table/render_spec.rb +57 -0
- data/spec/tty/table/{renders_with_spec.rb → render_with_spec.rb} +29 -10
- data/spec/tty/table/renderer/ascii/render_spec.rb +68 -0
- data/spec/tty/table/renderer/ascii/separator_spec.rb +28 -0
- data/spec/tty/table/renderer/basic/alignment_spec.rb +18 -16
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +17 -12
- data/spec/tty/table/renderer/basic/filter_spec.rb +53 -0
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +135 -0
- data/spec/tty/table/renderer/basic/new_spec.rb +13 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +48 -0
- data/spec/tty/table/renderer/basic/render_spec.rb +19 -121
- data/spec/tty/table/renderer/basic/separator_spec.rb +14 -48
- data/spec/tty/table/renderer/basic/truncation_spec.rb +35 -0
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +40 -0
- data/spec/tty/table/{border_spec.rb → renderer/border_spec.rb} +17 -20
- data/spec/tty/table/renderer/select_spec.rb +22 -0
- data/spec/tty/table/{border → renderer}/style_spec.rb +13 -14
- data/spec/tty/table/renderer/unicode/render_spec.rb +68 -0
- data/spec/tty/table/renderer/unicode/separator_spec.rb +26 -0
- data/spec/tty/table/rotate_spec.rb +2 -3
- data/spec/tty/table/row/call_spec.rb +1 -1
- data/spec/tty/table/row/each_spec.rb +31 -0
- data/spec/tty/table/row/height_spec.rb +27 -0
- data/spec/tty/table/to_s_spec.rb +3 -3
- data/spec/tty/table/transformation/extract_tuples_spec.rb +35 -0
- data/spec/tty/table/validatable/validate_options_spec.rb +1 -2
- data/spec/tty/terminal/home_spec.rb +3 -3
- data/spec/tty/terminal/page_spec.rb +13 -0
- data/spec/tty/terminal/pager/available_spec.rb +40 -0
- data/spec/tty/terminal/pager/basic/page_spec.rb +54 -0
- data/spec/tty/terminal/pager/command_spec.rb +16 -0
- data/spec/tty/terminal/pager/executables_spec.rb +13 -0
- data/spec/tty/terminal/pager/page_spec.rb +47 -0
- data/spec/tty/terminal/pager/system/page_spec.rb +29 -0
- data/spec/tty/text/distance/distance_spec.rb +12 -0
- data/tty.gemspec +7 -3
- metadata +160 -27
- data/spec/tty/table/operation/alignment_set/align_rows_spec.rb +0 -53
- data/spec/tty/table/renderer/pick_renderer_spec.rb +0 -25
- data/spec/tty/table/renderer_spec.rb +0 -49
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
|
5
|
+
if ENV['TRAVIS'] || ENV['COVERAGE']
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
add_filter 'spec'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
3
19
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
20
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
21
|
|
@@ -15,3 +31,7 @@ class String
|
|
15
31
|
gsub(/^[ \t]*/, '').chomp
|
16
32
|
end
|
17
33
|
end
|
34
|
+
|
35
|
+
unless defined?(Gem::Specification)
|
36
|
+
Gem::Specification = Struct.new(:name, :version)
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Plugins, '#find' do
|
6
|
+
let(:object) { described_class }
|
7
|
+
let(:tty_gem) { Gem::Specification.new('tty-console', '3.1.3')}
|
8
|
+
let(:gem) { Gem::Specification.new('thor', '1.1.4') }
|
9
|
+
let(:gems) { [gem, tty_gem] }
|
10
|
+
|
11
|
+
before {
|
12
|
+
Gem.stub(:refresh)
|
13
|
+
Gem::Specification.stub(:each).and_yield(tty_gem).and_yield(gem)
|
14
|
+
}
|
15
|
+
|
16
|
+
subject { object.new }
|
17
|
+
|
18
|
+
it 'inserts the tty gem only' do
|
19
|
+
found = subject.find
|
20
|
+
expect(found).to have(1).item
|
21
|
+
expect(found.first.gem).to eql(tty_gem)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'retrieves only tty plugin' do
|
25
|
+
subject.find
|
26
|
+
expect(subject.names['console'].gem).to eql(tty_gem)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Plugins, '#load' do
|
6
|
+
let(:object) { described_class }
|
7
|
+
let(:plugin) { double(:plugin, :enabled? => false) }
|
8
|
+
let(:plugins) { [plugin, plugin]}
|
9
|
+
|
10
|
+
subject { object.new }
|
11
|
+
|
12
|
+
before {
|
13
|
+
subject.stub(:plugins).and_return(plugins)
|
14
|
+
}
|
15
|
+
|
16
|
+
it "activates all plugins" do
|
17
|
+
plugin.should_receive(:load!).twice()
|
18
|
+
subject.load
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Plugin, '#load!' do
|
6
|
+
let(:gem) { Gem::Specification.new('tty-console', '3.1.3')}
|
7
|
+
let(:name) { 'console'}
|
8
|
+
let(:input) { StringIO.new }
|
9
|
+
let(:output) { StringIO.new }
|
10
|
+
|
11
|
+
subject { described_class.new(name, gem) }
|
12
|
+
|
13
|
+
context 'when gem unsuccessfully loaded' do
|
14
|
+
before { Kernel.stub(:require) { raise LoadError } }
|
15
|
+
|
16
|
+
it 'fails to load the gem' do
|
17
|
+
TTY.shell.should_receive(:error).with(/Unable to load plugin tty-console./)
|
18
|
+
subject.load!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when gem unsuccessfully required' do
|
23
|
+
before { Kernel.stub(:require) { raise StandardError } }
|
24
|
+
|
25
|
+
it 'fails to require the gem' do
|
26
|
+
TTY.shell.should_receive(:error).with(/Unable to load plugin tty-console./)
|
27
|
+
subject.load!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Plugin, '#new' do
|
6
|
+
let(:gem) { Gem::Specification.new('tty-console', '3.1.3')}
|
7
|
+
let(:name) { 'console'}
|
8
|
+
|
9
|
+
subject { described_class.new(name, gem) }
|
10
|
+
|
11
|
+
its(:name) { should == name }
|
12
|
+
|
13
|
+
its(:gem) { should == gem }
|
14
|
+
|
15
|
+
its(:enabled) { should be_false }
|
16
|
+
|
17
|
+
its(:gem_name) { should == "tty-#{name}" }
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Shell, '#suggest' do
|
6
|
+
let(:input) { StringIO.new }
|
7
|
+
let(:output) { StringIO.new }
|
8
|
+
let(:object) { described_class }
|
9
|
+
let(:possible) { ['status', 'stage', 'stash', 'commit', 'branch', 'blame'] }
|
10
|
+
|
11
|
+
subject(:shell) { object.new(input, output) }
|
12
|
+
|
13
|
+
after { output.rewind }
|
14
|
+
|
15
|
+
context 'when few matches' do
|
16
|
+
let(:string) { 'sta' }
|
17
|
+
|
18
|
+
it 'suggests few matches' do
|
19
|
+
shell.suggest(string, possible)
|
20
|
+
expect(output.string).to eql("Did you mean one of these?\n stage\n stash\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when one match' do
|
25
|
+
let(:string) { 'b' }
|
26
|
+
|
27
|
+
it 'suggests a single match' do
|
28
|
+
shell.suggest(string, possible)
|
29
|
+
expect(output.string).to eql("Did you mean this?\n blame\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when one match' do
|
34
|
+
let(:string) { 'co' }
|
35
|
+
|
36
|
+
it 'suggests a single match' do
|
37
|
+
shell.suggest(string, possible)
|
38
|
+
expect(output.string).to eql("Did you mean this?\n commit\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when custom options' do
|
43
|
+
let(:string) { 'b' }
|
44
|
+
|
45
|
+
it 'suggests with different text and indentation' do
|
46
|
+
shell.suggest(string, possible, :indent => 4, :single_text => 'Perhaps you meant?')
|
47
|
+
expect(output.string).to eql("Perhaps you meant?\n blame\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -23,16 +23,16 @@ describe TTY::Conversion do
|
|
23
23
|
|
24
24
|
context 'responds to #to_ary' do
|
25
25
|
let(:converted) { [] }
|
26
|
-
let(:enumerable) {
|
26
|
+
let(:enumerable) { double('Enumerable', :to_ary => converted) }
|
27
27
|
|
28
28
|
it { should == converted }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'does not respond to #to_ary' do
|
32
|
-
let(:enumerable) {
|
32
|
+
let(:enumerable) { double('Enumerable') }
|
33
33
|
|
34
34
|
it 'raises error' do
|
35
|
-
expect { subject}.to raise_error(TTY::TypeError)
|
35
|
+
expect { subject }.to raise_error(TTY::TypeError)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -27,7 +27,7 @@ describe TTY::Equatable do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when objects are different' do
|
30
|
-
let(:other) {
|
30
|
+
let(:other) { double('other') }
|
31
31
|
|
32
32
|
it { subject.eql?(other).should be_false }
|
33
33
|
end
|
@@ -41,7 +41,7 @@ describe TTY::Equatable do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'when objects are different' do
|
44
|
-
let(:other) {
|
44
|
+
let(:other) { double('other') }
|
45
45
|
|
46
46
|
it { (subject == other)}
|
47
47
|
end
|
@@ -54,8 +54,6 @@ describe TTY::Equatable do
|
|
54
54
|
describe '#hash' do
|
55
55
|
it { subject.hash.should eql([klass].hash) }
|
56
56
|
end
|
57
|
-
|
58
|
-
|
59
57
|
end
|
60
58
|
|
61
59
|
context 'with attributes' do
|
@@ -98,7 +96,7 @@ describe TTY::Equatable do
|
|
98
96
|
end
|
99
97
|
|
100
98
|
context 'when objects are different' do
|
101
|
-
let(:other) {
|
99
|
+
let(:other) { double('other') }
|
102
100
|
|
103
101
|
it { subject.eql?(other).should be_false }
|
104
102
|
end
|
@@ -112,7 +110,7 @@ describe TTY::Equatable do
|
|
112
110
|
end
|
113
111
|
|
114
112
|
context 'when objects are different' do
|
115
|
-
let(:other) {
|
113
|
+
let(:other) { double('other') }
|
116
114
|
|
117
115
|
it { (subject == other).should be_false }
|
118
116
|
end
|
@@ -182,7 +180,7 @@ describe TTY::Equatable do
|
|
182
180
|
end
|
183
181
|
|
184
182
|
context 'when objects are different' do
|
185
|
-
let(:other) {
|
183
|
+
let(:other) { double('other') }
|
186
184
|
|
187
185
|
it { subject.eql?(other).should be_false }
|
188
186
|
end
|
@@ -196,11 +194,10 @@ describe TTY::Equatable do
|
|
196
194
|
end
|
197
195
|
|
198
196
|
context 'when objects are different' do
|
199
|
-
let(:other) {
|
197
|
+
let(:other) { double('other') }
|
200
198
|
|
201
199
|
it { (subject == other)}
|
202
200
|
end
|
203
201
|
end
|
204
202
|
end
|
205
|
-
|
206
203
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Editor, '#available' do
|
6
|
+
let(:execs) { ['vi', 'emacs'] }
|
7
|
+
let(:editor) { 'sublime' }
|
8
|
+
let(:system) { TTY::System }
|
9
|
+
|
10
|
+
subject { described_class }
|
11
|
+
|
12
|
+
before { subject.stub(:executables).and_return(execs) }
|
13
|
+
|
14
|
+
context 'when editor exists' do
|
15
|
+
before {
|
16
|
+
system.stub(:exists?).with('vi').and_return(true)
|
17
|
+
system.stub(:exists?).with('emacs').and_return(false)
|
18
|
+
}
|
19
|
+
|
20
|
+
it 'finds single command' do
|
21
|
+
expect(subject.available).to eql('vi')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when no command exists' do
|
26
|
+
before { system.stub(:exists?).and_return(false) }
|
27
|
+
|
28
|
+
it "doesn't find command" do
|
29
|
+
expect(subject.available).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when custom command' do
|
34
|
+
before { system.stub(:exists?).with(editor).and_return(true) }
|
35
|
+
|
36
|
+
it "takes precedence over other commands" do
|
37
|
+
expect(subject.available(editor)).to eql(editor)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Editor, '#build' do
|
6
|
+
let(:file) { "/users/piotr/hello world.rb" }
|
7
|
+
let(:editor) { "vim" }
|
8
|
+
let(:object) { described_class }
|
9
|
+
|
10
|
+
subject { object.new(file) }
|
11
|
+
|
12
|
+
before { object.stub(:command).and_return(editor) }
|
13
|
+
|
14
|
+
context 'when on windows' do
|
15
|
+
before {
|
16
|
+
TTY::System.stub(:unix?).and_return(false)
|
17
|
+
TTY::System.stub(:windows?).and_return(true)
|
18
|
+
}
|
19
|
+
|
20
|
+
after {
|
21
|
+
TTY::System.unstub(:unix?)
|
22
|
+
TTY::System.unstub(:windows?)
|
23
|
+
}
|
24
|
+
|
25
|
+
it "doesn't shell escape" do
|
26
|
+
expect(subject.build).to eql("vim \\users\\piotr\\hello world.rb")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when on unix' do
|
31
|
+
|
32
|
+
before { TTY::System.stub(:unix?).and_return(true) }
|
33
|
+
|
34
|
+
after { TTY::System.unstub(:unix?) }
|
35
|
+
|
36
|
+
it 'escapes shell' do
|
37
|
+
expect(subject.build).to eql("vim /users/piotr/hello\\ world.rb")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Editor, '#command' do
|
6
|
+
let(:editor) { 'vim' }
|
7
|
+
|
8
|
+
subject { described_class }
|
9
|
+
|
10
|
+
context 'when custom command' do
|
11
|
+
it 'searches available commands' do
|
12
|
+
subject.should_receive(:available).with(editor)
|
13
|
+
subject.command(editor)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Editor, '#invoke' do
|
6
|
+
let(:file) { "hello.rb" }
|
7
|
+
let(:editor) { "vim" }
|
8
|
+
let(:object) { described_class }
|
9
|
+
|
10
|
+
subject { object.new(file) }
|
11
|
+
|
12
|
+
before {
|
13
|
+
object.stub(:command).and_return(editor)
|
14
|
+
TTY::System.stub(:unix?).and_return(true)
|
15
|
+
}
|
16
|
+
|
17
|
+
after {
|
18
|
+
TTY::System.unstub(:unix?)
|
19
|
+
}
|
20
|
+
|
21
|
+
context 'when invokes' do
|
22
|
+
before { subject.stub(:system).and_return(true) }
|
23
|
+
|
24
|
+
it 'executes editor command' do
|
25
|
+
subject.should_receive(:system).with(editor, file)
|
26
|
+
subject.invoke
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when fails to invoke' do
|
31
|
+
|
32
|
+
before { subject.stub(:system).and_return(false) }
|
33
|
+
|
34
|
+
it 'raises an error' do
|
35
|
+
expect { subject.invoke }.to raise_error(TTY::CommandInvocationError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Editor, '#open' do
|
6
|
+
let(:file) { "hello.rb" }
|
7
|
+
|
8
|
+
subject { described_class }
|
9
|
+
|
10
|
+
context 'when no editor' do
|
11
|
+
before { subject.stub(:command).and_return(nil) }
|
12
|
+
|
13
|
+
it 'raises error' do
|
14
|
+
expect { subject.open(file) }.to raise_error(TTY::CommandInvocationError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when editor' do
|
19
|
+
before { subject.stub(:command).and_return('vim') }
|
20
|
+
|
21
|
+
it 'invokes editor' do
|
22
|
+
invocable = double(:invocable, :invoke => nil)
|
23
|
+
subject.should_receive(:new).with(file).and_return(invocable)
|
24
|
+
subject.open(file)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -11,6 +11,10 @@ describe TTY::System, '#platform' do
|
|
11
11
|
|
12
12
|
it { should respond_to(:which) }
|
13
13
|
|
14
|
+
it { should respond_to(:exists?) }
|
15
|
+
|
16
|
+
it { should respond_to(:editor) }
|
17
|
+
|
14
18
|
it 'checks if windows' do
|
15
19
|
RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'windows'
|
16
20
|
subject.windows?.should be_true
|
@@ -20,10 +24,4 @@ describe TTY::System, '#platform' do
|
|
20
24
|
RbConfig::CONFIG.stub(:[]).with('host_os').and_return 'darwin'
|
21
25
|
subject.unix?.should be_true
|
22
26
|
end
|
23
|
-
|
24
|
-
it 'delegates to which' do
|
25
|
-
command = 'ruby'
|
26
|
-
TTY::System::Which.should_receive(:new).with(command)
|
27
|
-
subject.which(command)
|
28
|
-
end
|
29
27
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::System::Which, '#which' do
|
6
|
+
let(:path) { "/usr/local/bin:/usr/local/git/bin" }
|
7
|
+
let(:extension) { '.bat' }
|
8
|
+
|
9
|
+
subject { described_class.new(command) }
|
10
|
+
|
11
|
+
context 'without extension' do
|
12
|
+
let(:command) { 'ruby' }
|
13
|
+
|
14
|
+
before {
|
15
|
+
ENV.stub(:[]).with('PATHEXT').and_return(nil)
|
16
|
+
ENV.stub(:[]).with('PATH').and_return(path)
|
17
|
+
}
|
18
|
+
|
19
|
+
it 'finds command' do
|
20
|
+
File.stub(:executable?) { true }
|
21
|
+
expect(subject.which).to eql "/usr/local/bin/ruby"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't find command" do
|
25
|
+
File.stub(:executable?) { false }
|
26
|
+
expect(subject.which).to be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with extension' do
|
31
|
+
let(:command) { 'ruby' }
|
32
|
+
|
33
|
+
before {
|
34
|
+
ENV.stub(:[]).with('PATHEXT').and_return(extension)
|
35
|
+
ENV.stub(:[]).with('PATH').and_return(path)
|
36
|
+
}
|
37
|
+
|
38
|
+
it 'finds command' do
|
39
|
+
File.stub(:executable?) { true }
|
40
|
+
expect(subject.which).to eql "/usr/local/bin/ruby.bat"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "doesn't find command" do
|
44
|
+
File.stub(:executable?) { false }
|
45
|
+
expect(subject.which).to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,41 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
describe TTY::System
|
5
|
-
let(:
|
6
|
-
let(:
|
5
|
+
describe TTY::System, '#which' do
|
6
|
+
let(:command) { 'ruby' }
|
7
|
+
let(:which) { double(:which, :which => command) }
|
7
8
|
|
8
|
-
|
9
|
-
before {
|
10
|
-
ENV.stub(:[]).with('PATHEXT').and_return(nil)
|
11
|
-
ENV.stub(:[]).with('PATH').and_return(path)
|
12
|
-
}
|
9
|
+
subject { described_class }
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
it "doesn't find command" do
|
20
|
-
File.stub(:executable?) { false }
|
21
|
-
expect(subject.which("ruby")).to be_nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'with extension' do
|
26
|
-
before {
|
27
|
-
ENV.stub(:[]).with('PATHEXT').and_return(extension)
|
28
|
-
ENV.stub(:[]).with('PATH').and_return(path)
|
29
|
-
}
|
30
|
-
|
31
|
-
it 'finds command' do
|
32
|
-
File.stub(:executable?) { true }
|
33
|
-
expect(subject.which("ruby")).to eql "/usr/local/bin/ruby.bat"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "doesn't find command" do
|
37
|
-
File.stub(:executable?) { false }
|
38
|
-
expect(subject.which("ruby")).to be_nil
|
39
|
-
end
|
11
|
+
it 'seeks system command' do
|
12
|
+
TTY::System::Which.should_receive(:new).with(command).and_return(which)
|
13
|
+
expect(subject.which(command)).to eql(command)
|
40
14
|
end
|
41
15
|
end
|
@@ -4,10 +4,11 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe TTY::Table::Border::ASCII, '#rendering' do
|
6
6
|
|
7
|
-
subject { described_class.new
|
7
|
+
subject { described_class.new(column_widths) }
|
8
8
|
|
9
9
|
context 'with empty row' do
|
10
|
-
let(:row) { [] }
|
10
|
+
let(:row) { TTY::Table::Row.new([]) }
|
11
|
+
let(:column_widths) { []}
|
11
12
|
|
12
13
|
it 'draws top line' do
|
13
14
|
subject.top_line.should == "++"
|
@@ -22,12 +23,13 @@ describe TTY::Table::Border::ASCII, '#rendering' do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'draws row line' do
|
25
|
-
subject.row_line.should == "||"
|
26
|
+
subject.row_line(row).should == "||"
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
30
|
context 'with row' do
|
30
|
-
let(:
|
31
|
+
let(:column_widths) { [2,2,2] }
|
32
|
+
let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }
|
31
33
|
|
32
34
|
it 'draws top line' do
|
33
35
|
subject.top_line.should == "+--+--+--+"
|
@@ -42,8 +44,20 @@ describe TTY::Table::Border::ASCII, '#rendering' do
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it 'draws row line' do
|
45
|
-
subject.row_line.should == "|a1|a2|a3|"
|
47
|
+
subject.row_line(row).should == "|a1|a2|a3|"
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
51
|
+
context 'with multiline row' do
|
52
|
+
let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }
|
53
|
+
let(:column_widths) { [2,2,2]}
|
54
|
+
|
55
|
+
it 'draws row line' do
|
56
|
+
subject.row_line(row).should == <<-EOS.normalize
|
57
|
+
|a1|a2|a3|
|
58
|
+
|b1| | |
|
59
|
+
|c1| | |
|
60
|
+
EOS
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|