infopark-user_io 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a15ce6d28285af37873131efa6a552e1171dc387
4
- data.tar.gz: 2a4db190e4f9006fe8243fd31c4708a63bbff4d4
3
+ metadata.gz: 549d77e9aa188b9e65396c3759356988cf15cbe1
4
+ data.tar.gz: cee33dabca5cd62924d6b30ca57b9ff3d4f765c8
5
5
  SHA512:
6
- metadata.gz: f167e78f28d95e5926003ee9397717613bb24c0ecf8f1d5d52f0e49c64ea544d4b0861ab59f13b5144c63d4a1303d0bb0613cff7738067ff5918a22eea466afe
7
- data.tar.gz: 5124a94caedb71bfd0404a3f352f6bc2b9d8513158426a6fa4aeae38a6d481d13f97d923f99f4997e6fbc4b5f3b49bdb1265670e519813e544aa704f5d573225
6
+ metadata.gz: d2df43bc7cde82fb867657892b2bb4fe9a96161482ff79b31a9e29d1159e3df4052d67c69655904eecf32624b5f6e2f0d31f8a4164697f28296135ff36d56547
7
+ data.tar.gz: af3d4d4f243a6cebb4ee3588fe95f1352d04622fd5f2f13e1940f8412f05cf09e312e5764d63dd1209ff1ec70168aeeb1f40bc3931d8177f42e6162fcc88b21f
@@ -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 == "yes"
134
+ answer == expected
134
135
  end
135
136
 
136
137
  def listen(prompt = nil, **options)
@@ -1,5 +1,5 @@
1
1
  module Infopark
2
2
  class UserIO
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -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.0.0
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: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler