highline_wrapper 1.3.1 → 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.
@@ -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