shunkuntype 1.0.14 → 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 +5 -5
- data/.gitignore +10 -2
- data/.hyper_card/docs/.Shunkuntype.hiki.swp +0 -0
- data/.hyper_card/history/test_cli_bdd.md +849 -0
- data/.hyper_card/history/test_cli_bdd_251114.md +883 -0
- data/.hyper_card/history/tidy.md +226 -0
- data/.hyper_card/history/tidy_251114.md +248 -0
- data/Gemfile.lock +36 -0
- data/Rakefile +6 -35
- data/exe/shunkuntype +1 -1
- data/lib/shunkuntype/db.rb +7 -14
- data/lib/shunkuntype/finished_check.rb +1 -2
- data/lib/shunkuntype/speed.rb +38 -29
- data/lib/shunkuntype/training.rb +23 -25
- data/lib/shunkuntype/version.rb +2 -7
- data/lib/shunkuntype.rb +35 -111
- data/shunkuntype/speed_data.txt +6 -0
- data/shunkuntype/training_data.txt +36 -0
- data/shunkuntype.gemspec +5 -6
- metadata +50 -59
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/.yardopts +0 -3
- data/Rakefile.rb +0 -1
- data/lib/shunkuntype/#db.rb# +0 -49
- data/lib/shunkuntype/#mk_summary.rb# +0 -77
- data/lib/shunkuntype/merge.rb +0 -52
- data/lib/shunkuntype/mk_summary.rb +0 -77
- data/lib/shunkuntype/options.rb +0 -24
- data/lib/shunkuntype/plot.rb +0 -66
- data/lib/shunkuntype/plot_data.rb +0 -200
- data/shunkuntype_bob/.gitignore +0 -1
- data/shunkuntype_bob/Rakefile +0 -252
- data/shunkuntype_bob/hiki_help.yml +0 -53
- data/shunkuntype_bob/report.hiki +0 -173
- data/shunkuntype_bob/shunkuntype_bob.hiki +0 -36
- /data/{docs → .hyper_card/docs}/Shunkuntype.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_Coding.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_Coding_PlotData.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_Coding_gnuplot.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_GroupHearing_20160128.pdf +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_gemizing.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_manual.hiki +0 -0
- /data/{docs → .hyper_card/docs}/Shunkuntype_report.hiki +0 -0
- /data/{docs → .hyper_card/docs}/TouchTypespeedResult.png +0 -0
- /data/{docs → .hyper_card/docs}/TouchTypetrainingResult.png +0 -0
- /data/{docs → .hyper_card/docs}/TouchTypewhole_workResult.png +0 -0
- /data/{docs → .hyper_card/docs}/donkey_and_fujimoto.png +0 -0
- /data/{docs → .hyper_card/docs}/readme_en.hiki +0 -0
- /data/{docs → .hyper_card/docs}/readme_ja.hiki +0 -0
- /data/{docs → .hyper_card/docs}/res.png +0 -0
- /data/{docs → .hyper_card/docs}/shunkun_report.pdf +0 -0
- /data/{docs → .hyper_card/docs}/speed.png +0 -0
- /data/{docs → .hyper_card/docs}/work.png +0 -0
|
@@ -0,0 +1,849 @@
|
|
|
1
|
+
daddygongon: BDDで-hでヘルプを出すのをテストしましょう
|
|
2
|
+
|
|
3
|
+
Workspace: It looks like you may not have tests set up in this repository yet.
|
|
4
|
+
[object Object]
|
|
5
|
+
|
|
6
|
+
daddygongon: @workspace /tests Accept: "It looks like you may not have tests set up in this repository yet."
|
|
7
|
+
|
|
8
|
+
Workspace:
|
|
9
|
+
|
|
10
|
+
daddygongon: @workspace /setupTests
|
|
11
|
+
|
|
12
|
+
Workspace: This workspace is a Ruby gem project, as indicated by the presence of a `.gemspec`, Gemfile, and the lib and test directories. The test directory contains test files, suggesting a conventional Ruby testing setup.
|
|
13
|
+
|
|
14
|
+
For Ruby projects, the most common testing frameworks are:
|
|
15
|
+
|
|
16
|
+
- **Minitest**: Lightweight, comes bundled with Ruby, and is easy to use for small to medium projects.
|
|
17
|
+
- **RSpec**: Popular for its expressive syntax and powerful features, often used in larger or behavior-driven projects.
|
|
18
|
+
|
|
19
|
+
Choose **Minitest** for simplicity and speed, or **RSpec** for more expressive tests and advanced features.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Pick a testing framework
|
|
24
|
+
[object Object]
|
|
25
|
+
|
|
26
|
+
daddygongon: @workspace /setupTests minitest: "Pick a testing framework"
|
|
27
|
+
|
|
28
|
+
Workspace: To set up `minitest` in your Ruby workspace, you only need to ensure `minitest` is included in your Gemfile and add a basic test file if needed. Since you already have a test directory with `test_helper.rb` and `test_sample.rb`, let's add `minitest` to your Gemfile and provide a "hello world" test example.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Apply Changes
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Add the following line to your Gemfile if it's not already present:
|
|
37
|
+
```
|
|
38
|
+
gem 'minitest'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then, install the gem:
|
|
42
|
+
```sh
|
|
43
|
+
bundle install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
You can run your tests with:
|
|
47
|
+
```sh
|
|
48
|
+
ruby -Ilib:test test/test_hello_world.rb
|
|
49
|
+
```
|
|
50
|
+
Or to run all tests:
|
|
51
|
+
```sh
|
|
52
|
+
ruby -Ilib:test -e 'Dir.glob "./test/**/*_test.rb", &method(:require)'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You can also search for an extension to make tests easy to run in VS Code:
|
|
56
|
+
|
|
57
|
+
Search Extensions
|
|
58
|
+
|
|
59
|
+
daddygongon: @workspace /setupTests
|
|
60
|
+
|
|
61
|
+
Workspace: Your workspace is a Ruby gem project, and your active test file uses Minitest. Minitest is lightweight, fast, and comes bundled with Ruby, making it a popular choice for Ruby projects. Alternatively, RSpec is another widely used Ruby testing framework, known for its expressive syntax.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Pick a testing framework
|
|
66
|
+
[object Object]
|
|
67
|
+
|
|
68
|
+
daddygongon: @workspace /setupTests minitest: "Pick a testing framework"
|
|
69
|
+
|
|
70
|
+
Workspace: To set up `minitest` in your workspace, you should add the `minitest` gem to your Gemfile and ensure you have a basic test in the test directory. Since you already have `test_helper.rb` and some test files, let's just add a "hello world" test if it's not already present.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Apply Changes
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Add the following line to your Gemfile if it's not already present:
|
|
79
|
+
```
|
|
80
|
+
gem 'minitest'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Then, install the gem:
|
|
84
|
+
```sh
|
|
85
|
+
bundle install
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You can run your tests with:
|
|
89
|
+
```sh
|
|
90
|
+
bundle exec ruby -Ilib:test test/test_hello_world.rb
|
|
91
|
+
```
|
|
92
|
+
Or to run all tests:
|
|
93
|
+
```sh
|
|
94
|
+
bundle exec rake test
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
You can also search for an extension to make tests easy to run in VS Code:
|
|
98
|
+
|
|
99
|
+
Search Extensions
|
|
100
|
+
|
|
101
|
+
daddygongon: BDDでshunkuntype -hでヘルプを出すのをテストを書いて
|
|
102
|
+
|
|
103
|
+
GitHub Copilot: ````ruby
|
|
104
|
+
require 'minitest/autorun'
|
|
105
|
+
require 'open3'
|
|
106
|
+
|
|
107
|
+
class TestCLIHelp < Minitest::Test
|
|
108
|
+
def test_help_option
|
|
109
|
+
stdout, stderr, status = Open3.capture3('ruby bin/shunkuntype -h')
|
|
110
|
+
assert status.success?, "Process did not exit successfully"
|
|
111
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
````
|
|
115
|
+
|
|
116
|
+
daddygongon: #terminalSelection とのエラー
|
|
117
|
+
|
|
118
|
+
GitHub Copilot: Read terminal selection
|
|
119
|
+
|
|
120
|
+
`rake test`で失敗しているのは、test_cli_help.rbのこの行が原因の可能性が高いです。
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
stdout, stderr, status = Open3.capture3('ruby bin/shunkuntype -h')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- `bin/shunkuntype`がRubyスクリプトでなければ、`ruby bin/shunkuntype -h`は失敗します。
|
|
127
|
+
- また、`bin/shunkuntype`に実行権限がない場合や、`-h`でヘルプが出ない場合も失敗します。
|
|
128
|
+
|
|
129
|
+
**修正案:**
|
|
130
|
+
|
|
131
|
+
1. **shebangがある場合**
|
|
132
|
+
`bin/shunkuntype`の先頭に`#!/usr/bin/env ruby`があり、実行権限がある場合は、次のようにコマンドを修正してください。
|
|
133
|
+
|
|
134
|
+
````ruby
|
|
135
|
+
# filepath: /Users/bob/git_hub/shunkuntype/test/test_cli_help.rb
|
|
136
|
+
require 'minitest/autorun'
|
|
137
|
+
require 'open3'
|
|
138
|
+
|
|
139
|
+
class TestCLIHelp < Minitest::Test
|
|
140
|
+
def test_help_option
|
|
141
|
+
stdout, stderr, status = Open3.capture3('bin/shunkuntype -h')
|
|
142
|
+
assert status.success?, "Process did not exit successfully"
|
|
143
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
````
|
|
147
|
+
|
|
148
|
+
2. **shebangがない場合**
|
|
149
|
+
Rubyスクリプトなら、`ruby bin/shunkuntype -h`でOKですが、`bin/shunkuntype`の中身を確認してください。
|
|
150
|
+
|
|
151
|
+
3. **実行権限の付与**
|
|
152
|
+
ターミナルで以下を実行してください。
|
|
153
|
+
```sh
|
|
154
|
+
chmod +x bin/shunkuntype
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
4. **bin/shunkuntypeが存在しない場合**
|
|
158
|
+
ファイル名やパスを確認してください。
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
**まとめ**
|
|
163
|
+
- `bin/shunkuntype`のshebangと実行権限を確認
|
|
164
|
+
- テストのコマンドを`Open3.capture3('bin/shunkuntype -h')`に修正
|
|
165
|
+
|
|
166
|
+
これで解決しない場合は、`bin/shunkuntype`の内容やエラーメッセージ全文を教えてください。
|
|
167
|
+
|
|
168
|
+
daddygongon: ここはgemの環境です.そこで適切にBDDを実行するようにセットアップしてください.
|
|
169
|
+
|
|
170
|
+
GitHub Copilot: gem環境でCLIのヘルプ表示をBDD(振る舞い駆動開発)スタイルでテストするには、
|
|
171
|
+
`bin/shunkuntype`が実行可能であり、`bundle exec`を使って依存関係を解決するのが一般的です。
|
|
172
|
+
|
|
173
|
+
**修正版テスト例(minitest + Open3 + bundle exec):**
|
|
174
|
+
|
|
175
|
+
````ruby
|
|
176
|
+
require 'minitest/autorun'
|
|
177
|
+
require 'open3'
|
|
178
|
+
|
|
179
|
+
class TestCLIHelp < Minitest::Test
|
|
180
|
+
def test_help_option
|
|
181
|
+
# bundle execでgemの依存関係を解決して実行
|
|
182
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'bin/shunkuntype', '-h')
|
|
183
|
+
assert status.success?, "Process did not exit successfully"
|
|
184
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
````
|
|
188
|
+
|
|
189
|
+
### 補足
|
|
190
|
+
- `bin/shunkuntype`の先頭に`#!/usr/bin/env ruby`が必要です。
|
|
191
|
+
- 実行権限を付与してください:
|
|
192
|
+
```sh
|
|
193
|
+
chmod +x bin/shunkuntype
|
|
194
|
+
```
|
|
195
|
+
- テスト実行は以下でOKです:
|
|
196
|
+
```sh
|
|
197
|
+
bundle exec rake test
|
|
198
|
+
```
|
|
199
|
+
または
|
|
200
|
+
```sh
|
|
201
|
+
bundle exec ruby -Ilib:test test/test_cli_help.rb
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
これでgem環境でも正しくCLIのヘルプ表示テストができます。
|
|
205
|
+
|
|
206
|
+
daddygongon: TestCLIHelp
|
|
207
|
+
test_help_option FAIL (0.38s)
|
|
208
|
+
Process did not exit successfully
|
|
209
|
+
/Users/bob/git_hub/shunkuntype/test/test_cli_help.rb:8:in `test_help_option'
|
|
210
|
+
|
|
211
|
+
です.
|
|
212
|
+
|
|
213
|
+
GitHub Copilot: `Process did not exit successfully` というエラーは、`bin/shunkuntype -h` の実行が失敗していることを示しています。
|
|
214
|
+
よくある原因と対策は以下の通りです。
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
### 1. `bin/shunkuntype` の shebang と実行権限
|
|
219
|
+
|
|
220
|
+
- 先頭に `#!/usr/bin/env ruby` があるか確認してください。
|
|
221
|
+
- 実行権限を付与してください:
|
|
222
|
+
```sh
|
|
223
|
+
chmod +x bin/shunkuntype
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
### 2. `bin/shunkuntype` の中身が正しいか
|
|
229
|
+
|
|
230
|
+
- `-h` オプションでヘルプを出す処理が実装されているか確認してください。
|
|
231
|
+
- 例:
|
|
232
|
+
```ruby
|
|
233
|
+
#!/usr/bin/env ruby
|
|
234
|
+
if ARGV.include?('-h') || ARGV.include?('--help')
|
|
235
|
+
puts "Usage: shunkuntype [options]"
|
|
236
|
+
exit 0
|
|
237
|
+
end
|
|
238
|
+
# ...他の処理...
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### 3. テストでエラー内容を出力して原因を特定
|
|
244
|
+
|
|
245
|
+
エラー内容を確認するため、テストを以下のように修正してください。
|
|
246
|
+
|
|
247
|
+
````ruby
|
|
248
|
+
require 'minitest/autorun'
|
|
249
|
+
require 'open3'
|
|
250
|
+
|
|
251
|
+
class TestCLIHelp < Minitest::Test
|
|
252
|
+
def test_help_option
|
|
253
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'bin/shunkuntype', '-h')
|
|
254
|
+
unless status.success?
|
|
255
|
+
puts "STDOUT:\n#{stdout}"
|
|
256
|
+
puts "STDERR:\n#{stderr}"
|
|
257
|
+
end
|
|
258
|
+
assert status.success?, "Process did not exit successfully"
|
|
259
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
````
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
これで再度テストを実行し、STDOUT/STDERRの内容を確認してください。
|
|
267
|
+
その内容を教えていただければ、さらに具体的なアドバイスが可能です。
|
|
268
|
+
|
|
269
|
+
daddygongon: あります
|
|
270
|
+
|
|
271
|
+
GitHub Copilot: ありがとうございます。
|
|
272
|
+
shunkuntype がエントリポイントですが、テストでは shunkuntype を実行しています。
|
|
273
|
+
RubyGemsのgem構成では、**shunkuntype は shunkuntype へのラッパー**として自動生成されることが多いですが、
|
|
274
|
+
このプロジェクトでは shunkuntype が本体です。
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 修正方法
|
|
279
|
+
|
|
280
|
+
### 1. テストの実行対象を shunkuntype に変更
|
|
281
|
+
|
|
282
|
+
````ruby
|
|
283
|
+
require 'minitest/autorun'
|
|
284
|
+
require 'open3'
|
|
285
|
+
|
|
286
|
+
class TestCLIHelp < Minitest::Test
|
|
287
|
+
def test_help_option
|
|
288
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-h')
|
|
289
|
+
unless status.success?
|
|
290
|
+
puts "STDOUT:\n#{stdout}"
|
|
291
|
+
puts "STDERR:\n#{stderr}"
|
|
292
|
+
end
|
|
293
|
+
assert status.success?, "Process did not exit successfully"
|
|
294
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
````
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
### 2. 実行権限を付与
|
|
302
|
+
|
|
303
|
+
```sh
|
|
304
|
+
chmod +x exe/shunkuntype
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
### 3. `Command.run(ARGV)` の実装確認
|
|
310
|
+
|
|
311
|
+
- `Command.run(ARGV)` で `-h` オプション時にヘルプを表示し、正常終了(`exit 0`)するようになっているか確認してください。
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
これでテストが通るはずです。
|
|
316
|
+
もしまだ失敗する場合は、STDOUT/STDERRの内容を教えてください。
|
|
317
|
+
|
|
318
|
+
daddygongon: #file:shunkuntype.rb:33-34 なんで,-hをhelpに割り当てるように変更しましょう.--historyは何か適当な英単語に置き換えてください.
|
|
319
|
+
|
|
320
|
+
GitHub Copilot: ````ruby
|
|
321
|
+
# ...existing code...
|
|
322
|
+
opt.on('-v', '--version','show program Version.') { |v|
|
|
323
|
+
opt.version = Shunkuntype::VERSION
|
|
324
|
+
puts opt.ver
|
|
325
|
+
}
|
|
326
|
+
opt.on('-c', '--check','Check speed') {|v| SpeedCheck.new }
|
|
327
|
+
opt.on('-d', '--drill [VAL]','one minute Drill [VAL]', Integer) {|v| Training.new(v) }
|
|
328
|
+
opt.on('-h', '--help','show help message') { puts opt; exit }
|
|
329
|
+
opt.on('--history','view training History') {|v| FinishCheck.new }
|
|
330
|
+
opt.on('--reset','reset training data') { |v| reset_data()}
|
|
331
|
+
# ...existing code...
|
|
332
|
+
````
|
|
333
|
+
|
|
334
|
+
※ `--history` はそのままですが、例えば `--record` などに変更したい場合は以下のようにしてください。
|
|
335
|
+
|
|
336
|
+
````ruby
|
|
337
|
+
opt.on('--record','view training History') {|v| FinishCheck.new }
|
|
338
|
+
````
|
|
339
|
+
|
|
340
|
+
Similar code found with 1 license type
|
|
341
|
+
|
|
342
|
+
daddygongon: logにしましょう
|
|
343
|
+
|
|
344
|
+
GitHub Copilot: ````ruby
|
|
345
|
+
opt.on('-h', '--help','show help message') { puts opt; exit }
|
|
346
|
+
opt.on('--log','view training History') {|v| FinishCheck.new }
|
|
347
|
+
````
|
|
348
|
+
|
|
349
|
+
daddygongon: -dでdrillが動くかテストできますか?
|
|
350
|
+
|
|
351
|
+
GitHub Copilot: はい、`-d`オプションで`Training`が動くかどうかもCLIテストできます。
|
|
352
|
+
以下のようなテストを追加してください。
|
|
353
|
+
|
|
354
|
+
````ruby
|
|
355
|
+
require 'minitest/autorun'
|
|
356
|
+
require 'open3'
|
|
357
|
+
|
|
358
|
+
class TestCLIDrill < Minitest::Test
|
|
359
|
+
def test_drill_option
|
|
360
|
+
# -d 1 でテスト(1は適当な引数。必要に応じて変更)
|
|
361
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-d', '1')
|
|
362
|
+
unless status.success?
|
|
363
|
+
puts "STDOUT:\n#{stdout}"
|
|
364
|
+
puts "STDERR:\n#{stderr}"
|
|
365
|
+
end
|
|
366
|
+
# Trainingクラスの出力や挙動に応じて適切なアサートに変更してください
|
|
367
|
+
assert_match(/STEP-1\.txt|keyboard|Repeat above sentences|Shunkuntype says 'Hello world'/i, stdout + stderr)
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
````
|
|
371
|
+
|
|
372
|
+
- `-d 1` の `1` はテスト用の値です。
|
|
373
|
+
- `assert_match` のパターンは `Training` の出力内容に合わせて調整してください。
|
|
374
|
+
|
|
375
|
+
このテストで`-d`オプションが正しく動作するか確認できます。
|
|
376
|
+
|
|
377
|
+
daddygongon: -cでcheck speedが動くかのテストを追加
|
|
378
|
+
|
|
379
|
+
GitHub Copilot: ````ruby
|
|
380
|
+
require 'minitest/autorun'
|
|
381
|
+
require 'open3'
|
|
382
|
+
|
|
383
|
+
class TestCLICheck < Minitest::Test
|
|
384
|
+
def test_check_option
|
|
385
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-c')
|
|
386
|
+
unless status.success?
|
|
387
|
+
puts "STDOUT:\n#{stdout}"
|
|
388
|
+
puts "STDERR:\n#{stderr}"
|
|
389
|
+
end
|
|
390
|
+
# SpeedCheckクラスの出力内容に応じてパターンを調整してください
|
|
391
|
+
assert_match(/speed|check|Shunkuntype says 'Hello world'/i, stdout + stderr)
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
````
|
|
395
|
+
|
|
396
|
+
daddygongon: TestCLIDrill
|
|
397
|
+
STDOUT:
|
|
398
|
+
Shunkuntype says 'Hello world'.
|
|
399
|
+
"STEP-1.txt"
|
|
400
|
+
q \ w \ e \ r t \ y u \ i \ o \ p
|
|
401
|
+
a \ s \ d \ f g \ h j \ k \ l \ ; enter
|
|
402
|
+
sh z \ x \ c \ v b \ n m \ , \ . \ shift
|
|
403
|
+
frf ded juj kik
|
|
404
|
+
|
|
405
|
+
Repeat above sentences. Type return-key to start.frf ded juj kik
|
|
406
|
+
STDERR:
|
|
407
|
+
bundler: failed to load command: exe/shunkuntype (exe/shunkuntype)
|
|
408
|
+
/Users/bob/git_hub/shunkuntype/lib/shunkuntype/training.rb:73:in `block in type_loop': undefined method `chomp' for nil:NilClass (NoMethodError)
|
|
409
|
+
|
|
410
|
+
line=STDIN.gets.chomp
|
|
411
|
+
^^^^^^
|
|
412
|
+
from /Users/bob/git_hub/shunkuntype/lib/shunkuntype/training.rb:69:in `each'
|
|
413
|
+
と出ます.
|
|
414
|
+
|
|
415
|
+
GitHub Copilot: このエラーは、テスト実行時に `STDIN.gets` が `nil` を返し、`chomp` を呼んでいるためです。
|
|
416
|
+
CIや自動テスト環境では標準入力がないため、`gets` は `nil` を返します。
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## 解決方法
|
|
421
|
+
|
|
422
|
+
### 1. テスト時は標準入力をモックする
|
|
423
|
+
|
|
424
|
+
テストで `Open3.capture3` の第4引数(`stdin_data`)を使い、入力を与えることで回避できます。
|
|
425
|
+
|
|
426
|
+
````ruby
|
|
427
|
+
class TestCLIDrill < Minitest::Test
|
|
428
|
+
def test_drill_option
|
|
429
|
+
# "frf ded juj kik\n" など、必要なだけ改行を入れて入力を模倣
|
|
430
|
+
input = "\n" * 3
|
|
431
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-d', '1', stdin_data: input)
|
|
432
|
+
unless status.success?
|
|
433
|
+
puts "STDOUT:\n#{stdout}"
|
|
434
|
+
puts "STDERR:\n#{stderr}"
|
|
435
|
+
end
|
|
436
|
+
assert_match(/STEP-1\.txt|keyboard|Repeat above sentences|Shunkuntype says 'Hello world'/i, stdout + stderr)
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
````
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
### 2. 本体側で `nil` チェックを入れる(推奨)
|
|
444
|
+
|
|
445
|
+
`training.rb` の該当箇所を次のように修正してください。
|
|
446
|
+
|
|
447
|
+
````ruby
|
|
448
|
+
line = STDIN.gets
|
|
449
|
+
break if line.nil?
|
|
450
|
+
line = line.chomp
|
|
451
|
+
counter(sentence, line)
|
|
452
|
+
````
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
### どちらも行うとより堅牢です。
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
これでテストが失敗せず、`-d`オプションの自動テストが可能になります。
|
|
461
|
+
|
|
462
|
+
daddygongon: TestCLIDrill
|
|
463
|
+
STDOUT:
|
|
464
|
+
Shunkuntype says 'Hello world'.
|
|
465
|
+
"STEP-1.txt"
|
|
466
|
+
q \ w \ e \ r t \ y u \ i \ o \ p
|
|
467
|
+
a \ s \ d \ f g \ h j \ k \ l \ ; enter
|
|
468
|
+
sh z \ x \ c \ v b \ n m \ , \ . \ shift
|
|
469
|
+
frf ded juj kik
|
|
470
|
+
|
|
471
|
+
Repeat above sentences. Type return-key to start.frf ded juj kik
|
|
472
|
+
STDERR:
|
|
473
|
+
bundler: failed to load command: exe/shunkuntype (exe/shunkuntype)
|
|
474
|
+
/Users/bob/git_hub/shunkuntype/lib/shunkuntype/training.rb:73:in `block in type_loop': undefined method `chomp' for nil:NilClass (NoMethodError)
|
|
475
|
+
|
|
476
|
+
line=STDIN.gets.chomp
|
|
477
|
+
^^^^^^
|
|
478
|
+
from /Users/bob/git_hub/shunkuntype/lib/shunkuntype/training.rb:69:in `each'とエラーは出ますが,testは全部成功しています.どこを改修しましょう.
|
|
479
|
+
|
|
480
|
+
GitHub Copilot: このエラーは、`STDIN.gets` が `nil` を返したときに `chomp` を呼んでいるため発生しています。
|
|
481
|
+
テストは成功していますが、**本番環境や他の自動化環境でも同じエラーが出る可能性があるため、堅牢性のために修正すべきです**。
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## 改修ポイント
|
|
486
|
+
|
|
487
|
+
training.rb の
|
|
488
|
+
`line = STDIN.gets.chomp`
|
|
489
|
+
を、**nilチェックを入れて安全に**しましょう。
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
### 修正版
|
|
494
|
+
|
|
495
|
+
````ruby
|
|
496
|
+
# ...existing code...
|
|
497
|
+
line = STDIN.gets
|
|
498
|
+
break if line.nil?
|
|
499
|
+
line = line.chomp
|
|
500
|
+
# ...existing code...
|
|
501
|
+
````
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
### 解説
|
|
506
|
+
|
|
507
|
+
- `STDIN.gets` が `nil` の場合は `break` してループを抜けることで、`chomp` のエラーを防ぎます。
|
|
508
|
+
- これでテスト時も本番時も安全です。
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
**この修正を加えれば、エラーは出なくなります。**
|
|
513
|
+
|
|
514
|
+
daddygongon: #terminalSelection の通りだいぶエラーが出ています.実行コードを修正しましょうか?
|
|
515
|
+
|
|
516
|
+
GitHub Copilot: Read terminal selection
|
|
517
|
+
|
|
518
|
+
はい、修正が必要です。
|
|
519
|
+
主な問題は training.rb の `init_proc` メソッドで `break` を使っていることです。
|
|
520
|
+
`break` はメソッド内で直接使うと `Invalid break (SyntaxError)` となります。
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## 修正案
|
|
525
|
+
|
|
526
|
+
### 1. `init_proc` の `break` を `return` に変更
|
|
527
|
+
|
|
528
|
+
````ruby
|
|
529
|
+
def init_proc(file_name)
|
|
530
|
+
data=File.readlines(file_name)
|
|
531
|
+
data.each{|word| print word }
|
|
532
|
+
print "\nRepeat above sentences. Type return-key to start."
|
|
533
|
+
line=STDIN.gets
|
|
534
|
+
if line.nil?
|
|
535
|
+
# 入力がなければnilを返して呼び出し元で処理
|
|
536
|
+
return nil, data
|
|
537
|
+
end
|
|
538
|
+
line = line.chomp
|
|
539
|
+
start_time = Time.now
|
|
540
|
+
return start_time, data
|
|
541
|
+
end
|
|
542
|
+
````
|
|
543
|
+
|
|
544
|
+
### 2. `initialize` で `start_time` が `nil` の場合は早期リターン
|
|
545
|
+
|
|
546
|
+
````ruby
|
|
547
|
+
start_time, data = init_proc(file_name)
|
|
548
|
+
return if start_time.nil?
|
|
549
|
+
````
|
|
550
|
+
|
|
551
|
+
### 3. `type_loop` でも `STDIN.gets` のnilチェック
|
|
552
|
+
|
|
553
|
+
````ruby
|
|
554
|
+
def type_loop(data)
|
|
555
|
+
data.each do |sentence|
|
|
556
|
+
break if @time_flag == false
|
|
557
|
+
puts sentence
|
|
558
|
+
line = STDIN.gets
|
|
559
|
+
break if line.nil?
|
|
560
|
+
line = line.chomp
|
|
561
|
+
counter(sentence, line)
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
````
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
## まとめ
|
|
569
|
+
|
|
570
|
+
- `break` の代わりに `return` を使う
|
|
571
|
+
- `STDIN.gets` のnilチェックを徹底する
|
|
572
|
+
|
|
573
|
+
これでSyntaxErrorやNoMethodErrorが解消し、テストも安定して動作します。
|
|
574
|
+
|
|
575
|
+
daddygongon: #terminalSelection の通りfailuresはなくなりましたが,実行コードからのエラーが気になります.実行コードを修正してください.
|
|
576
|
+
|
|
577
|
+
GitHub Copilot: Read terminal selection
|
|
578
|
+
|
|
579
|
+
`failures` はありませんが、**実行時に `NoMethodError: undefined method 'chomp' for nil:NilClass`** が出ているのは、
|
|
580
|
+
`STDIN.gets`(または `$stdin.gets`)が `nil` を返した場合に `chomp` を呼んでいるためです。
|
|
581
|
+
|
|
582
|
+
training.rb だけでなく、**`speed.rb` など他の箇所でも同じ問題**が起きています。
|
|
583
|
+
|
|
584
|
+
---
|
|
585
|
+
|
|
586
|
+
## 1. training.rb の修正(すでにOK)
|
|
587
|
+
|
|
588
|
+
あなたの training.rb はすでに `nil` チェックが入っています。
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
## 2. `speed.rb` の修正
|
|
593
|
+
|
|
594
|
+
`speed.rb` の `line = $stdin.gets.chomp` を
|
|
595
|
+
**`line = $stdin.gets` → `break if line.nil?` → `line = line.chomp`**
|
|
596
|
+
のように修正してください。
|
|
597
|
+
|
|
598
|
+
### 例(`speed.rb` の該当箇所)
|
|
599
|
+
|
|
600
|
+
````ruby
|
|
601
|
+
# ...existing code...
|
|
602
|
+
line = $stdin.gets
|
|
603
|
+
break if line.nil?
|
|
604
|
+
line = line.chomp
|
|
605
|
+
# ...existing code...
|
|
606
|
+
````
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
610
|
+
## 3. 他にも `$stdin.gets.chomp` や `STDIN.gets.chomp` を使っている箇所があれば、同様に修正してください
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
## まとめ
|
|
615
|
+
|
|
616
|
+
- **`gets` の戻り値が `nil` の場合は `break` する**(`chomp` を呼ばない)
|
|
617
|
+
- すべての `gets.chomp` をこのパターンに修正
|
|
618
|
+
|
|
619
|
+
---
|
|
620
|
+
|
|
621
|
+
### 参考:修正例
|
|
622
|
+
|
|
623
|
+
````ruby
|
|
624
|
+
line = $stdin.gets
|
|
625
|
+
break if line.nil?
|
|
626
|
+
line = line.chomp
|
|
627
|
+
````
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
これで実行時のエラーも解消し、テストも安定します。
|
|
632
|
+
|
|
633
|
+
daddygongon: #terminalSelection のようなエラーが出ます.
|
|
634
|
+
|
|
635
|
+
GitHub Copilot: Read terminal selection
|
|
636
|
+
|
|
637
|
+
`#terminalSelection` のエラーの主因は、**speed.rb の `break` の使い方が不正**なためです。
|
|
638
|
+
|
|
639
|
+
Rubyでは、メソッド本体で `break` を使うと `Invalid break (SyntaxError)` になります。
|
|
640
|
+
`break` はブロックやループの中でのみ使えます。
|
|
641
|
+
|
|
642
|
+
---
|
|
643
|
+
|
|
644
|
+
## 修正版(speed.rb)
|
|
645
|
+
|
|
646
|
+
### `exec_speed_check` の該当箇所を修正
|
|
647
|
+
|
|
648
|
+
```ruby
|
|
649
|
+
def exec_speed_check(data)
|
|
650
|
+
print "\n\n"+number.to_s+" words should be cleared."
|
|
651
|
+
print "\nType return-key to start."
|
|
652
|
+
p ''
|
|
653
|
+
line = $stdin.gets
|
|
654
|
+
return [nil, nil, nil] if line.nil? # breakの代わりにreturnで早期リターン
|
|
655
|
+
line = line.chomp
|
|
656
|
+
|
|
657
|
+
t0 = Time.now
|
|
658
|
+
count = 0
|
|
659
|
+
@number.times do |i|
|
|
660
|
+
print_keyboard()
|
|
661
|
+
puts (i+1).to_s
|
|
662
|
+
word = data[i]
|
|
663
|
+
count += word.length
|
|
664
|
+
while line != word do
|
|
665
|
+
puts word
|
|
666
|
+
p ''
|
|
667
|
+
line = $stdin.gets
|
|
668
|
+
return [t0, Time.now, count] if line.nil? # ここもnilチェック
|
|
669
|
+
line = line.chomp
|
|
670
|
+
end
|
|
671
|
+
end
|
|
672
|
+
t1 = Time.now
|
|
673
|
+
return t0, t1, count
|
|
674
|
+
end
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
---
|
|
678
|
+
|
|
679
|
+
## ポイント
|
|
680
|
+
|
|
681
|
+
- メソッド本体で `break` は使えません。**`return` で抜ける**ように修正してください。
|
|
682
|
+
- `$stdin.gets` の戻り値が `nil` の場合は `return` で抜けるようにします。
|
|
683
|
+
- ループ内の `line = $stdin.gets.chomp` も、`line = $stdin.gets` → `return if line.nil?` → `line = line.chomp` の順で安全に。
|
|
684
|
+
|
|
685
|
+
---
|
|
686
|
+
|
|
687
|
+
この修正で `Invalid break (SyntaxError)` は解消し、テストも正常に動作します。
|
|
688
|
+
|
|
689
|
+
daddygongon: #terminalSelection のエラーが出ています.
|
|
690
|
+
|
|
691
|
+
GitHub Copilot: Read terminal selection
|
|
692
|
+
|
|
693
|
+
エラーの本質はここです:
|
|
694
|
+
|
|
695
|
+
```
|
|
696
|
+
/Users/bob/git_hub/shunkuntype/lib/shunkuntype/speed.rb:78:in `keep_record': undefined method `-' for nil:NilClass (NoMethodError)
|
|
697
|
+
statement << (t1-t0).to_s+","
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
これは、`exec_speed_check` で `t0` または `t1` が `nil` のまま `keep_record` に渡されているためです。
|
|
701
|
+
(テスト時などで `$stdin.gets` が `nil` になった場合に発生)
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
## 修正方法
|
|
706
|
+
|
|
707
|
+
### 1. `keep_record` の前に `t0` や `t1` が `nil` なら記録処理をスキップ
|
|
708
|
+
|
|
709
|
+
````ruby
|
|
710
|
+
def initialize
|
|
711
|
+
@number = 20 #default 20
|
|
712
|
+
@period = 60
|
|
713
|
+
check_data_files
|
|
714
|
+
data = mk_random_words
|
|
715
|
+
t0, t1, count = exec_speed_check(data)
|
|
716
|
+
# ここでnilチェック
|
|
717
|
+
if t0.nil? || t1.nil?
|
|
718
|
+
puts "Speed check was interrupted or no input was given."
|
|
719
|
+
return
|
|
720
|
+
end
|
|
721
|
+
keep_record(t0, t1, count)
|
|
722
|
+
end
|
|
723
|
+
````
|
|
724
|
+
|
|
725
|
+
---
|
|
726
|
+
|
|
727
|
+
### 2. `keep_record` の中でnilチェック(念のため)
|
|
728
|
+
|
|
729
|
+
````ruby
|
|
730
|
+
def keep_record(t0, t1, count)
|
|
731
|
+
return if t0.nil? || t1.nil?
|
|
732
|
+
statement = t0.to_s + ","
|
|
733
|
+
statement << @number.to_s + ","
|
|
734
|
+
statement << (t1 - t0).to_s + ","
|
|
735
|
+
icount = @period / (t1 - t0) * count
|
|
736
|
+
statement << icount.to_s + "\n"
|
|
737
|
+
data_file = open(Shunkuntype::SPEED_FILE, "a+")
|
|
738
|
+
data_file << statement
|
|
739
|
+
p statement
|
|
740
|
+
|
|
741
|
+
printf("%5.3f sec\n", Time.now - t0)
|
|
742
|
+
printf("%4d characters.\n", icount)
|
|
743
|
+
end
|
|
744
|
+
````
|
|
745
|
+
|
|
746
|
+
---
|
|
747
|
+
|
|
748
|
+
## まとめ
|
|
749
|
+
|
|
750
|
+
- `t0` または `t1` が `nil` の場合は `keep_record` を呼ばない
|
|
751
|
+
- これで `NoMethodError` は解消します
|
|
752
|
+
|
|
753
|
+
---
|
|
754
|
+
|
|
755
|
+
**この修正で #terminalSelection のエラーは出なくなります。**
|
|
756
|
+
|
|
757
|
+
Similar code found with 1 license type
|
|
758
|
+
|
|
759
|
+
daddygongon: エラーがなくなりました.ありがとう.
|
|
760
|
+
|
|
761
|
+
GitHub Copilot: どういたしまして!
|
|
762
|
+
また何かあればいつでもご相談ください。
|
|
763
|
+
|
|
764
|
+
daddygongon: このファイルにあるBDDテストをまとめましょう.さらに,ファイル名を変更しましょう.
|
|
765
|
+
|
|
766
|
+
GitHub Copilot: ### まとめ
|
|
767
|
+
|
|
768
|
+
このファイルには、shunkuntype CLIの主要な3つの機能についてBDDスタイルでテストが書かれています。
|
|
769
|
+
|
|
770
|
+
- **ヘルプ表示(-h)**
|
|
771
|
+
`shunkuntype -h` でヘルプメッセージが表示されることをテスト
|
|
772
|
+
|
|
773
|
+
- **ドリル実行(-d)**
|
|
774
|
+
`shunkuntype -d 1` でドリル機能が動作し、キーボード配列や指示文が出力されることをテスト
|
|
775
|
+
|
|
776
|
+
- **スピードチェック(-c)**
|
|
777
|
+
`shunkuntype -c` でスピードチェック機能が動作し、関連する出力がされることをテスト
|
|
778
|
+
|
|
779
|
+
各テストは `Open3.capture3` でCLIを実行し、標準出力・標準エラー・終了ステータスを検証しています。
|
|
780
|
+
|
|
781
|
+
---
|
|
782
|
+
|
|
783
|
+
### ファイル名の提案
|
|
784
|
+
|
|
785
|
+
より分かりやすくするため、
|
|
786
|
+
**test_cli_help.rb → `test_cli_bdd.rb`**
|
|
787
|
+
などに変更するのが良いでしょう。
|
|
788
|
+
|
|
789
|
+
---
|
|
790
|
+
|
|
791
|
+
#### 変更例
|
|
792
|
+
|
|
793
|
+
```
|
|
794
|
+
mv test/test_cli_help.rb test/test_cli_bdd.rb
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
---
|
|
798
|
+
|
|
799
|
+
#### ファイル先頭のコメント例
|
|
800
|
+
|
|
801
|
+
````ruby
|
|
802
|
+
# BDD tests for shunkuntype CLI:
|
|
803
|
+
# - Help message (-h)
|
|
804
|
+
# - Drill mode (-d)
|
|
805
|
+
# - Speed check (-c)
|
|
806
|
+
````
|
|
807
|
+
|
|
808
|
+
daddygongon: TestCLIにclassをまとめて,defを並列するように変更
|
|
809
|
+
|
|
810
|
+
GitHub Copilot: ````ruby
|
|
811
|
+
require 'minitest/autorun'
|
|
812
|
+
require 'open3'
|
|
813
|
+
|
|
814
|
+
# BDD tests for shunkuntype CLI:
|
|
815
|
+
# - Help message (-h)
|
|
816
|
+
# - Drill mode (-d)
|
|
817
|
+
# - Speed check (-c)
|
|
818
|
+
|
|
819
|
+
class TestCLI < Minitest::Test
|
|
820
|
+
def test_help_option
|
|
821
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-h')
|
|
822
|
+
unless status.success?
|
|
823
|
+
puts "STDOUT:\n#{stdout}"
|
|
824
|
+
puts "STDERR:\n#{stderr}"
|
|
825
|
+
end
|
|
826
|
+
assert status.success?, "Process did not exit successfully"
|
|
827
|
+
assert_match(/Usage|ヘルプ|help/i, stdout + stderr, "Help message not found in output")
|
|
828
|
+
end
|
|
829
|
+
|
|
830
|
+
def test_drill_option
|
|
831
|
+
input = "\n" * 3
|
|
832
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-d', '1', stdin_data: input)
|
|
833
|
+
unless status.success?
|
|
834
|
+
puts "STDOUT:\n#{stdout}"
|
|
835
|
+
puts "STDERR:\n#{stderr}"
|
|
836
|
+
end
|
|
837
|
+
assert_match(/STEP-1\.txt|keyboard|Repeat above sentences|Shunkuntype says 'Hello world'/i, stdout + stderr)
|
|
838
|
+
end
|
|
839
|
+
|
|
840
|
+
def test_check_option
|
|
841
|
+
stdout, stderr, status = Open3.capture3('bundle', 'exec', 'exe/shunkuntype', '-c')
|
|
842
|
+
unless status.success?
|
|
843
|
+
puts "STDOUT:\n#{stdout}"
|
|
844
|
+
puts "STDERR:\n#{stderr}"
|
|
845
|
+
end
|
|
846
|
+
assert_match(/speed|check|Shunkuntype says 'Hello world'/i, stdout + stderr)
|
|
847
|
+
end
|
|
848
|
+
end
|
|
849
|
+
````
|