highline_wrapper 0.1.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'highline_wrapper'
5
-
6
- describe HighlineWrapper::Client 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
- end
13
-
14
- describe '#ask' do
15
- it 'should ask the highline client ask' do
16
- expect(highline).to receive(:ask)
17
- subject.ask(Faker::Lorem.sentence, false)
18
- end
19
-
20
- it 'should return a string' do
21
- expect(subject.ask(Faker::Lorem.sentence, true)).to be_a(String)
22
- end
23
- end
24
-
25
- describe '#ask_yes_no' do
26
- it 'should ask the highline client ask' do
27
- expect(highline).to receive(:ask)
28
- subject.ask_yes_no(Faker::Lorem.sentence, true)
29
- end
30
-
31
- it 'should return a boolean' do
32
- expect(subject.ask_yes_no(Faker::Lorem.sentence, false)).to be_falsey
33
- end
34
-
35
- it 'should return true if we say yes' do
36
- allow(response).to receive(:to_s).and_return('y')
37
- expect(subject.ask_yes_no(Faker::Lorem.sentence, false)).to be_truthy
38
- end
39
-
40
- it 'should return false if we say yes' do
41
- allow(response).to receive(:to_s).and_return('no')
42
- expect(subject.ask_yes_no(Faker::Lorem.sentence, true)).to be_falsey
43
- end
44
-
45
- context 'when preferring true' do
46
- it 'should return true if empty' do
47
- allow(response).to receive(:to_s).and_return('')
48
- expect(subject.ask_yes_no(Faker::Lorem.sentence, true)).to be_truthy
49
- end
50
-
51
- it 'should return false if empty' do
52
- allow(response).to receive(:to_s).and_return('')
53
- expect(subject.ask_yes_no(Faker::Lorem.sentence, false)).to be_falsey
54
- end
55
- end
56
- end
57
-
58
- describe '#ask_multiple_choice' do
59
- it 'should ask the highline client ask' do
60
- expect(highline).to receive(:ask)
61
- subject.ask_multiple_choice(Faker::Lorem.sentence, %w[one two three], false)
62
- end
63
-
64
- context 'when not including the index' do
65
- it 'should return an array of one from the options' do
66
- resp = subject.ask_multiple_choice(Faker::Lorem.sentence, %w[one two three], false)
67
- expect(resp).to be_a(String)
68
- expect(resp).to eq('three')
69
- end
70
- end
71
-
72
- context 'when including the index' do
73
- it 'should return an array of two' do
74
- resp = subject.ask_multiple_choice(Faker::Lorem.sentence, %w[one two three], true)
75
- expect(resp).to be_a(Hash)
76
- expect(resp[:choice]).to eq('three')
77
- expect(resp[:index]).to eq(2)
78
- end
79
- end
80
- end
81
-
82
- describe '#ask_checkbox' do
83
- it 'should ask the highline client ask' do
84
- expect(highline).to receive(:ask).and_return('2')
85
- subject.ask_checkbox(Faker::Lorem.sentence, %w[one two three], false)
86
- end
87
-
88
- context 'when not including the index' do
89
- it 'should return an array of one from the options' do
90
- allow(highline).to receive(:ask).and_return('1, 3')
91
- resp = subject.ask_checkbox(Faker::Lorem.sentence, %w[one two three], false)
92
- expect(resp).to be_a(Array)
93
- expect(resp.count).to eq(2)
94
- expect(resp).to include('one')
95
- end
96
- end
97
-
98
- context 'when including the index' do
99
- it 'should return an array of two' do
100
- allow(highline).to receive(:ask).and_return('1, 3')
101
- resp = subject.ask_checkbox(Faker::Lorem.sentence, %w[one two three], true)
102
- expect(resp).to be_a(Array)
103
- expect(resp.count).to eq(2)
104
- expect(resp).to include({ choice: 'one', index: 0 })
105
- expect(resp).to include({ choice: 'three', index: 2 })
106
- end
107
- end
108
- end
109
- end