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
data/lib/tty/text/distance.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Text
|
5
|
-
|
6
5
|
# A class responsible for string comparison
|
7
6
|
class Distance
|
8
7
|
include Unicode
|
@@ -22,7 +21,7 @@ module TTY
|
|
22
21
|
# @api private
|
23
22
|
def initialize(first, second, *args)
|
24
23
|
options = Utils.extract_options!(args)
|
25
|
-
@first
|
24
|
+
@first = first.to_s
|
26
25
|
@second = second.to_s
|
27
26
|
# TODO: add option to ignore case
|
28
27
|
end
|
@@ -67,7 +66,6 @@ module TTY
|
|
67
66
|
end
|
68
67
|
distances[rows][cols]
|
69
68
|
end
|
70
|
-
|
71
69
|
end # Distance
|
72
70
|
end # Text
|
73
71
|
end # TTY
|
data/lib/tty/text/truncation.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Text
|
5
|
-
|
6
5
|
# A class responsible for text truncation operations
|
7
6
|
class Truncation
|
8
7
|
include Unicode
|
@@ -92,7 +91,6 @@ module TTY
|
|
92
91
|
length - trailing_size
|
93
92
|
end
|
94
93
|
end
|
95
|
-
|
96
94
|
end # Truncation
|
97
95
|
end # Text
|
98
96
|
end # TTY
|
data/lib/tty/text/wrapping.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Text
|
5
|
-
|
6
5
|
# A class responsible for text wrapping operations
|
7
6
|
class Wrapping
|
8
7
|
include Unicode
|
@@ -111,7 +110,6 @@ module TTY
|
|
111
110
|
part.insert(0, padding_left).insert(-1, padding_right)
|
112
111
|
end
|
113
112
|
end
|
114
|
-
|
115
113
|
end # Wrapping
|
116
114
|
end # Text
|
117
115
|
end # TTY
|
data/lib/tty/vector.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
|
-
|
5
4
|
# This class represents a mathematical vector.
|
6
5
|
class Vector
|
7
6
|
include Enumerable, Equatable, Conversion
|
@@ -27,7 +26,7 @@ module TTY
|
|
27
26
|
# @return [undefined]
|
28
27
|
#
|
29
28
|
# @api public
|
30
|
-
def initialize(array=[])
|
29
|
+
def initialize(array = [])
|
31
30
|
@elements = convert_to_array(array)
|
32
31
|
end
|
33
32
|
|
@@ -58,7 +57,7 @@ module TTY
|
|
58
57
|
#
|
59
58
|
# @api public
|
60
59
|
def []=(indx, value)
|
61
|
-
|
60
|
+
elements[indx] = value
|
62
61
|
end
|
63
62
|
alias set_element []=
|
64
63
|
|
@@ -113,6 +112,5 @@ module TTY
|
|
113
112
|
def to_a
|
114
113
|
to_ary.dup
|
115
114
|
end
|
116
|
-
|
117
115
|
end # Vector
|
118
116
|
end # TTY
|
data/lib/tty/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
3
|
if ENV['TRAVIS'] || ENV['COVERAGE']
|
6
4
|
require 'simplecov'
|
7
5
|
require 'coveralls'
|
@@ -16,14 +14,13 @@ if ENV['TRAVIS'] || ENV['COVERAGE']
|
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
21
|
-
|
22
|
-
require 'rspec'
|
23
17
|
require 'tty'
|
24
18
|
|
25
19
|
RSpec.configure do |config|
|
26
|
-
config.
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run :focus
|
22
|
+
config.order = 'random'
|
23
|
+
config.raise_errors_for_deprecations!
|
27
24
|
end
|
28
25
|
|
29
26
|
class String
|
@@ -31,7 +28,3 @@ class String
|
|
31
28
|
gsub(/^[ \t]*/, '').chomp
|
32
29
|
end
|
33
30
|
end
|
34
|
-
|
35
|
-
unless defined?(Gem::Specification)
|
36
|
-
Gem::Specification = Struct.new(:name, :version)
|
37
|
-
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe TTY::Coercer::Boolean, '#coerce' do
|
6
|
+
|
4
7
|
subject { described_class.coerce(value) }
|
5
8
|
|
6
9
|
context "with empty" do
|
@@ -12,97 +15,97 @@ describe TTY::Coercer::Boolean, '#coerce' do
|
|
12
15
|
context "with true" do
|
13
16
|
let(:value) { true }
|
14
17
|
|
15
|
-
it {
|
18
|
+
it { is_expected.to eq(true) }
|
16
19
|
end
|
17
20
|
|
18
21
|
context "with 'true'" do
|
19
22
|
let(:value) { 'true' }
|
20
23
|
|
21
|
-
it {
|
24
|
+
it { is_expected.to eq(true) }
|
22
25
|
end
|
23
26
|
|
24
27
|
context "with TRUE" do
|
25
28
|
let(:value) { TRUE }
|
26
29
|
|
27
|
-
it {
|
30
|
+
it { is_expected.to eq(true) }
|
28
31
|
end
|
29
32
|
|
30
33
|
context "with 'TRUE'" do
|
31
34
|
let(:value) { 'TRUE' }
|
32
35
|
|
33
|
-
it {
|
36
|
+
it { is_expected.to eq(true) }
|
34
37
|
end
|
35
38
|
|
36
39
|
context "with 't'" do
|
37
40
|
let(:value) { 't' }
|
38
41
|
|
39
|
-
it {
|
42
|
+
it { is_expected.to eq(true) }
|
40
43
|
end
|
41
44
|
|
42
45
|
context "with 'T'" do
|
43
46
|
let(:value) { 'T' }
|
44
47
|
|
45
|
-
it {
|
48
|
+
it { is_expected.to eq(true) }
|
46
49
|
end
|
47
50
|
|
48
51
|
context "with 1" do
|
49
52
|
let(:value) { 1 }
|
50
53
|
|
51
|
-
it {
|
54
|
+
it { is_expected.to eq(true) }
|
52
55
|
end
|
53
56
|
|
54
57
|
context "with '1'" do
|
55
58
|
let(:value) { '1' }
|
56
59
|
|
57
|
-
it {
|
60
|
+
it { is_expected.to eq(true) }
|
58
61
|
end
|
59
62
|
|
60
63
|
context "with false" do
|
61
64
|
let(:value) { false }
|
62
65
|
|
63
|
-
it {
|
66
|
+
it { is_expected.to eq(false) }
|
64
67
|
end
|
65
68
|
|
66
69
|
context "with 'false'" do
|
67
70
|
let(:value) { 'false' }
|
68
71
|
|
69
|
-
it {
|
72
|
+
it { is_expected.to eq(false) }
|
70
73
|
end
|
71
74
|
|
72
75
|
context "with FALSE" do
|
73
76
|
let(:value) { FALSE }
|
74
77
|
|
75
|
-
it {
|
78
|
+
it { is_expected.to eq(false) }
|
76
79
|
end
|
77
80
|
|
78
81
|
context "with 'FALSE'" do
|
79
82
|
let(:value) { 'FALSE' }
|
80
83
|
|
81
|
-
it {
|
84
|
+
it { is_expected.to eq(false) }
|
82
85
|
end
|
83
86
|
|
84
87
|
context "with 'f'" do
|
85
88
|
let(:value) { 'f' }
|
86
89
|
|
87
|
-
it {
|
90
|
+
it { is_expected.to eq(false) }
|
88
91
|
end
|
89
92
|
|
90
93
|
context "with 'F'" do
|
91
94
|
let(:value) { 'F' }
|
92
95
|
|
93
|
-
it {
|
96
|
+
it { is_expected.to eq(false) }
|
94
97
|
end
|
95
98
|
|
96
99
|
context "with 0" do
|
97
100
|
let(:value) { 0 }
|
98
101
|
|
99
|
-
it {
|
102
|
+
it { is_expected.to eq(false) }
|
100
103
|
end
|
101
104
|
|
102
105
|
context "with '0'" do
|
103
106
|
let(:value) { '0' }
|
104
107
|
|
105
|
-
it {
|
108
|
+
it { is_expected.to eq(false) }
|
106
109
|
end
|
107
110
|
|
108
111
|
context "with FOO" do
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe TTY::Coercer::Float, '#coerce' do
|
4
6
|
let(:strict) { true }
|
7
|
+
|
5
8
|
subject { described_class.coerce(value, strict) }
|
6
9
|
|
7
10
|
context 'with empty' do
|
@@ -13,7 +16,7 @@ describe TTY::Coercer::Float, '#coerce' do
|
|
13
16
|
context 'with 1 as string' do
|
14
17
|
let(:value) { '1' }
|
15
18
|
|
16
|
-
it {
|
19
|
+
it { is_expected.to eql 1.0 }
|
17
20
|
end
|
18
21
|
|
19
22
|
context 'with float' do
|
@@ -23,10 +26,9 @@ describe TTY::Coercer::Float, '#coerce' do
|
|
23
26
|
end
|
24
27
|
|
25
28
|
context 'with float not strict' do
|
26
|
-
let(:value)
|
29
|
+
let(:value) { '1.2abc'}
|
27
30
|
let(:strict) { false }
|
28
31
|
|
29
|
-
it {
|
32
|
+
it { is_expected.to eql 1.2 }
|
30
33
|
end
|
31
|
-
|
32
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe TTY::Coercer::Integer, '#coerce' do
|
@@ -13,7 +15,7 @@ describe TTY::Coercer::Integer, '#coerce' do
|
|
13
15
|
context 'with 1 as string' do
|
14
16
|
let(:value) { '1' }
|
15
17
|
|
16
|
-
it {
|
18
|
+
it { is_expected.to eql 1 }
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'with float' do
|
@@ -26,14 +28,13 @@ describe TTY::Coercer::Integer, '#coerce' do
|
|
26
28
|
let(:value) { 1.2 }
|
27
29
|
let(:strict) { false }
|
28
30
|
|
29
|
-
it {
|
31
|
+
it { is_expected.to eql 1 }
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'with letters not strict' do
|
33
35
|
let(:value) { '1abc' }
|
34
36
|
let(:strict) { false }
|
35
37
|
|
36
|
-
it {
|
38
|
+
it { is_expected.to eql 1 }
|
37
39
|
end
|
38
|
-
|
39
40
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe TTY::Coercer::Range, '#coerce' do
|
@@ -13,61 +15,60 @@ describe TTY::Coercer::Range, '#coerce' do
|
|
13
15
|
context 'with 1' do
|
14
16
|
let(:value) { '1' }
|
15
17
|
|
16
|
-
it {
|
18
|
+
it { is_expected.to eq(1..1) }
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'with 1..10' do
|
20
22
|
let(:value) { '1..10' }
|
21
23
|
|
22
|
-
it {
|
24
|
+
it { is_expected.to eq(1..10) }
|
23
25
|
end
|
24
26
|
|
25
27
|
context 'with 1-10' do
|
26
28
|
let(:value) { '1-10' }
|
27
29
|
|
28
|
-
it {
|
30
|
+
it { is_expected.to eq(1..10) }
|
29
31
|
end
|
30
32
|
|
31
33
|
context 'with 1,10' do
|
32
34
|
let(:value) { '1,10' }
|
33
35
|
|
34
|
-
it {
|
36
|
+
it { is_expected.to eq(1..10) }
|
35
37
|
end
|
36
38
|
|
37
39
|
context 'with 1...10' do
|
38
40
|
let(:value) { '1...10'}
|
39
41
|
|
40
|
-
it {
|
42
|
+
it { is_expected.to eq(1...10) }
|
41
43
|
end
|
42
44
|
|
43
45
|
context 'with -1..10' do
|
44
46
|
let(:value) { '-1..10' }
|
45
47
|
|
46
|
-
it {
|
48
|
+
it { is_expected.to eq(-1..10) }
|
47
49
|
end
|
48
50
|
|
49
51
|
context 'with 1..-10' do
|
50
52
|
let(:value) { '1..-10' }
|
51
53
|
|
52
|
-
it {
|
54
|
+
it { is_expected.to eq(1..-10) }
|
53
55
|
end
|
54
56
|
|
55
57
|
context 'with a..z' do
|
56
58
|
let(:value) { 'a..z' }
|
57
59
|
|
58
|
-
it {
|
60
|
+
it { is_expected.to eq('a'..'z')}
|
59
61
|
end
|
60
62
|
|
61
63
|
context 'with a-z' do
|
62
64
|
let(:value) { 'a-z' }
|
63
65
|
|
64
|
-
it {
|
66
|
+
it { is_expected.to eq('a'..'z')}
|
65
67
|
end
|
66
68
|
|
67
69
|
context 'with A..Z' do
|
68
70
|
let(:value) { 'A..Z' }
|
69
71
|
|
70
|
-
it {
|
72
|
+
it { is_expected.to eq('A'..'Z')}
|
71
73
|
end
|
72
|
-
|
73
74
|
end # coerce
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'timecop'
|
5
|
+
|
6
|
+
describe TTY::Logger, '#log' do
|
7
|
+
let(:output) { StringIO.new }
|
8
|
+
let(:message) { 'text' }
|
9
|
+
let(:namespace) { 'tty::'}
|
10
|
+
let(:options) { {output: output, namespace: namespace} }
|
11
|
+
let(:object) { described_class.new(options) }
|
12
|
+
|
13
|
+
subject { object.log(message) }
|
14
|
+
|
15
|
+
before { Timecop.freeze }
|
16
|
+
|
17
|
+
after { Timecop.return }
|
18
|
+
|
19
|
+
it 'logs message to output' do
|
20
|
+
subject
|
21
|
+
expect(output.string).to eq("#{object.timestamp} - #{message}")
|
22
|
+
end
|
23
|
+
end
|
data/spec/tty/logger/new_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,31 +6,31 @@ describe TTY::Logger, '#new' do
|
|
6
6
|
let(:object) { described_class }
|
7
7
|
let(:output) { StringIO.new }
|
8
8
|
|
9
|
-
subject { object.new
|
9
|
+
subject(:logger) { object.new(options) }
|
10
10
|
|
11
11
|
context 'when default' do
|
12
|
-
let(:options) { {:
|
12
|
+
let(:options) { {namespace: ''} }
|
13
13
|
|
14
|
-
|
14
|
+
it { expect(logger.level).to eq(object::ALL) }
|
15
15
|
|
16
|
-
|
16
|
+
it { expect(logger.output).to eq($stderr) }
|
17
17
|
|
18
|
-
|
18
|
+
it { expect(logger.timestamp_format).to eq('%Y-%m-%d %T') }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'when custom' do
|
22
22
|
let(:options) { {
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
23
|
+
namespace: 'tty::color',
|
24
|
+
level: 2,
|
25
|
+
output: output,
|
26
|
+
timestamp_format: "%dd" } }
|
27
27
|
|
28
|
-
|
28
|
+
it { expect(logger.namespace).to eq('tty::color') }
|
29
29
|
|
30
|
-
|
30
|
+
it { expect(logger.level).to eq(2) }
|
31
31
|
|
32
|
-
|
32
|
+
it { expect(logger.output).to eq(output) }
|
33
33
|
|
34
|
-
|
34
|
+
it { expect(logger.timestamp_format).to eq('%dd') }
|
35
35
|
end
|
36
36
|
end
|