highline_wrapper 1.3.0 → 2.0.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/Gemfile.lock +55 -45
- data/Guardfile +2 -2
- data/README.md +68 -12
- data/lib/highline_wrapper/checkbox_question.rb +2 -2
- data/lib/highline_wrapper/multiple_choice_question.rb +1 -1
- data/lib/highline_wrapper/open_ended_question.rb +2 -2
- data/lib/highline_wrapper/question.rb +2 -3
- data/lib/highline_wrapper/version.rb +1 -1
- data/lib/highline_wrapper/yes_no_question.rb +1 -1
- data/lib/highline_wrapper.rb +1 -1
- data/renovate.json +9 -0
- metadata +25 -21
- data/spec/highline_wrapper/checkbox_question_spec.rb +0 -226
- data/spec/highline_wrapper/multiple_choice_question_spec.rb +0 -226
- data/spec/highline_wrapper/open_ended_question_spec.rb +0 -108
- data/spec/highline_wrapper/question_spec.rb +0 -114
- data/spec/highline_wrapper/yes_no_question_spec.rb +0 -108
- data/spec/spec_helper.rb +0 -50
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'highline_wrapper'
|
5
|
-
|
6
|
-
describe HighlineWrapper::Question do
|
7
|
-
let(:response) { double(:response, readline: true, to_i: 3) }
|
8
|
-
let(:highline) { double(:highline_cli, ask: response) }
|
9
|
-
|
10
|
-
before do
|
11
|
-
allow(HighLine).to receive(:new).and_return(highline)
|
12
|
-
allow(subject).to receive(:puts)
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
HighlineWrapper::Question.instance_variable_set('@highline', nil)
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { HighlineWrapper::Question }
|
20
|
-
|
21
|
-
describe '#highline' do
|
22
|
-
it 'should start a new highline client' do
|
23
|
-
expect(HighLine).to receive(:new)
|
24
|
-
subject.send(:highline)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#ask_highline' do
|
29
|
-
it 'should ask the highline client a question' do
|
30
|
-
expect(HighLine).to receive(:new)
|
31
|
-
subject.send(:ask_highline, Faker::Lorem.sentence)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should accept an optional secret parameter' do
|
35
|
-
expect(HighLine).to receive(:new)
|
36
|
-
subject.send(:ask_highline, Faker::Lorem.sentence, secret: true)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#format_options' do
|
41
|
-
it 'should format the prompt and choices into a single string with new lines' do
|
42
|
-
response = "Prompt\n1. Choice 1\n2. Choice 2"
|
43
|
-
expect(subject.format_options('Prompt', ['Choice 1', 'Choice 2'])).to eq(response)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#format_selection' do
|
48
|
-
let(:choices) { %w[one two three] }
|
49
|
-
let(:index) { 1 }
|
50
|
-
|
51
|
-
context 'with_index as false' do
|
52
|
-
it 'should format the selection based on the index into a hash' do
|
53
|
-
expect(subject.format_selection(choices, index, false)).to eq({ value: 'two' })
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with_index as true' do
|
58
|
-
it 'should format the selection based on the index into a hash' do
|
59
|
-
expect(subject.format_selection(choices, index, true)).to eq({ value: 'two', index: 1 })
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#should print out a message indicating EMPTY was selected, and return the defaults' do
|
65
|
-
context 'when default message is true' do
|
66
|
-
let(:options) do
|
67
|
-
{
|
68
|
-
defaults: :default,
|
69
|
-
indicate_default_message: true
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should return the default in the options' do
|
74
|
-
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should puts a message' do
|
78
|
-
expect(subject).to receive(:puts)
|
79
|
-
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'when default message is false' do
|
84
|
-
let(:options) do
|
85
|
-
{
|
86
|
-
defaults: :default,
|
87
|
-
indicate_default_message: false
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should return the default in the options' do
|
92
|
-
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should not puts a message' do
|
96
|
-
expect(subject).not_to receive(:puts)
|
97
|
-
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'when a singular default is present, but not plural' do
|
102
|
-
let(:options) do
|
103
|
-
{
|
104
|
-
default: :default,
|
105
|
-
indicate_default_message: false
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should return the default in the options' do
|
110
|
-
expect(subject.send(:return_empty_defaults, options)).to eq(:default)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'highline_wrapper'
|
5
|
-
|
6
|
-
describe HighlineWrapper::YesNoQuestion do
|
7
|
-
let(:response) { double(:response, readline: true, to_i: 3) }
|
8
|
-
let(:highline) { double(:highline_cli, ask: response) }
|
9
|
-
|
10
|
-
before do
|
11
|
-
allow(HighLine).to receive(:new).and_return(highline)
|
12
|
-
allow(subject).to receive(:puts)
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
HighlineWrapper::YesNoQuestion.instance_variable_set('@highline', nil)
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { HighlineWrapper::YesNoQuestion }
|
20
|
-
|
21
|
-
context 'with the options as defaults' do
|
22
|
-
let(:options) do
|
23
|
-
{
|
24
|
-
indicate_default_message: true,
|
25
|
-
default: true,
|
26
|
-
required: false
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should ask the highline client ask' do
|
31
|
-
expect(highline).to receive(:ask).and_return('Y')
|
32
|
-
subject.ask(Faker::Lorem.sentence, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should return the value the user selects' do
|
36
|
-
allow(highline).to receive(:ask).and_return('n')
|
37
|
-
resp = subject.ask(Faker::Lorem.sentence, options)
|
38
|
-
expect(resp).to eq(false)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should return true if the user skips' do
|
42
|
-
allow(highline).to receive(:ask).and_return('')
|
43
|
-
resp = subject.ask(Faker::Lorem.sentence, options)
|
44
|
-
expect(resp).to eq(true)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should call to print the default message' do
|
48
|
-
allow(highline).to receive(:ask).and_return('')
|
49
|
-
expect(subject).to receive(:print_default_message)
|
50
|
-
subject.ask(Faker::Lorem.sentence, options)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should recurse if the answer given is unparseable' do
|
54
|
-
allow(highline).to receive(:ask).and_return('yep', 'yessss', 'yes')
|
55
|
-
expect(subject).to receive(:recurse).exactly(2).times.and_call_original
|
56
|
-
subject.ask(Faker::Lorem.sentence, options)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'with required set to true' do
|
61
|
-
let(:options) do
|
62
|
-
{
|
63
|
-
default: false,
|
64
|
-
required: true
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should return the value the user selects' do
|
69
|
-
allow(highline).to receive(:ask).and_return('y')
|
70
|
-
resp = subject.ask(Faker::Lorem.sentence, options)
|
71
|
-
expect(resp).to eq(true)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should recurse multiple times if the user skips' do
|
75
|
-
allow(highline).to receive(:ask).and_return('', '', 'y')
|
76
|
-
expect(subject).to receive(:ask).exactly(3).times.and_call_original
|
77
|
-
subject.ask(Faker::Lorem.sentence, options)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'with required set to false' do
|
82
|
-
let(:options) do
|
83
|
-
{
|
84
|
-
indicate_default_message: false,
|
85
|
-
default: false,
|
86
|
-
required: false
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should return the value the user selects' do
|
91
|
-
allow(highline).to receive(:ask).and_return('y')
|
92
|
-
resp = subject.ask(Faker::Lorem.sentence, options)
|
93
|
-
expect(resp).to eq(true)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should return the default if the user skips' do
|
97
|
-
allow(highline).to receive(:ask).and_return('')
|
98
|
-
resp = subject.ask(Faker::Lorem.sentence, options)
|
99
|
-
expect(resp).to eq(false)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should not call to print the default message' do
|
103
|
-
allow(highline).to receive(:ask).and_return('')
|
104
|
-
expect(subject).not_to receive(:print_default_message)
|
105
|
-
subject.ask(Faker::Lorem.sentence, options)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'faker'
|
4
|
-
require 'pry'
|
5
|
-
|
6
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
9
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
10
|
-
# files.
|
11
|
-
#
|
12
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
13
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
14
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
15
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
16
|
-
# a separate helper file that requires the additional dependencies and performs
|
17
|
-
# the additional setup, and require it from the spec files that actually need
|
18
|
-
# it.
|
19
|
-
#
|
20
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
21
|
-
# users commonly want.
|
22
|
-
#
|
23
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
24
|
-
RSpec.configure do |config|
|
25
|
-
# rspec-expectations config goes here. You can use an alternate
|
26
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
27
|
-
# assertions if you prefer.
|
28
|
-
config.expect_with :rspec do |expectations|
|
29
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
30
|
-
# and `failure_message` of custom matchers include text for helper methods
|
31
|
-
# defined using `chain`, e.g.:
|
32
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
-
# # => "be bigger than 2 and smaller than 4"
|
34
|
-
# ...rather than:
|
35
|
-
# # => "be bigger than 2"
|
36
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
-
end
|
38
|
-
|
39
|
-
config.filter_run focus: true
|
40
|
-
config.run_all_when_everything_filtered = true
|
41
|
-
|
42
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
43
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
44
|
-
config.mock_with :rspec do |mocks|
|
45
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
46
|
-
# a real object. This is generally recommended, and will default to
|
47
|
-
# `true` in RSpec 4.
|
48
|
-
mocks.verify_partial_doubles = true
|
49
|
-
end
|
50
|
-
end
|