tty 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -1
- data/README.md +55 -28
- data/Rakefile +5 -9
- data/images/tty.png +0 -0
- data/lib/tty.rb +7 -1
- data/lib/tty/coercer/boolean.rb +6 -9
- data/lib/tty/coercer/float.rb +14 -17
- data/lib/tty/coercer/integer.rb +14 -17
- data/lib/tty/coercer/range.rb +6 -7
- data/lib/tty/logger.rb +23 -9
- data/lib/tty/plugins.rb +3 -6
- data/lib/tty/plugins/plugin.rb +4 -7
- data/lib/tty/shell.rb +20 -12
- data/lib/tty/shell/question.rb +41 -48
- data/lib/tty/shell/question/modifier.rb +5 -8
- data/lib/tty/shell/question/validation.rb +8 -7
- data/lib/tty/shell/reader.rb +28 -19
- data/lib/tty/shell/response.rb +26 -22
- data/lib/tty/shell/statement.rb +13 -9
- data/lib/tty/shell/suggestion.rb +17 -13
- data/lib/tty/support/coercion.rb +5 -6
- data/lib/tty/support/conversion.rb +7 -6
- data/lib/tty/support/delegatable.rb +5 -5
- data/lib/tty/support/unicode.rb +3 -4
- data/lib/tty/support/utils.rb +1 -2
- data/lib/tty/system.rb +13 -6
- data/lib/tty/system/editor.rb +21 -18
- data/lib/tty/system/which.rb +3 -5
- data/lib/tty/table.rb +18 -22
- data/lib/tty/table/border.rb +2 -4
- data/lib/tty/table/border/ascii.rb +3 -2
- data/lib/tty/table/border/null.rb +1 -3
- data/lib/tty/table/border/row_line.rb +1 -4
- data/lib/tty/table/border/unicode.rb +3 -2
- data/lib/tty/table/border_dsl.rb +21 -17
- data/lib/tty/table/border_options.rb +6 -5
- data/lib/tty/table/column_set.rb +11 -7
- data/lib/tty/table/columns.rb +19 -16
- data/lib/tty/table/error.rb +1 -3
- data/lib/tty/table/field.rb +30 -12
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/indentation.rb +1 -3
- data/lib/tty/table/operation/alignment.rb +8 -9
- data/lib/tty/table/operation/alignment_set.rb +6 -5
- data/lib/tty/table/operation/escape.rb +3 -3
- data/lib/tty/table/operation/filter.rb +3 -4
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -4
- data/lib/tty/table/operations.rb +19 -22
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +9 -6
- data/lib/tty/table/orientation/vertical.rb +10 -7
- data/lib/tty/table/padder.rb +46 -8
- data/lib/tty/table/renderer.rb +21 -14
- data/lib/tty/table/renderer/ascii.rb +6 -5
- data/lib/tty/table/renderer/basic.rb +18 -19
- data/lib/tty/table/renderer/unicode.rb +11 -5
- data/lib/tty/table/row.rb +36 -20
- data/lib/tty/table/transformation.rb +6 -5
- data/lib/tty/table/validatable.rb +32 -17
- data/lib/tty/terminal.rb +26 -42
- data/lib/tty/terminal/color.rb +10 -12
- data/lib/tty/terminal/echo.rb +4 -7
- data/lib/tty/terminal/home.rb +3 -10
- data/lib/tty/terminal/pager.rb +11 -10
- data/lib/tty/terminal/pager/basic.rb +3 -6
- data/lib/tty/terminal/pager/system.rb +2 -5
- data/lib/tty/text.rb +7 -10
- data/lib/tty/text/distance.rb +2 -4
- data/lib/tty/text/truncation.rb +1 -3
- data/lib/tty/text/wrapping.rb +1 -3
- data/lib/tty/vector.rb +3 -5
- data/lib/tty/version.rb +2 -2
- data/spec/spec_helper.rb +4 -11
- data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
- data/spec/tty/coercer/float/coerce_spec.rb +6 -4
- data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
- data/spec/tty/coercer/range/coerce_spec.rb +12 -11
- data/spec/tty/logger/log_spec.rb +23 -0
- data/spec/tty/logger/new_spec.rb +14 -14
- data/spec/tty/logger/valid_level_spec.rb +6 -6
- data/spec/tty/plugins/find_spec.rb +4 -4
- data/spec/tty/plugins/load_spec.rb +4 -5
- data/spec/tty/plugins/plugin/load_spec.rb +10 -8
- data/spec/tty/plugins/plugin/new_spec.rb +7 -7
- data/spec/tty/shell/ask_spec.rb +6 -7
- data/spec/tty/shell/error_spec.rb +1 -2
- data/spec/tty/shell/print_table_spec.rb +1 -2
- data/spec/tty/shell/question/argument_spec.rb +1 -1
- data/spec/tty/shell/question/character_spec.rb +11 -3
- data/spec/tty/shell/question/default_spec.rb +3 -3
- data/spec/tty/shell/question/in_spec.rb +1 -1
- data/spec/tty/shell/question/initialize_spec.rb +8 -11
- data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
- data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
- data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
- data/spec/tty/shell/question/modify_spec.rb +1 -1
- data/spec/tty/shell/question/valid_spec.rb +4 -4
- data/spec/tty/shell/question/validate_spec.rb +4 -4
- data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
- data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
- data/spec/tty/shell/reader/getc_spec.rb +16 -14
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/response/read_char_spec.rb +1 -2
- data/spec/tty/shell/response/read_date_spec.rb +1 -1
- data/spec/tty/shell/response/read_email_spec.rb +1 -1
- data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
- data/spec/tty/shell/response/read_number_spec.rb +1 -2
- data/spec/tty/shell/response/read_range_spec.rb +2 -2
- data/spec/tty/shell/response/read_spec.rb +7 -7
- data/spec/tty/shell/response/read_string_spec.rb +2 -2
- data/spec/tty/shell/say_spec.rb +1 -1
- data/spec/tty/shell/statement/initialize_spec.rb +3 -3
- data/spec/tty/shell/suggest_spec.rb +1 -1
- data/spec/tty/shell/warn_spec.rb +1 -2
- data/spec/tty/support/coercion_spec.rb +10 -10
- data/spec/tty/support/conversion_spec.rb +9 -9
- data/spec/tty/support/delegatable_spec.rb +7 -5
- data/spec/tty/support/equatable_spec.rb +32 -34
- data/spec/tty/support/fixtures/classes.rb +4 -2
- data/spec/tty/system/editor/available_spec.rb +12 -12
- data/spec/tty/system/editor/build_spec.rb +8 -16
- data/spec/tty/system/editor/command_spec.rb +3 -2
- data/spec/tty/system/editor/executables_spec.rb +3 -3
- data/spec/tty/system/editor/invoke_spec.rb +10 -14
- data/spec/tty/system/editor/open_spec.rb +9 -7
- data/spec/tty/system/platform_spec.rb +32 -13
- data/spec/tty/system/which/which_spec.rb +9 -9
- data/spec/tty/system/which_spec.rb +4 -4
- data/spec/tty/table/access_spec.rb +24 -21
- data/spec/tty/table/add_row_spec.rb +2 -2
- data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
- data/spec/tty/table/border/new_spec.rb +5 -4
- data/spec/tty/table/border/null/rendering_spec.rb +12 -12
- data/spec/tty/table/border/options/from_spec.rb +2 -3
- data/spec/tty/table/border/options/new_spec.rb +4 -5
- data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
- data/spec/tty/table/border_options/new_spec.rb +20 -0
- data/spec/tty/table/border_options/update_spec.rb +18 -0
- data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
- data/spec/tty/table/column_set/total_width_spec.rb +2 -2
- data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
- data/spec/tty/table/columns/enforce_spec.rb +2 -2
- data/spec/tty/table/columns/widths_spec.rb +2 -0
- data/spec/tty/table/data_spec.rb +3 -3
- data/spec/tty/table/each_spec.rb +9 -11
- data/spec/tty/table/each_with_index_spec.rb +8 -9
- data/spec/tty/table/empty_spec.rb +3 -3
- data/spec/tty/table/eql_spec.rb +6 -6
- data/spec/tty/table/field/equality_spec.rb +11 -11
- data/spec/tty/table/field/length_spec.rb +4 -4
- data/spec/tty/table/field/lines_spec.rb +3 -3
- data/spec/tty/table/field/new_spec.rb +7 -7
- data/spec/tty/table/field/width_spec.rb +6 -4
- data/spec/tty/table/filter_spec.rb +3 -3
- data/spec/tty/table/header/call_spec.rb +3 -3
- data/spec/tty/table/header/height_spec.rb +1 -1
- data/spec/tty/table/header/new_spec.rb +5 -5
- data/spec/tty/table/header/set_spec.rb +9 -4
- data/spec/tty/table/header/to_ary_spec.rb +4 -4
- data/spec/tty/table/header_spec.rb +3 -4
- data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
- data/spec/tty/table/initialize_spec.rb +13 -13
- data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
- data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
- data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
- data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
- data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
- data/spec/tty/table/operation/escape/call_spec.rb +1 -1
- data/spec/tty/table/operation/filter/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
- data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
- data/spec/tty/table/operations/new_spec.rb +1 -1
- data/spec/tty/table/options_spec.rb +8 -8
- data/spec/tty/table/orientation_spec.rb +15 -13
- data/spec/tty/table/padder/parse_spec.rb +1 -1
- data/spec/tty/table/padder/to_s_spec.rb +14 -0
- data/spec/tty/table/padding_spec.rb +1 -1
- data/spec/tty/table/properties_spec.rb +9 -8
- data/spec/tty/table/render_spec.rb +8 -5
- data/spec/tty/table/render_with_spec.rb +5 -4
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
- data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
- data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
- data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
- data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
- data/spec/tty/table/renderer/border_spec.rb +21 -21
- data/spec/tty/table/renderer/render_spec.rb +7 -7
- data/spec/tty/table/renderer/select_spec.rb +4 -4
- data/spec/tty/table/renderer/style_spec.rb +19 -19
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
- data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
- data/spec/tty/table/renderer_spec.rb +1 -1
- data/spec/tty/table/rotate_spec.rb +27 -27
- data/spec/tty/table/row/access_spec.rb +3 -3
- data/spec/tty/table/row/call_spec.rb +4 -4
- data/spec/tty/table/row/data_spec.rb +5 -5
- data/spec/tty/table/row/each_spec.rb +1 -1
- data/spec/tty/table/row/equality_spec.rb +16 -16
- data/spec/tty/table/row/height_spec.rb +1 -1
- data/spec/tty/table/row/new_spec.rb +11 -11
- data/spec/tty/table/row/to_ary_spec.rb +3 -3
- data/spec/tty/table/to_s_spec.rb +8 -8
- data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
- data/spec/tty/table/validatable_spec.rb +14 -1
- data/spec/tty/terminal/color/code_spec.rb +3 -3
- data/spec/tty/terminal/color/remove_spec.rb +8 -9
- data/spec/tty/terminal/color/set_spec.rb +5 -6
- data/spec/tty/terminal/color_spec.rb +3 -5
- data/spec/tty/terminal/echo_spec.rb +3 -4
- data/spec/tty/terminal/home_spec.rb +12 -14
- data/spec/tty/terminal/page_spec.rb +5 -4
- data/spec/tty/terminal/pager/available_spec.rb +11 -11
- data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
- data/spec/tty/terminal/pager/command_spec.rb +2 -2
- data/spec/tty/terminal/pager/executables_spec.rb +3 -3
- data/spec/tty/terminal/pager/page_spec.rb +8 -10
- data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
- data/spec/tty/terminal/size_spec.rb +39 -36
- data/spec/tty/text/distance/distance_spec.rb +13 -13
- data/spec/tty/text/distance/initialize_spec.rb +4 -4
- data/spec/tty/text/distance_spec.rb +2 -2
- data/spec/tty/text/truncate_spec.rb +2 -3
- data/spec/tty/text/truncation/initialize_spec.rb +9 -9
- data/spec/tty/text/truncation/truncate_spec.rb +14 -14
- data/spec/tty/text/wrap_spec.rb +2 -3
- data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
- data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
- data/spec/tty/tty_spec.rb +22 -0
- data/spec/tty/vector/new_spec.rb +7 -7
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/metrics/cane.rake +2 -0
- data/tasks/metrics/flog.rake +2 -0
- data/tasks/metrics/heckle.rake +15 -0
- data/tasks/metrics/reek.rake +2 -0
- data/tasks/spec.rake +29 -0
- data/tty.gemspec +5 -12
- metadata +34 -91
- data/.rvmrc +0 -34
@@ -1,40 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::System::Editor, '#available' do
|
6
|
-
let(:execs)
|
7
|
-
let(:
|
6
|
+
let(:execs) { ['vi', 'emacs'] }
|
7
|
+
let(:name) { 'sublime' }
|
8
8
|
let(:system) { TTY::System }
|
9
9
|
|
10
|
-
subject { described_class }
|
10
|
+
subject(:editor) { described_class }
|
11
11
|
|
12
|
-
before {
|
12
|
+
before { allow(editor).to receive(:executables).and_return(execs) }
|
13
13
|
|
14
14
|
context 'when editor exists' do
|
15
15
|
before {
|
16
|
-
system.
|
17
|
-
system.
|
16
|
+
allow(system).to receive(:exists?).with('vi').and_return(true)
|
17
|
+
allow(system).to receive(:exists?).with('emacs').and_return(false)
|
18
18
|
}
|
19
19
|
|
20
20
|
it 'finds single command' do
|
21
|
-
expect(
|
21
|
+
expect(editor.available).to eql('vi')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when no command exists' do
|
26
|
-
before { system.
|
26
|
+
before { allow(system).to receive(:exists?).and_return(false) }
|
27
27
|
|
28
28
|
it "doesn't find command" do
|
29
|
-
expect(
|
29
|
+
expect(editor.available).to be_nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'when custom command' do
|
34
|
-
before { system.
|
34
|
+
before { allow(system).to receive(:exists?).with(name).and_return(true) }
|
35
35
|
|
36
36
|
it "takes precedence over other commands" do
|
37
|
-
expect(
|
37
|
+
expect(editor.available(name)).to eql(name)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,25 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::System::Editor, '#build' do
|
6
6
|
let(:file) { "/users/piotr/hello world.rb" }
|
7
|
-
let(:
|
7
|
+
let(:name) { "vim" }
|
8
8
|
let(:object) { described_class }
|
9
9
|
|
10
|
-
subject { object.new(file) }
|
10
|
+
subject(:editor) { object.new(file) }
|
11
11
|
|
12
|
-
before { object.
|
12
|
+
before { allow(object).to receive(:command).and_return(name) }
|
13
13
|
|
14
14
|
context 'when on windows' do
|
15
15
|
before {
|
16
|
-
TTY::System.
|
17
|
-
TTY::System.
|
18
|
-
}
|
19
|
-
|
20
|
-
after {
|
21
|
-
TTY::System.unstub(:unix?)
|
22
|
-
TTY::System.unstub(:windows?)
|
16
|
+
allow(TTY::System).to receive(:unix?).and_return(false)
|
17
|
+
allow(TTY::System).to receive(:windows?).and_return(true)
|
23
18
|
}
|
24
19
|
|
25
20
|
it "doesn't shell escape" do
|
@@ -28,13 +23,10 @@ describe TTY::System::Editor, '#build' do
|
|
28
23
|
end
|
29
24
|
|
30
25
|
context 'when on unix' do
|
31
|
-
|
32
|
-
before { TTY::System.stub(:unix?).and_return(true) }
|
33
|
-
|
34
|
-
after { TTY::System.unstub(:unix?) }
|
26
|
+
before { allow(TTY::System).to receive(:unix?).and_return(true) }
|
35
27
|
|
36
28
|
it 'escapes shell' do
|
37
|
-
expect(
|
29
|
+
expect(editor.build).to eql("vim /users/piotr/hello\\ world.rb")
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,8 +9,9 @@ describe TTY::System::Editor, '#command' do
|
|
9
9
|
|
10
10
|
context 'when custom command' do
|
11
11
|
it 'searches available commands' do
|
12
|
-
subject.
|
12
|
+
allow(subject).to receive(:available)
|
13
13
|
subject.command(editor)
|
14
|
+
expect(subject).to have_received(:available).with(editor)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -7,7 +7,7 @@ describe TTY::System::Editor, '#executables' do
|
|
7
7
|
|
8
8
|
subject { object.executables }
|
9
9
|
|
10
|
-
it {
|
10
|
+
it { is_expected.to be_an Array }
|
11
11
|
|
12
|
-
it {
|
12
|
+
it { is_expected.to include('vi') }
|
13
13
|
end
|
@@ -1,38 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::System::Editor, '#invoke' do
|
6
6
|
let(:file) { "hello.rb" }
|
7
|
-
let(:
|
7
|
+
let(:name) { "vim" }
|
8
8
|
let(:object) { described_class }
|
9
9
|
|
10
|
-
subject { object.new(file) }
|
10
|
+
subject(:editor) { object.new(file) }
|
11
11
|
|
12
12
|
before {
|
13
|
-
object.
|
14
|
-
TTY::System.
|
15
|
-
}
|
16
|
-
|
17
|
-
after {
|
18
|
-
TTY::System.unstub(:unix?)
|
13
|
+
allow(object).to receive(:command).and_return(name)
|
14
|
+
allow(TTY::System).to receive(:unix?).and_return(true)
|
19
15
|
}
|
20
16
|
|
21
17
|
context 'when invokes' do
|
22
|
-
before {
|
18
|
+
before { allow(editor).to receive(:system).and_return(true) }
|
23
19
|
|
24
20
|
it 'executes editor command' do
|
25
|
-
|
26
|
-
|
21
|
+
editor.invoke
|
22
|
+
expect(editor).to have_received(:system).with(name, file)
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
26
|
context 'when fails to invoke' do
|
31
27
|
|
32
|
-
before {
|
28
|
+
before { allow(editor).to receive(:system).and_return(false) }
|
33
29
|
|
34
30
|
it 'raises an error' do
|
35
|
-
expect {
|
31
|
+
expect { editor.invoke }.to raise_error(TTY::CommandInvocationError)
|
36
32
|
end
|
37
33
|
end
|
38
34
|
end
|
@@ -1,27 +1,29 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::System::Editor, '#open' do
|
6
6
|
let(:file) { "hello.rb" }
|
7
7
|
|
8
|
-
subject { described_class }
|
8
|
+
subject(:editor) { described_class }
|
9
9
|
|
10
10
|
context 'when no editor' do
|
11
|
-
before {
|
11
|
+
before { allow(editor).to receive(:command).and_return(nil) }
|
12
12
|
|
13
13
|
it 'raises error' do
|
14
|
-
expect {
|
14
|
+
expect {
|
15
|
+
editor.open(file)
|
16
|
+
}.to raise_error(TTY::CommandInvocationError)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
context 'when editor' do
|
19
|
-
before {
|
21
|
+
before { allow(editor).to receive(:command).and_return('vim') }
|
20
22
|
|
21
23
|
it 'invokes editor' do
|
22
24
|
invocable = double(:invocable, :invoke => nil)
|
23
|
-
subject.
|
24
|
-
|
25
|
+
expect(subject).to receive(:new).with(file).and_return(invocable)
|
26
|
+
editor.open(file)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -1,27 +1,46 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::System, '#platform' do
|
6
|
-
subject { described_class }
|
6
|
+
subject(:system) { described_class }
|
7
7
|
|
8
|
-
it {
|
8
|
+
it { is_expected.to respond_to(:windows?) }
|
9
9
|
|
10
|
-
it {
|
10
|
+
it { is_expected.to respond_to(:unix?) }
|
11
11
|
|
12
|
-
it {
|
12
|
+
it { is_expected.to respond_to(:which) }
|
13
13
|
|
14
|
-
it {
|
14
|
+
it { is_expected.to respond_to(:exists?) }
|
15
15
|
|
16
|
-
it {
|
16
|
+
it { is_expected.to respond_to(:editor) }
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
context 'windows?' do
|
19
|
+
it 'is on windows' do
|
20
|
+
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('windows')
|
21
|
+
expect(system.windows?).to eq(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'is on windows ignoring case' do
|
25
|
+
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('Windows')
|
26
|
+
expect(system.windows?).to eq(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'is not on windows' do
|
30
|
+
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('unknown')
|
31
|
+
expect(system.windows?).to eq(false)
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
context 'unix?' do
|
36
|
+
it 'checks if unix' do
|
37
|
+
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('darwin')
|
38
|
+
expect(system.unix?).to eq(true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'checks if unix' do
|
42
|
+
allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('unknown')
|
43
|
+
expect(system.unix?).to eq(false)
|
44
|
+
end
|
26
45
|
end
|
27
46
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -12,17 +12,17 @@ describe TTY::System::Which, '#which' do
|
|
12
12
|
let(:command) { 'ruby' }
|
13
13
|
|
14
14
|
before {
|
15
|
-
ENV.
|
16
|
-
ENV.
|
15
|
+
allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil)
|
16
|
+
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
17
17
|
}
|
18
18
|
|
19
19
|
it 'finds command' do
|
20
|
-
File.
|
20
|
+
allow(File).to receive(:executable?) { true }
|
21
21
|
expect(subject.which).to eql "/usr/local/bin/ruby"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "doesn't find command" do
|
25
|
-
File.
|
25
|
+
allow(File).to receive(:executable?) { false }
|
26
26
|
expect(subject.which).to be_nil
|
27
27
|
end
|
28
28
|
end
|
@@ -31,17 +31,17 @@ describe TTY::System::Which, '#which' do
|
|
31
31
|
let(:command) { 'ruby' }
|
32
32
|
|
33
33
|
before {
|
34
|
-
ENV.
|
35
|
-
ENV.
|
34
|
+
allow(ENV).to receive(:[]).with('PATHEXT').and_return(extension)
|
35
|
+
allow(ENV).to receive(:[]).with('PATH').and_return(path)
|
36
36
|
}
|
37
37
|
|
38
38
|
it 'finds command' do
|
39
|
-
File.
|
39
|
+
allow(File).to receive(:executable?) { true }
|
40
40
|
expect(subject.which).to eql "/usr/local/bin/ruby.bat"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "doesn't find command" do
|
44
|
-
File.
|
44
|
+
allow(File).to receive(:executable?) { false }
|
45
45
|
expect(subject.which).to be_nil
|
46
46
|
end
|
47
47
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,10 +6,10 @@ describe TTY::System, '#which' do
|
|
6
6
|
let(:command) { 'ruby' }
|
7
7
|
let(:which) { double(:which, :which => command) }
|
8
8
|
|
9
|
-
subject { described_class }
|
9
|
+
subject(:system) { described_class }
|
10
10
|
|
11
11
|
it 'seeks system command' do
|
12
|
-
TTY::System::Which.
|
13
|
-
expect(
|
12
|
+
allow(TTY::System::Which).to receive(:new).with(command).and_return(which)
|
13
|
+
expect(system.which(command)).to eql(command)
|
14
14
|
end
|
15
15
|
end
|
@@ -1,49 +1,52 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Table, 'access' do
|
6
6
|
let(:header) { [:head1, :head2] }
|
7
|
-
let(:rows)
|
8
|
-
subject { TTY::Table.new :rows => rows, :header => header }
|
7
|
+
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
9
8
|
|
10
|
-
|
9
|
+
subject(:table) { TTY::Table.new rows: rows, header: header }
|
10
|
+
|
11
|
+
it { is_expected.to respond_to(:element) }
|
11
12
|
|
12
13
|
it { should respond_to(:component) }
|
13
14
|
|
14
15
|
it { should respond_to(:at) }
|
15
16
|
|
16
|
-
|
17
|
+
context 'when array like access' do
|
18
|
+
it { expect(table[0,0]).to eq('a1') }
|
17
19
|
|
18
|
-
|
20
|
+
it { expect(table[0]).to eq(rows[0]) }
|
19
21
|
|
20
|
-
|
22
|
+
it { expect(table[5]).to eq(nil) }
|
21
23
|
|
22
|
-
|
24
|
+
it { expect(table[-1]).to eq(rows[-1]) }
|
23
25
|
|
24
|
-
|
26
|
+
it { expect(table[5,5]).to eq(nil) }
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
it 'raises error for negative indices' do
|
29
|
+
expect { table[-5,-5] }.to raise_error(IndexError)
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
context '#row' do
|
31
34
|
it 'returns nil for wrong index' do
|
32
|
-
|
35
|
+
expect(table.row(11)).to be_nil
|
33
36
|
end
|
34
37
|
|
35
38
|
it 'gets row at index' do
|
36
|
-
|
39
|
+
expect(table.row(1)).to eq(rows[1])
|
37
40
|
end
|
38
41
|
|
39
42
|
it 'yields self for wrong index' do
|
40
43
|
block = lambda { |el| [] << el }
|
41
|
-
|
44
|
+
expect(table.row(11, &block)).to eq(table)
|
42
45
|
end
|
43
46
|
|
44
47
|
it 'yields row at index' do
|
45
48
|
yields = []
|
46
|
-
expect {
|
49
|
+
expect { table.row(1).each { |el| yields << el } }.to change { yields }.
|
47
50
|
from( [] ).
|
48
51
|
to( rows[1] )
|
49
52
|
end
|
@@ -51,31 +54,31 @@ describe TTY::Table, 'access' do
|
|
51
54
|
|
52
55
|
context '#column' do
|
53
56
|
it "gets based on header name" do
|
54
|
-
|
57
|
+
expect(table.column(:head1)).to eq(['a1', 'b1'])
|
55
58
|
end
|
56
59
|
|
57
60
|
it "yields based on header name" do
|
58
61
|
yielded = []
|
59
|
-
|
62
|
+
table.column(:head1) { |el| yielded << el }
|
60
63
|
expect(yielded).to eql(['a1', 'b1'])
|
61
64
|
end
|
62
65
|
|
63
66
|
it 'returns nil for wrong index' do
|
64
|
-
|
67
|
+
expect(table.column(11)).to be_nil
|
65
68
|
end
|
66
69
|
|
67
70
|
it 'gets column at index' do
|
68
|
-
|
71
|
+
expect(table.column(0)).to eq(['a1', 'b1'])
|
69
72
|
end
|
70
73
|
|
71
74
|
it 'yields self for wrong index' do
|
72
75
|
block = lambda { |el| [] << el }
|
73
|
-
|
76
|
+
expect(table.column(11, &block)).to eq(table)
|
74
77
|
end
|
75
78
|
|
76
79
|
it 'yields column at index' do
|
77
80
|
yields = []
|
78
|
-
expect {
|
81
|
+
expect { table.column(1).each { |el| yields << el } }.to change { yields }.
|
79
82
|
from( [] ).
|
80
83
|
to( ['a2', 'b2'])
|
81
84
|
end
|