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,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Shell::Question, '#validate' do
|
6
6
|
let(:input) { StringIO.new }
|
7
7
|
let(:output) { StringIO.new }
|
8
|
-
let(:shell)
|
8
|
+
let(:shell) { TTY::Shell.new(input, output) }
|
9
9
|
|
10
10
|
it 'fails to validate input' do
|
11
11
|
input << 'piotrmurach'
|
@@ -18,13 +18,13 @@ describe TTY::Shell::Question, '#validate' do
|
|
18
18
|
input << 'piotr.murach'
|
19
19
|
input.rewind
|
20
20
|
q = shell.ask("What is your username?").validate(/^[^\.]+\.[^\.]+/)
|
21
|
-
expect(q.read_string).to
|
21
|
+
expect(q.read_string).to eq('piotr.murach')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'validates input in block' do
|
25
25
|
input << 'piotr.murach'
|
26
26
|
input.rewind
|
27
27
|
q = shell.ask("What is your username?").validate { |arg| arg =~ /^[^\.]+\.[^\.]+/ }
|
28
|
-
expect(q.read_string).to
|
28
|
+
expect(q.read_string).to eq('piotr.murach')
|
29
29
|
end
|
30
30
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -13,7 +13,7 @@ describe TTY::Shell::Question::Validation, '#coerce' do
|
|
13
13
|
context 'when proc' do
|
14
14
|
let(:validation) { lambda { "^[^\.]+\.[^\.]+" } }
|
15
15
|
|
16
|
-
it {
|
16
|
+
it { is_expected.to be_kind_of Proc }
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'when unkown type' do
|
@@ -21,5 +21,4 @@ describe TTY::Shell::Question::Validation, '#coerce' do
|
|
21
21
|
|
22
22
|
it { expect { subject }.to raise_error(TTY::ValidationCoercion) }
|
23
23
|
end
|
24
|
-
|
25
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -11,13 +11,13 @@ describe TTY::Shell::Question::Validation, '#valid_value?' do
|
|
11
11
|
context '' do
|
12
12
|
let(:value) { nil }
|
13
13
|
|
14
|
-
it {
|
14
|
+
it { is_expected.to eq(false) }
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when the value matches validation' do
|
18
18
|
let(:value) { 'piotr.murach' }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eq(true) }
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'when the value is not matching validation' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -8,15 +8,18 @@ describe TTY::Shell::Reader, '#getc' do
|
|
8
8
|
let(:input) { StringIO.new }
|
9
9
|
let(:output) { StringIO.new }
|
10
10
|
let(:shell) { TTY::Shell.new(input, output) }
|
11
|
-
let(:mask) { '*'}
|
12
11
|
|
13
12
|
subject(:reader) { instance.getc mask }
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
context 'with mask' do
|
15
|
+
let(:mask) { '*'}
|
16
|
+
|
17
|
+
it 'masks characters' do
|
18
|
+
input << "password\n"
|
19
|
+
input.rewind
|
20
|
+
expect(reader).to eql "password"
|
21
|
+
expect(output.string).to eql("********")
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
context "without mask" do
|
@@ -29,12 +32,11 @@ describe TTY::Shell::Reader, '#getc' do
|
|
29
32
|
expect(output.string).to eql("password")
|
30
33
|
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
expect(output.string).to eql('')
|
35
|
+
it 'deletes characters when backspace pressed' do
|
36
|
+
input << "\b\b"
|
37
|
+
input.rewind
|
38
|
+
expect(reader).to eql ''
|
39
|
+
expect(output.string).to eql('')
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -11,14 +11,13 @@ describe TTY::Shell::Question, '#read_multiple' do
|
|
11
11
|
input << "First line\nSecond line\nThird line"
|
12
12
|
input.rewind
|
13
13
|
q = shell.ask("Provide description?")
|
14
|
-
expect(q.read_multiple).to
|
14
|
+
expect(q.read_multiple).to eq("First line\nSecond line\nThird line")
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'skips empty lines' do
|
18
18
|
input << "First line\n\nSecond line"
|
19
19
|
input.rewind
|
20
20
|
q = shell.ask("Provide description?")
|
21
|
-
expect(q.read_multiple).to
|
21
|
+
expect(q.read_multiple).to eq("First line\nSecond line")
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Shell::Question, '#read_range' do
|
6
6
|
let(:input) { StringIO.new }
|
7
7
|
let(:output) { StringIO.new }
|
8
|
-
let(:shell)
|
8
|
+
let(:shell) { TTY::Shell.new(input, output) }
|
9
9
|
|
10
10
|
subject {
|
11
11
|
input << value
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -14,7 +14,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
14
14
|
q = shell.ask("What is your password: ").echo(true)
|
15
15
|
expect(q.read).to eql("password")
|
16
16
|
expect(output.string).to eql('What is your password: ')
|
17
|
-
expect(q.mask?).to
|
17
|
+
expect(q.mask?).to eq(false)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'asks with echo off' do
|
@@ -23,7 +23,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
23
23
|
q = shell.ask("What is your password: ").echo(false)
|
24
24
|
expect(q.read).to eql("password")
|
25
25
|
expect(output.string).to eql('What is your password: ')
|
26
|
-
expect(q.mask?).to
|
26
|
+
expect(q.mask?).to eq(false)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -34,7 +34,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
34
34
|
q = shell.ask("What is your password: ").mask('*')
|
35
35
|
expect(q.read).to eql("password")
|
36
36
|
expect(output.string).to eql('What is your password: ********')
|
37
|
-
expect(q.mask?).to
|
37
|
+
expect(q.mask?).to eq(true)
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'ignores mask if echo is off' do
|
@@ -43,7 +43,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
43
43
|
q = shell.ask("What is your password: ").echo(false).mask('*')
|
44
44
|
expect(q.read).to eql("password")
|
45
45
|
expect(output.string).to eql('What is your password: ')
|
46
|
-
expect(q.mask?).to
|
46
|
+
expect(q.mask?).to eq(true)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -52,7 +52,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
52
52
|
input << "password"
|
53
53
|
input.rewind
|
54
54
|
q = shell.ask("What is your password: ", :echo => false, :mask => '*')
|
55
|
-
expect(q.read_password).to
|
55
|
+
expect(q.read_password).to eq("password")
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'asks with block' do
|
@@ -62,7 +62,7 @@ describe TTY::Shell::Question, '#read_password' do
|
|
62
62
|
echo false
|
63
63
|
mask '*'
|
64
64
|
end
|
65
|
-
expect(q.read_password).to
|
65
|
+
expect(q.read_password).to eq("password")
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Shell::Question, '#initialize' do
|
6
6
|
let(:input) { StringIO.new }
|
7
7
|
let(:output) { StringIO.new }
|
8
|
-
let(:shell)
|
8
|
+
let(:shell) { TTY::Shell.new(input, output) }
|
9
9
|
|
10
10
|
it 'reads string' do
|
11
11
|
name = "Piotr"
|
data/spec/tty/shell/say_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,7 +9,7 @@ describe TTY::Shell::Statement, '#new' do
|
|
9
9
|
|
10
10
|
subject(:statement) { described_class.new }
|
11
11
|
|
12
|
-
|
12
|
+
it { expect(statement.newline).to eq(true) }
|
13
13
|
|
14
|
-
|
14
|
+
it { expect(statement.color).to be_nil }
|
15
15
|
end
|
data/spec/tty/shell/warn_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -24,5 +24,4 @@ describe TTY::Shell, '#warn' do
|
|
24
24
|
shell.warn "Careful young apprentice!", :newline => false
|
25
25
|
expect(output.string).to eql "\e[33mCareful young apprentice!\e[0m"
|
26
26
|
end
|
27
|
-
|
28
27
|
end # warn
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -10,32 +10,32 @@ describe TTY::Coercion do
|
|
10
10
|
|
11
11
|
subject { object.coerce_to( *coercible ) }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to eq(value) }
|
14
14
|
|
15
15
|
context 'coerces into integer' do
|
16
|
-
let(:value)
|
16
|
+
let(:value) { '123' }
|
17
17
|
let(:coercible) { [ value, Integer, :to_i] }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to be_kind_of(Integer) }
|
20
20
|
|
21
|
-
it {
|
21
|
+
it { is_expected.to eq(value.to_i) }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'coerces into symbol' do
|
25
|
-
let(:value)
|
25
|
+
let(:value) { 'argument' }
|
26
26
|
let(:coercible) { [value, Symbol, :to_sym]}
|
27
27
|
|
28
|
-
it {
|
28
|
+
it { is_expected.to be_kind_of(Symbol) }
|
29
29
|
|
30
|
-
it {
|
30
|
+
it { is_expected.to eq(value.to_sym) }
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'coerces into string' do
|
34
34
|
let(:value) { true }
|
35
35
|
let(:coercible) { [value, String, :to_s] }
|
36
36
|
|
37
|
-
it {
|
37
|
+
it { is_expected.to be_kind_of(String) }
|
38
38
|
|
39
|
-
it {
|
39
|
+
it { is_expected.to eq(value.to_s) }
|
40
40
|
end
|
41
41
|
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Conversion do
|
6
|
-
let(:
|
7
|
-
let(:object)
|
6
|
+
let(:new_class) { Class.new { include TTY::Conversion } }
|
7
|
+
let(:object) { new_class.new }
|
8
8
|
let(:enumerable) { [] }
|
9
9
|
|
10
10
|
subject { object.convert_to_array(enumerable) }
|
11
11
|
|
12
12
|
context 'Array type' do
|
13
|
-
it {
|
13
|
+
it { is_expected.to eq(enumerable) }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'Hash type' do
|
17
|
-
let(:enumerable) { {:
|
17
|
+
let(:enumerable) { {a: 1, b: 2} }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to include([:a, 1]) }
|
20
20
|
|
21
|
-
it {
|
21
|
+
it { is_expected.to include([:b, 2]) }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'responds to #to_ary' do
|
25
|
-
let(:converted)
|
25
|
+
let(:converted) { [] }
|
26
26
|
let(:enumerable) { double('Enumerable', :to_ary => converted) }
|
27
27
|
|
28
|
-
it {
|
28
|
+
it { is_expected.to eq(converted) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'does not respond to #to_ary' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require File.expand_path('../fixtures/classes', __FILE__)
|
@@ -17,10 +17,12 @@ describe TTY::Delegatable do
|
|
17
17
|
to(true)
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'delegates #output to
|
20
|
+
it 'delegates #output to target' do
|
21
21
|
subject
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
instance = spy(:target_spec)
|
23
|
+
allow(TargetSpec::Object).to receive(:new).and_return(instance)
|
24
|
+
|
25
|
+
delegatable.output
|
26
|
+
expect(instance).to have_received(:output)
|
25
27
|
end
|
26
28
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -11,25 +11,25 @@ describe TTY::Equatable do
|
|
11
11
|
subject { klass.new }
|
12
12
|
|
13
13
|
before {
|
14
|
-
klass.
|
14
|
+
allow(klass).to receive(:name).and_return('Value')
|
15
15
|
klass.send :include, described_class
|
16
16
|
}
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to respond_to :compare? }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to be_instance_of klass }
|
21
21
|
|
22
22
|
describe '#eql?' do
|
23
23
|
context 'when objects are similar' do
|
24
24
|
let(:other) { subject.dup }
|
25
25
|
|
26
|
-
it { subject.eql?(other).
|
26
|
+
it { expect(subject.eql?(other)).to eq(true) }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when objects are different' do
|
30
30
|
let(:other) { double('other') }
|
31
31
|
|
32
|
-
it { subject.eql?(other).
|
32
|
+
it { expect(subject.eql?(other)).to eq(false) }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -37,22 +37,22 @@ describe TTY::Equatable do
|
|
37
37
|
context 'when objects are similar' do
|
38
38
|
let(:other) { subject.dup }
|
39
39
|
|
40
|
-
it { (subject == other).
|
40
|
+
it { expect(subject == other).to eq(true) }
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'when objects are different' do
|
44
44
|
let(:other) { double('other') }
|
45
45
|
|
46
|
-
it { (subject == other)}
|
46
|
+
it { expect(subject == other).to eq(false) }
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe '#inspect' do
|
51
|
-
it { subject.inspect.
|
51
|
+
it { expect(subject.inspect).to eql('#<Value>') }
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#hash' do
|
55
|
-
it { subject.hash.
|
55
|
+
it { expect(subject.hash).to eql([klass].hash) }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -71,34 +71,34 @@ describe TTY::Equatable do
|
|
71
71
|
}
|
72
72
|
|
73
73
|
before {
|
74
|
-
klass.
|
74
|
+
allow(klass).to receive(:name).and_return name
|
75
75
|
}
|
76
76
|
|
77
77
|
subject { klass.new(value) }
|
78
78
|
|
79
79
|
it 'dynamically defines #hash method' do
|
80
|
-
klass.method_defined?(:hash).
|
80
|
+
expect(klass.method_defined?(:hash)).to eq(true)
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'dynamically defines #inspect method' do
|
84
|
-
klass.method_defined?(:inspect).
|
84
|
+
expect(klass.method_defined?(:inspect)).to eq(true)
|
85
85
|
end
|
86
86
|
|
87
|
-
it {
|
87
|
+
it { is_expected.to respond_to :compare? }
|
88
88
|
|
89
|
-
it {
|
89
|
+
it { is_expected.to respond_to :eql? }
|
90
90
|
|
91
91
|
describe '#eql?' do
|
92
92
|
context 'when objects are similar' do
|
93
93
|
let(:other) { subject.dup }
|
94
94
|
|
95
|
-
it { subject.eql?(other).
|
95
|
+
it { expect(subject.eql?(other)).to eq(true) }
|
96
96
|
end
|
97
97
|
|
98
98
|
context 'when objects are different' do
|
99
99
|
let(:other) { double('other') }
|
100
100
|
|
101
|
-
it { subject.eql?(other).
|
101
|
+
it { expect(subject.eql?(other)).to eq(false) }
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -106,40 +106,38 @@ describe TTY::Equatable do
|
|
106
106
|
context 'when objects are similar' do
|
107
107
|
let(:other) { subject.dup }
|
108
108
|
|
109
|
-
it { (subject == other).
|
109
|
+
it { expect(subject == other).to eq(true) }
|
110
110
|
end
|
111
111
|
|
112
112
|
context 'when objects are different' do
|
113
113
|
let(:other) { double('other') }
|
114
114
|
|
115
|
-
it { (subject == other).
|
115
|
+
it { expect(subject == other).to eq(false) }
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe '#inspect' do
|
120
|
-
it { subject.inspect.
|
120
|
+
it { expect(subject.inspect).to eql('#<Value value=11>') }
|
121
121
|
end
|
122
122
|
|
123
123
|
describe '#hash' do
|
124
|
-
it { subject.hash.
|
124
|
+
it { expect(subject.hash).to eql( ([klass] + [value]).hash) }
|
125
125
|
end
|
126
126
|
|
127
127
|
context 'equivalence relation' do
|
128
128
|
let(:other) { subject.dup }
|
129
129
|
|
130
130
|
it 'is not equal to nil reference' do
|
131
|
-
|
131
|
+
expect(subject.eql?(nil)).to eq(false)
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'is reflexive' do
|
135
|
-
subject.eql?(subject).
|
135
|
+
expect(subject.eql?(subject)).to eq(true)
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'is symmetric' do
|
139
|
-
(subject.eql?(other)).
|
139
|
+
expect(subject.eql?(other)).to eql( other.eql?(subject) )
|
140
140
|
end
|
141
|
-
|
142
|
-
it 'is transitive'
|
143
141
|
end
|
144
142
|
end
|
145
143
|
|
@@ -159,30 +157,30 @@ describe TTY::Equatable do
|
|
159
157
|
let(:subclass) { ::Class.new(klass) }
|
160
158
|
|
161
159
|
before {
|
162
|
-
klass.
|
160
|
+
allow(klass).to receive(:name).and_return name
|
163
161
|
}
|
164
162
|
|
165
163
|
subject { subclass.new(value) }
|
166
164
|
|
167
|
-
it { subclass.superclass.
|
165
|
+
it { expect(subclass.superclass).to eq(klass) }
|
168
166
|
|
169
|
-
it {
|
167
|
+
it { is_expected.to respond_to :value }
|
170
168
|
|
171
169
|
describe '#inspect' do
|
172
|
-
it { subject.inspect.
|
170
|
+
it { expect(subject.inspect).to eql('#<Value value=11>') }
|
173
171
|
end
|
174
172
|
|
175
173
|
describe '#eql?' do
|
176
174
|
context 'when objects are similar' do
|
177
175
|
let(:other) { subject.dup }
|
178
176
|
|
179
|
-
it { subject.eql?(other).
|
177
|
+
it { expect(subject.eql?(other)).to eq(true) }
|
180
178
|
end
|
181
179
|
|
182
180
|
context 'when objects are different' do
|
183
181
|
let(:other) { double('other') }
|
184
182
|
|
185
|
-
it { subject.eql?(other).
|
183
|
+
it { expect(subject.eql?(other)).to eq(false) }
|
186
184
|
end
|
187
185
|
end
|
188
186
|
|
@@ -190,13 +188,13 @@ describe TTY::Equatable do
|
|
190
188
|
context 'when objects are similar' do
|
191
189
|
let(:other) { subject.dup }
|
192
190
|
|
193
|
-
it { (subject == other).
|
191
|
+
it { expect(subject == other).to eq(true) }
|
194
192
|
end
|
195
193
|
|
196
194
|
context 'when objects are different' do
|
197
195
|
let(:other) { double('other') }
|
198
196
|
|
199
|
-
it { (subject == other)}
|
197
|
+
it { expect(subject == other).to eq(false) }
|
200
198
|
end
|
201
199
|
end
|
202
200
|
end
|