tty-prompt 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +29 -4
- data/lib/tty/prompt.rb +3 -3
- data/lib/tty/prompt/multi_list.rb +33 -10
- data/lib/tty/prompt/version.rb +1 -1
- metadata +11 -175
- data/Rakefile +0 -8
- data/examples/ask.rb +0 -7
- data/examples/ask_blank.rb +0 -9
- data/examples/ask_multiline.rb +0 -7
- data/examples/ask_valid.rb +0 -12
- data/examples/collect.rb +0 -21
- data/examples/echo.rb +0 -11
- data/examples/enum_select.rb +0 -7
- data/examples/enum_select_disabled.rb +0 -16
- data/examples/enum_select_paged.rb +0 -9
- data/examples/enum_select_wrapped.rb +0 -15
- data/examples/expand.rb +0 -29
- data/examples/expand_auto.rb +0 -29
- data/examples/in.rb +0 -9
- data/examples/inputs.rb +0 -10
- data/examples/key_events.rb +0 -15
- data/examples/keypress.rb +0 -9
- data/examples/mask.rb +0 -13
- data/examples/multi_select.rb +0 -8
- data/examples/multi_select_disabled.rb +0 -17
- data/examples/multi_select_disabled_paged.rb +0 -22
- data/examples/multi_select_paged.rb +0 -9
- data/examples/multi_select_wrapped.rb +0 -15
- data/examples/multiline.rb +0 -9
- data/examples/pause.rb +0 -9
- data/examples/select.rb +0 -24
- data/examples/select_disabled.rb +0 -18
- data/examples/select_disabled_paged.rb +0 -22
- data/examples/select_enum.rb +0 -8
- data/examples/select_filtered.rb +0 -11
- data/examples/select_paginated.rb +0 -11
- data/examples/select_wrapped.rb +0 -15
- data/examples/slider.rb +0 -6
- data/examples/validation.rb +0 -9
- data/examples/yes_no.rb +0 -7
- data/spec/spec_helper.rb +0 -61
- data/spec/unit/ask_spec.rb +0 -173
- data/spec/unit/block_paginator_spec.rb +0 -84
- data/spec/unit/choice/eql_spec.rb +0 -22
- data/spec/unit/choice/from_spec.rb +0 -130
- data/spec/unit/choices/add_spec.rb +0 -12
- data/spec/unit/choices/each_spec.rb +0 -13
- data/spec/unit/choices/find_by_spec.rb +0 -10
- data/spec/unit/choices/new_spec.rb +0 -10
- data/spec/unit/choices/pluck_spec.rb +0 -9
- data/spec/unit/collect_spec.rb +0 -96
- data/spec/unit/converters/convert_bool_spec.rb +0 -58
- data/spec/unit/converters/convert_char_spec.rb +0 -11
- data/spec/unit/converters/convert_custom_spec.rb +0 -14
- data/spec/unit/converters/convert_date_spec.rb +0 -34
- data/spec/unit/converters/convert_file_spec.rb +0 -18
- data/spec/unit/converters/convert_number_spec.rb +0 -39
- data/spec/unit/converters/convert_path_spec.rb +0 -15
- data/spec/unit/converters/convert_range_spec.rb +0 -22
- data/spec/unit/converters/convert_regex_spec.rb +0 -12
- data/spec/unit/converters/convert_string_spec.rb +0 -21
- data/spec/unit/converters/on_error_spec.rb +0 -9
- data/spec/unit/distance/distance_spec.rb +0 -73
- data/spec/unit/enum_select_spec.rb +0 -518
- data/spec/unit/error_spec.rb +0 -20
- data/spec/unit/evaluator_spec.rb +0 -67
- data/spec/unit/expand_spec.rb +0 -290
- data/spec/unit/keypress_spec.rb +0 -66
- data/spec/unit/mask_spec.rb +0 -140
- data/spec/unit/multi_select_spec.rb +0 -741
- data/spec/unit/multiline_spec.rb +0 -77
- data/spec/unit/new_spec.rb +0 -20
- data/spec/unit/ok_spec.rb +0 -10
- data/spec/unit/paginator_spec.rb +0 -92
- data/spec/unit/question/checks_spec.rb +0 -97
- data/spec/unit/question/default_spec.rb +0 -31
- data/spec/unit/question/echo_spec.rb +0 -38
- data/spec/unit/question/in_spec.rb +0 -115
- data/spec/unit/question/initialize_spec.rb +0 -12
- data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
- data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
- data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
- data/spec/unit/question/modify_spec.rb +0 -41
- data/spec/unit/question/required_spec.rb +0 -92
- data/spec/unit/question/validate_spec.rb +0 -115
- data/spec/unit/question/validation/call_spec.rb +0 -31
- data/spec/unit/question/validation/coerce_spec.rb +0 -30
- data/spec/unit/result_spec.rb +0 -40
- data/spec/unit/say_spec.rb +0 -67
- data/spec/unit/select_spec.rb +0 -942
- data/spec/unit/slider_spec.rb +0 -142
- data/spec/unit/statement/initialize_spec.rb +0 -15
- data/spec/unit/subscribe_spec.rb +0 -22
- data/spec/unit/suggest_spec.rb +0 -28
- data/spec/unit/timer_spec.rb +0 -29
- data/spec/unit/warn_spec.rb +0 -21
- data/spec/unit/yes_no_spec.rb +0 -285
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-prompt.gemspec +0 -40
    
        data/examples/select_wrapped.rb
    DELETED
    
    | @@ -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
    
    
    
        data/examples/validation.rb
    DELETED
    
    
    
        data/examples/yes_no.rb
    DELETED
    
    
    
        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
         | 
    
        data/spec/unit/ask_spec.rb
    DELETED
    
    | @@ -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
         | 
| @@ -1,22 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            RSpec.describe TTY::Prompt::Choice, '#==' do
         | 
| 4 | 
            -
              it "is true with the same name and value attributes" do
         | 
| 5 | 
            -
                expect(described_class.new(:large, 1)).
         | 
| 6 | 
            -
                  to eq(described_class.new(:large, 1))
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              it "is false with different name attribute" do
         | 
| 10 | 
            -
                expect(described_class.new(:large, 1)).
         | 
| 11 | 
            -
                  not_to eq(described_class.new(:medium, 1))
         | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              it "is false with different value attribute" do
         | 
| 15 | 
            -
                expect(described_class.new(:large, 1)).
         | 
| 16 | 
            -
                  not_to eq(described_class.new(:large, 2))
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              it "is false with non-choice object" do
         | 
| 20 | 
            -
                expect(described_class.new(:large, 1)).not_to eq(:other)
         | 
| 21 | 
            -
              end
         | 
| 22 | 
            -
            end
         | 
| @@ -1,130 +0,0 @@ | |
| 1 | 
            -
            # frozen_string_literal: true
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            RSpec.describe TTY::Prompt::Choice, '#from' do
         | 
| 4 | 
            -
              it "skips Choice instance" do
         | 
| 5 | 
            -
                choice = described_class.new(:large, 1)
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                expect(described_class.from(choice)).to eq(choice)
         | 
| 8 | 
            -
              end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              it "creates choice from string" do
         | 
| 11 | 
            -
                expected_choice = described_class.new('large', 'large')
         | 
| 12 | 
            -
                choice = described_class.from('large')
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 15 | 
            -
                expect(choice.name).to eq('large')
         | 
| 16 | 
            -
                expect(choice.value).to eq('large')
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              it "creates choice from array with one element" do
         | 
| 20 | 
            -
                expected_choice = described_class.new('large', 'large')
         | 
| 21 | 
            -
                choice = described_class.from([:large])
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 24 | 
            -
                expect(choice.name).to eq('large')
         | 
| 25 | 
            -
                expect(choice.value).to eq('large')
         | 
| 26 | 
            -
              end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              it "creates choice from array with more than one element" do
         | 
| 29 | 
            -
                expected_choice = described_class.new('large', 1)
         | 
| 30 | 
            -
                choice = described_class.from([:large, 1])
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 33 | 
            -
                expect(choice.name).to eq('large')
         | 
| 34 | 
            -
                expect(choice.value).to eq(1)
         | 
| 35 | 
            -
              end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
              it "creates choice from array with false" do
         | 
| 38 | 
            -
                expected_choice = described_class.new('large', false)
         | 
| 39 | 
            -
                choice = described_class.from([:large, false])
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 42 | 
            -
                expect(choice.name).to eq('large')
         | 
| 43 | 
            -
                expect(choice.value).to eq(false)
         | 
| 44 | 
            -
              end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
              it "defaults value to name if value is nil" do
         | 
| 47 | 
            -
                expected_choice = described_class.new('large', 'large')
         | 
| 48 | 
            -
                choice = described_class.from([:large, nil])
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 51 | 
            -
                expect(choice.name).to eq('large')
         | 
| 52 | 
            -
                expect(choice.value).to eq('large')
         | 
| 53 | 
            -
              end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
              it "creates choice from hash value" do
         | 
| 56 | 
            -
                expected_choice = described_class.new('large', 1)
         | 
| 57 | 
            -
                choice = described_class.from({large: 1})
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 60 | 
            -
                expect(choice.name).to eq('large')
         | 
| 61 | 
            -
                expect(choice.value).to eq(1)
         | 
| 62 | 
            -
              end
         | 
| 63 | 
            -
             | 
| 64 | 
            -
              it "creats choice from array with key value pair" do
         | 
| 65 | 
            -
                expected_choice = described_class.new('large', 1)
         | 
| 66 | 
            -
                choice = described_class.from([{'large' => 1}])
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 69 | 
            -
                expect(choice.name).to eq('large')
         | 
| 70 | 
            -
                expect(choice.value).to eq(1)
         | 
| 71 | 
            -
              end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
              it "creats choice from array with hash elements" do
         | 
| 74 | 
            -
                expected_choice = described_class.new('large', 1)
         | 
| 75 | 
            -
                choice = described_class.from([{name: 'large', value: 1}])
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 78 | 
            -
                expect(choice.name).to eq('large')
         | 
| 79 | 
            -
                expect(choice.value).to eq(1)
         | 
| 80 | 
            -
              end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
              it "creats choice from array with hash elements without value" do
         | 
| 83 | 
            -
                expected_choice = described_class.new('large', 'large')
         | 
| 84 | 
            -
                choice = described_class.from([{name: 'large'}])
         | 
| 85 | 
            -
             | 
| 86 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 87 | 
            -
                expect(choice.name).to eq('large')
         | 
| 88 | 
            -
                expect(choice.value).to eq('large')
         | 
| 89 | 
            -
              end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
              it "creates choice from hash with key property" do
         | 
| 92 | 
            -
                default = {key: 'h', name: 'Help', value: :help}
         | 
| 93 | 
            -
                expected_choice = described_class.new('Help', :help, key: 'h')
         | 
| 94 | 
            -
                choice = described_class.from(default) 
         | 
| 95 | 
            -
             | 
| 96 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 97 | 
            -
                expect(choice.name).to eq('Help')
         | 
| 98 | 
            -
                expect(choice.value).to eq(:help)
         | 
| 99 | 
            -
                expect(choice.disabled?).to eq(false)
         | 
| 100 | 
            -
              end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
              it "creates disabled choice" do
         | 
| 103 | 
            -
                expected_choice = described_class.new('Disabled', :none, disabled: true)
         | 
| 104 | 
            -
                choice = described_class.from({
         | 
| 105 | 
            -
                  name: 'Disabled',
         | 
| 106 | 
            -
                  value: :none,
         | 
| 107 | 
            -
                  disabled: 'unavailable'})
         | 
| 108 | 
            -
             | 
| 109 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 110 | 
            -
                expect(choice.name).to eq('Disabled')
         | 
| 111 | 
            -
                expect(choice.value).to eq(:none)
         | 
| 112 | 
            -
                expect(choice.disabled?).to eq(true)
         | 
| 113 | 
            -
              end
         | 
| 114 | 
            -
             | 
| 115 | 
            -
              it "creates choice from an arbitrary object that responds to to_s call" do
         | 
| 116 | 
            -
                stub_const("Size", Class.new do
         | 
| 117 | 
            -
                  def to_s
         | 
| 118 | 
            -
                    'large'
         | 
| 119 | 
            -
                  end
         | 
| 120 | 
            -
                end)
         | 
| 121 | 
            -
                size = Size.new
         | 
| 122 | 
            -
                expected_choice = described_class.new(size, size)
         | 
| 123 | 
            -
                choice = described_class.from(size)
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                expect(choice).to eq(expected_choice)
         | 
| 126 | 
            -
                expect(choice.name).to eq(size)
         | 
| 127 | 
            -
                expect(choice.value).to eq(size)
         | 
| 128 | 
            -
                expect(choice.disabled?).to eq(false)
         | 
| 129 | 
            -
              end
         | 
| 130 | 
            -
            end
         |