tty-prompt 0.19.0 → 0.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +485 -233
  5. data/lib/tty-prompt.rb +1 -2
  6. data/lib/tty/prompt.rb +159 -147
  7. data/lib/tty/prompt/answers_collector.rb +5 -5
  8. data/lib/tty/prompt/block_paginator.rb +1 -1
  9. data/lib/tty/prompt/choice.rb +31 -13
  10. data/lib/tty/prompt/choices.rb +30 -12
  11. data/lib/tty/prompt/confirm_question.rb +42 -16
  12. data/lib/tty/prompt/const.rb +17 -0
  13. data/lib/tty/prompt/converter_dsl.rb +6 -7
  14. data/lib/tty/prompt/converter_registry.rb +31 -26
  15. data/lib/tty/prompt/converters.rb +139 -32
  16. data/lib/tty/prompt/enum_list.rb +58 -25
  17. data/lib/tty/prompt/errors.rb +31 -0
  18. data/lib/tty/prompt/evaluator.rb +2 -2
  19. data/lib/tty/prompt/expander.rb +27 -15
  20. data/lib/tty/prompt/keypress.rb +5 -3
  21. data/lib/tty/prompt/list.rb +101 -38
  22. data/lib/tty/prompt/mask_question.rb +9 -5
  23. data/lib/tty/prompt/multi_list.rb +108 -29
  24. data/lib/tty/prompt/multiline.rb +9 -7
  25. data/lib/tty/prompt/paginator.rb +1 -1
  26. data/lib/tty/prompt/question.rb +67 -36
  27. data/lib/tty/prompt/question/checks.rb +20 -2
  28. data/lib/tty/prompt/question/modifier.rb +4 -2
  29. data/lib/tty/prompt/question/validation.rb +3 -3
  30. data/lib/tty/prompt/selected_choices.rb +77 -0
  31. data/lib/tty/prompt/slider.rb +110 -23
  32. data/lib/tty/prompt/statement.rb +3 -3
  33. data/lib/tty/prompt/suggestion.rb +7 -6
  34. data/lib/tty/prompt/symbols.rb +58 -58
  35. data/lib/tty/prompt/test.rb +36 -0
  36. data/lib/tty/prompt/utils.rb +1 -3
  37. data/lib/tty/prompt/version.rb +1 -1
  38. metadata +27 -196
  39. data/Rakefile +0 -8
  40. data/examples/ask.rb +0 -7
  41. data/examples/ask_blank.rb +0 -9
  42. data/examples/ask_valid.rb +0 -12
  43. data/examples/collect.rb +0 -21
  44. data/examples/echo.rb +0 -11
  45. data/examples/enum_select.rb +0 -7
  46. data/examples/enum_select_disabled.rb +0 -16
  47. data/examples/enum_select_paged.rb +0 -9
  48. data/examples/enum_select_wrapped.rb +0 -15
  49. data/examples/expand.rb +0 -29
  50. data/examples/expand_auto.rb +0 -29
  51. data/examples/in.rb +0 -9
  52. data/examples/inputs.rb +0 -10
  53. data/examples/key_events.rb +0 -15
  54. data/examples/keypress.rb +0 -9
  55. data/examples/mask.rb +0 -13
  56. data/examples/multi_select.rb +0 -8
  57. data/examples/multi_select_disabled.rb +0 -17
  58. data/examples/multi_select_disabled_paged.rb +0 -22
  59. data/examples/multi_select_paged.rb +0 -9
  60. data/examples/multi_select_wrapped.rb +0 -15
  61. data/examples/multiline.rb +0 -9
  62. data/examples/pause.rb +0 -9
  63. data/examples/select.rb +0 -24
  64. data/examples/select_disabled.rb +0 -18
  65. data/examples/select_disabled_paged.rb +0 -22
  66. data/examples/select_enum.rb +0 -8
  67. data/examples/select_filtered.rb +0 -11
  68. data/examples/select_paginated.rb +0 -11
  69. data/examples/select_wrapped.rb +0 -15
  70. data/examples/slider.rb +0 -6
  71. data/examples/validation.rb +0 -9
  72. data/examples/yes_no.rb +0 -7
  73. data/lib/tty/prompt/messages.rb +0 -49
  74. data/lib/tty/test_prompt.rb +0 -20
  75. data/spec/spec_helper.rb +0 -61
  76. data/spec/unit/ask_spec.rb +0 -173
  77. data/spec/unit/block_paginator_spec.rb +0 -84
  78. data/spec/unit/choice/eql_spec.rb +0 -22
  79. data/spec/unit/choice/from_spec.rb +0 -112
  80. data/spec/unit/choices/add_spec.rb +0 -12
  81. data/spec/unit/choices/each_spec.rb +0 -13
  82. data/spec/unit/choices/find_by_spec.rb +0 -10
  83. data/spec/unit/choices/new_spec.rb +0 -10
  84. data/spec/unit/choices/pluck_spec.rb +0 -9
  85. data/spec/unit/collect_spec.rb +0 -96
  86. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  87. data/spec/unit/converters/convert_char_spec.rb +0 -11
  88. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  89. data/spec/unit/converters/convert_date_spec.rb +0 -34
  90. data/spec/unit/converters/convert_file_spec.rb +0 -18
  91. data/spec/unit/converters/convert_number_spec.rb +0 -39
  92. data/spec/unit/converters/convert_path_spec.rb +0 -15
  93. data/spec/unit/converters/convert_range_spec.rb +0 -22
  94. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  95. data/spec/unit/converters/convert_string_spec.rb +0 -21
  96. data/spec/unit/converters/on_error_spec.rb +0 -9
  97. data/spec/unit/distance/distance_spec.rb +0 -73
  98. data/spec/unit/enum_select_spec.rb +0 -518
  99. data/spec/unit/error_spec.rb +0 -20
  100. data/spec/unit/evaluator_spec.rb +0 -67
  101. data/spec/unit/expand_spec.rb +0 -290
  102. data/spec/unit/keypress_spec.rb +0 -66
  103. data/spec/unit/mask_spec.rb +0 -140
  104. data/spec/unit/multi_select_spec.rb +0 -741
  105. data/spec/unit/multiline_spec.rb +0 -77
  106. data/spec/unit/new_spec.rb +0 -20
  107. data/spec/unit/ok_spec.rb +0 -10
  108. data/spec/unit/paginator_spec.rb +0 -92
  109. data/spec/unit/question/checks_spec.rb +0 -97
  110. data/spec/unit/question/default_spec.rb +0 -31
  111. data/spec/unit/question/echo_spec.rb +0 -38
  112. data/spec/unit/question/in_spec.rb +0 -115
  113. data/spec/unit/question/initialize_spec.rb +0 -12
  114. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  115. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  116. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  117. data/spec/unit/question/modify_spec.rb +0 -41
  118. data/spec/unit/question/required_spec.rb +0 -92
  119. data/spec/unit/question/validate_spec.rb +0 -115
  120. data/spec/unit/question/validation/call_spec.rb +0 -31
  121. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  122. data/spec/unit/result_spec.rb +0 -40
  123. data/spec/unit/say_spec.rb +0 -67
  124. data/spec/unit/select_spec.rb +0 -942
  125. data/spec/unit/slider_spec.rb +0 -142
  126. data/spec/unit/statement/initialize_spec.rb +0 -15
  127. data/spec/unit/subscribe_spec.rb +0 -22
  128. data/spec/unit/suggest_spec.rb +0 -28
  129. data/spec/unit/timer_spec.rb +0 -29
  130. data/spec/unit/warn_spec.rb +0 -21
  131. data/spec/unit/yes_no_spec.rb +0 -251
  132. data/tasks/console.rake +0 -11
  133. data/tasks/coverage.rake +0 -11
  134. data/tasks/spec.rake +0 -29
  135. data/tty-prompt.gemspec +0 -31
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- warriors = %w(Scorpion Kano Jax Kitana Raiden)
8
-
9
- answer = prompt.select('Choose your destiny?', warriors, filter: true)
10
-
11
- puts answer.inspect
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- alfabet = ('A'..'Z').to_a
8
-
9
- answer = prompt.select('Which letter?', alfabet, per_page: 7, cycle: true, default: 5)
10
-
11
- puts answer.inspect
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-prompt'
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- quotes = [
8
- "There are certain queer times and occasions in this strange mixed affair we call life when a man takes this whole universe for a vast practical joke, though the wit thereof he but dimly discerns, and more than suspects that the joke is at nobody's expense but his own.",
9
- "Talk not to me of blasphemy, man;\n I'd strike the sun if it insulted me.",
10
- "There is a wisdom that is woe; but there is a woe that is madness. And there is a Catskill eagle in some souls that can alike dive down into the blackest gorges, and soar out of them again and become invisible in the sunny spaces. And even if he for ever flies within the gorge, that gorge is in the mountains; so that even in his lowest swoop the mountain eagle is still higher than other birds upon the plain, even though they soar."
11
- ]
12
-
13
- answer = prompt.select('Chose your quote?', quotes)
14
-
15
- puts "Answer: #{answer}"
data/examples/slider.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
- prompt.slider("Volume", max: 100, step: 5, default: 75, format: "|:slider| %d%%")
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- prompt.ask('What is your username?') do |q|
8
- q.validate(/^[^\.]+\.[^\.]+/)
9
- end
data/examples/yes_no.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- prompt.yes?('Do you like Ruby?')
@@ -1,49 +0,0 @@
1
- module TTY
2
- class Prompt
3
- class Messages
4
-
5
- def setup_messages
6
- @messages = {
7
- range?: 'Value %{value} must be within the range %{in}',
8
- valid?: 'Your answer is invalid (must match %{valid})',
9
- required?: 'Value must be provided'
10
- }
11
- end
12
-
13
- def initialize
14
- setup_messages
15
- end
16
-
17
- # Stores all the error messages displayed to user
18
- # The currently supported messages are:
19
- # * :range?
20
- # * :required?
21
- # * :valid?
22
- attr_reader :messages
23
-
24
- def get(key)
25
-
26
- end
27
-
28
- # Retrieve message based on the key
29
- #
30
- # @param [Symbol] name
31
- # the name of message key
32
- #
33
- # @param [Hash] tokens
34
- # the tokens to evaluate
35
- #
36
- # @return [Array[String]]
37
- #
38
- # @api private
39
- def message_for(name, tokens = nil)
40
- template = @messages[name]
41
- if !template.match(/\%\{/).nil?
42
- [template % tokens]
43
- else
44
- [template]
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'prompt'
4
-
5
- module TTY
6
- # Used for initializing test cases
7
- class TestPrompt < Prompt
8
- def initialize(options = {})
9
- @input = StringIO.new
10
- @output = StringIO.new
11
- options.merge!({
12
- input: @input,
13
- output: @output,
14
- env: { "TTY_TEST" => true },
15
- enable_color: options.fetch(:enable_color) { true }
16
- })
17
- super(options)
18
- end
19
- end # TestPrompt
20
- end # TTY
data/spec/spec_helper.rb DELETED
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ])
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty-prompt'
19
-
20
- class StringIO
21
- def wait_readable(*)
22
- true
23
- end
24
- end
25
-
26
- module Helpers
27
- def diff_output(actual_output, expected_output)
28
- puts "ACTUAL: #{actual_output.inspect}"
29
- puts "--------------------------------\n"
30
- puts "EXPECT: #{expected_output.inspect}"
31
- end
32
- end
33
-
34
- RSpec.configure do |config|
35
- config.include(Helpers)
36
-
37
- config.expect_with :rspec do |expectations|
38
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
- end
40
-
41
- config.mock_with :rspec do |mocks|
42
- mocks.verify_partial_doubles = true
43
- end
44
-
45
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
46
- config.disable_monkey_patching!
47
-
48
- # This setting enables warnings. It's recommended, but in some cases may
49
- # be too noisy due to issues in dependencies.
50
- config.warnings = true
51
-
52
- if config.files_to_run.one?
53
- config.default_formatter = 'doc'
54
- end
55
-
56
- config.profile_examples = 2
57
-
58
- config.order = :random
59
-
60
- Kernel.srand config.seed
61
- end
@@ -1,173 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt, '#ask' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'asks question' do
8
- prompt.ask('What is your name?')
9
- expect(prompt.output.string).to eq([
10
- "What is your name? ",
11
- "\e[1A\e[2K\e[1G",
12
- "What is your name? \n"
13
- ].join)
14
- end
15
-
16
- it 'asks an empty question ' do
17
- prompt = TTY::TestPrompt.new
18
- prompt.input << "\r"
19
- prompt.input.rewind
20
-
21
- answer = prompt.ask
22
- expect(answer).to eq(nil)
23
-
24
- expect(prompt.output.string).to eql("\e[2K\e[1G\n\e[1A\e[2K\e[1G\n")
25
- end
26
-
27
- it "asks an empty question and returns nil if EOF is sent to stdin" do
28
- prompt = TTY::TestPrompt.new
29
- prompt.input << nil
30
- prompt.input.rewind
31
-
32
- answer = prompt.ask('')
33
-
34
- expect(answer).to eql(nil)
35
- expect(prompt.output.string).to eq("\e[1A\e[2K\e[1G\n")
36
- end
37
-
38
- it "asks an empty question with prepopulated value" do
39
- prompt = TTY::TestPrompt.new
40
- prompt.input << "\n"
41
- prompt.input.rewind
42
-
43
- answer = prompt.ask value: "yes"
44
-
45
- expect(answer).to eq("yes")
46
- expect(prompt.output.string).to eq([
47
- "yes\e[2K\e[1G",
48
- "yes\n\e[1A\e[2K\e[1G",
49
- "\e[32myes\e[0m\n"
50
- ].join)
51
- end
52
-
53
- it "asks question with prepopulated value" do
54
- prompt = TTY::TestPrompt.new prefix: "> "
55
- prompt.input << "\n"
56
- prompt.input.rewind
57
-
58
- answer = prompt.ask("Say?") do |q|
59
- q.value "yes"
60
- end
61
-
62
- expect(answer).to eq("yes")
63
- expect(prompt.output.string).to eq([
64
- "> Say? yes\e[2K\e[1G",
65
- "> Say? yes\n\e[1A\e[2K\e[1G",
66
- "> Say? \e[32myes\e[0m\n"
67
- ].join)
68
- end
69
-
70
- it "asks a question with a prefix [?]" do
71
- prompt = TTY::TestPrompt.new(prefix: "[?] ")
72
- prompt.input << "\r"
73
- prompt.input.rewind
74
- answer = prompt.ask 'Are you Polish?'
75
- expect(answer).to eq(nil)
76
- expect(prompt.output.string).to eq([
77
- "[?] Are you Polish? ",
78
- "\e[2K\e[1G[?] Are you Polish? \n",
79
- "\e[1A\e[2K\e[1G",
80
- "[?] Are you Polish? \n"
81
- ].join)
82
- end
83
-
84
- it 'asks a question with block' do
85
- prompt.input << ''
86
- prompt.input.rewind
87
- answer = prompt.ask "What is your name?" do |q|
88
- q.default 'Piotr'
89
- end
90
- expect(answer).to eq('Piotr')
91
- expect(prompt.output.string).to eq([
92
- "What is your name? \e[90m(Piotr)\e[0m ",
93
- "\e[1A\e[2K\e[1G",
94
- "What is your name? \e[32mPiotr\e[0m\n"
95
- ].join)
96
- end
97
-
98
- it "changes question color" do
99
- prompt.input << ''
100
- prompt.input.rewind
101
- options = {default: 'Piotr', help_color: :red, active_color: :cyan}
102
- answer = prompt.ask("What is your name?", options)
103
- expect(answer).to eq('Piotr')
104
- expect(prompt.output.string).to eq([
105
- "What is your name? \e[31m(Piotr)\e[0m ",
106
- "\e[1A\e[2K\e[1G",
107
- "What is your name? \e[36mPiotr\e[0m\n"
108
- ].join)
109
- end
110
-
111
- it "permits empty default parameter" do
112
- prompt.input << "\r"
113
- prompt.input.rewind
114
-
115
- answer = prompt.ask("What is your name?", default: '')
116
- expect(answer).to eq('')
117
- expect(prompt.output.string).to eq([
118
- "What is your name? ",
119
- "\e[2K\e[1GWhat is your name? \n",
120
- "\e[1A\e[2K\e[1G",
121
- "What is your name? \n"
122
- ].join)
123
- end
124
-
125
- it "permits nil default parameter" do
126
- prompt.input << "\r"
127
- prompt.input.rewind
128
-
129
- answer = prompt.ask("What is your name?", default: nil)
130
- expect(answer).to eq(nil)
131
- expect(prompt.output.string).to eq([
132
- "What is your name? ",
133
- "\e[2K\e[1GWhat is your name? \n",
134
- "\e[1A\e[2K\e[1G",
135
- "What is your name? \n"
136
- ].join)
137
- end
138
-
139
- it "overwrites global settings" do
140
- global_settings = {prefix: "[?] ", active_color: :cyan, help_color: :red}
141
- prompt = TTY::TestPrompt.new(global_settings)
142
-
143
- prompt.input << "Piotr\r"
144
- prompt.input.rewind
145
- prompt.ask('What is your name?')
146
-
147
- prompt.input << "Piotr\r"
148
- prompt.input.rewind
149
- local_settings = {prefix: ':-) ', active_color: :blue, help_color: :magenta}
150
- prompt.ask('What is your name?', local_settings)
151
-
152
- expect(prompt.output.string).to eq([
153
- "[?] What is your name? ",
154
- "\e[2K\e[1G[?] What is your name? P",
155
- "\e[2K\e[1G[?] What is your name? Pi",
156
- "\e[2K\e[1G[?] What is your name? Pio",
157
- "\e[2K\e[1G[?] What is your name? Piot",
158
- "\e[2K\e[1G[?] What is your name? Piotr",
159
- "\e[2K\e[1G[?] What is your name? Piotr\n",
160
- "\e[1A\e[2K\e[1G",
161
- "[?] What is your name? \e[36mPiotr\e[0m\n",
162
- ":-) What is your name? ",
163
- "\e[2K\e[1G:-) What is your name? P",
164
- "\e[2K\e[1G:-) What is your name? Pi",
165
- "\e[2K\e[1G:-) What is your name? Pio",
166
- "\e[2K\e[1G:-) What is your name? Piot",
167
- "\e[2K\e[1G:-) What is your name? Piotr",
168
- "\e[2K\e[1G:-) What is your name? Piotr\n",
169
- "\e[1A\e[2K\e[1G",
170
- ":-) What is your name? \e[34mPiotr\e[0m\n"
171
- ].join)
172
- end
173
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::BlockPaginator, '#paginate' do
4
- it "ignores per_page when equal items " do
5
- list = %w(a b c d)
6
- paginator = described_class.new({per_page: 4})
7
-
8
- expect(paginator.paginate(list, 1).to_a).to eq([
9
- ['a',0],['b',1],['c',2],['d',3]])
10
- end
11
-
12
- it "ignores per_page when less items " do
13
- list = %w(a b c d)
14
- paginator = described_class.new({per_page: 5})
15
-
16
- expect(paginator.paginate(list, 1).to_a).to eq([
17
- ['a',0],['b',1],['c',2],['d',3]])
18
- end
19
-
20
- it "paginates items matching per_page count" do
21
- list = %w(a b c d e f)
22
- paginator = described_class.new({per_page: 3})
23
-
24
- expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
25
- expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
26
- expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
27
- expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
28
- expect(paginator.paginate(list, 5).to_a).to eq([['d',3], ['e',4], ['f',5]])
29
- expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
30
- expect(paginator.paginate(list, 7).to_a).to eq([['d',3], ['e',4], ['f',5]])
31
- end
32
-
33
- it "paginates items not matching per_page count" do
34
- list = %w(a b c d e f g)
35
- paginator = described_class.new({per_page: 3})
36
-
37
- expect(paginator.paginate(list, 1).to_a).to eq([['a',0], ['b',1], ['c',2]])
38
- expect(paginator.paginate(list, 2).to_a).to eq([['a',0], ['b',1], ['c',2]])
39
- expect(paginator.paginate(list, 3).to_a).to eq([['a',0], ['b',1], ['c',2]])
40
- expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
41
- expect(paginator.paginate(list, 5).to_a).to eq([['d',3], ['e',4], ['f',5]])
42
- expect(paginator.paginate(list, 6).to_a).to eq([['d',3], ['e',4], ['f',5]])
43
- expect(paginator.paginate(list, 7).to_a).to eq([['g',6]])
44
- expect(paginator.paginate(list, 8).to_a).to eq([['g',6]])
45
- end
46
-
47
- it "finds both start and end index for current selection" do
48
- list = %w(a b c d e f g)
49
- paginator = described_class.new({per_page: 3, default: 0})
50
-
51
- paginator.paginate(list, 3)
52
- expect(paginator.start_index).to eq(0)
53
- expect(paginator.end_index).to eq(2)
54
-
55
- paginator.paginate(list, 4)
56
- expect(paginator.start_index).to eq(3)
57
- expect(paginator.end_index).to eq(5)
58
-
59
- paginator.paginate(list, 5)
60
- expect(paginator.start_index).to eq(3)
61
- expect(paginator.end_index).to eq(5)
62
-
63
- paginator.paginate(list, 7)
64
- expect(paginator.start_index).to eq(6)
65
- expect(paginator.end_index).to eq(6)
66
- end
67
-
68
- it "starts with default selection" do
69
- list = %w(a b c d e f g)
70
- paginator = described_class.new({per_page: 3, default: 3})
71
-
72
- expect(paginator.paginate(list, 4).to_a).to eq([['d',3], ['e',4], ['f',5]])
73
- end
74
-
75
- it "doesn't accept invalid pagination" do
76
- list = %w(a b c d e f g)
77
-
78
- paginator = described_class.new({per_page: 0})
79
-
80
- expect {
81
- paginator.paginate(list, 4)
82
- }.to raise_error(TTY::Prompt::InvalidArgument, /per_page must be > 0/)
83
- end
84
- end