infopark-user_io 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/infopark/user_io.rb +3 -2
- data/lib/infopark/user_io/version.rb +1 -1
- data/spec/user_io_spec.rb +40 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 549d77e9aa188b9e65396c3759356988cf15cbe1
|
4
|
+
data.tar.gz: cee33dabca5cd62924d6b30ca57b9ff3d4f765c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2df43bc7cde82fb867657892b2bb4fe9a96161482ff79b31a9e29d1159e3df4052d67c69655904eecf32624b5f6e2f0d31f8a4164697f28296135ff36d56547
|
7
|
+
data.tar.gz: af3d4d4f243a6cebb4ee3588fe95f1352d04622fd5f2f13e1940f8412f05cf09e312e5764d63dd1209ff1ec70168aeeb1f40bc3931d8177f42e6162fcc88b21f
|
data/lib/infopark/user_io.rb
CHANGED
@@ -115,8 +115,9 @@ class UserIO
|
|
115
115
|
read_line
|
116
116
|
end
|
117
117
|
|
118
|
-
def ask(*text, default: nil)
|
118
|
+
def ask(*text, default: nil, expected: "yes")
|
119
119
|
# TODO implementation error if default not boolean or nil
|
120
|
+
# TODO implementation error if expected not "yes" or "no"
|
120
121
|
tell("-" * 80)
|
121
122
|
tell(*text, color: :cyan, bright: true)
|
122
123
|
tell("-" * 80)
|
@@ -130,7 +131,7 @@ class UserIO
|
|
130
131
|
tell("I couldn't understand “#{answer}”.", newline: false, color: :red, bright: true)
|
131
132
|
tell(" > ", newline: false)
|
132
133
|
end
|
133
|
-
answer ==
|
134
|
+
answer == expected
|
134
135
|
end
|
135
136
|
|
136
137
|
def listen(prompt = nil, **options)
|
data/spec/user_io_spec.rb
CHANGED
@@ -107,6 +107,46 @@ RSpec.describe UserIO do
|
|
107
107
|
# TODO
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
context "with “expected”" do
|
112
|
+
let(:ask_options) { {expected: expected_value} }
|
113
|
+
|
114
|
+
context "“yes”" do
|
115
|
+
let(:expected_value) { "yes" }
|
116
|
+
|
117
|
+
it_behaves_like "any question"
|
118
|
+
|
119
|
+
it "returns “true” when answering “yes”" do
|
120
|
+
expect($stdin).to receive(:gets).and_return("yes\n")
|
121
|
+
expect(ask).to be true
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns “false” when answering “no”"do
|
125
|
+
expect($stdin).to receive(:gets).and_return("no\n")
|
126
|
+
expect(ask).to be false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "“no”" do
|
131
|
+
let(:expected_value) { "no" }
|
132
|
+
|
133
|
+
it_behaves_like "any question"
|
134
|
+
|
135
|
+
it "returns “true” when answering “no”" do
|
136
|
+
expect($stdin).to receive(:gets).and_return("no\n")
|
137
|
+
expect(ask).to be true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns “false” when answering “yes”" do
|
141
|
+
expect($stdin).to receive(:gets).and_return("yes\n")
|
142
|
+
expect(ask).to be false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "other" do
|
147
|
+
# TODO
|
148
|
+
end
|
149
|
+
end
|
110
150
|
end
|
111
151
|
|
112
152
|
describe "#select" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark-user_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilo Prütz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|