Skip to content

Commit c9997ad

Browse files
committed
refactor: RSpecからMinitestへ移行してテストを高速化・簡素化
- RSpecは1つのCSVテストには過剰(オーバースペック) - MinitestはRuby標準ライブラリで追加gem不要 - より高速な実行とシンプルな記述 - テスト内容を拡充(ヘッダー確認、空文字チェック、SSH鍵フォーマット検証) 追加したRakeタスク: - rake test (rake t) - 全テスト実行 - rake test_csv - CSV検証のみ - rake test_verbose - 詳細出力モード パフォーマンス向上: - 外部依存を削減 - 起動時間の短縮 - 学習コストの低減
1 parent bf91206 commit c9997ad

File tree

5 files changed

+81
-33
lines changed

5 files changed

+81
-33
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
33

44
gem 'httpclient'
55
gem 'rake'
6-
gem 'rspec'
76

87
# Add bundled gems to fix errors/warnings
98
gem 'csv'

Gemfile.lock

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,12 @@ GEM
33
specs:
44
base64 (0.3.0)
55
csv (3.3.4)
6-
diff-lcs (1.6.2)
76
dotenv (3.1.8)
87
httpclient (2.9.0)
98
mutex_m
109
mutex_m (0.3.0)
1110
net-ssh (7.3.0)
1211
rake (13.2.1)
13-
rspec (3.13.0)
14-
rspec-core (~> 3.13.0)
15-
rspec-expectations (~> 3.13.0)
16-
rspec-mocks (~> 3.13.0)
17-
rspec-core (3.13.3)
18-
rspec-support (~> 3.13.0)
19-
rspec-expectations (3.13.4)
20-
diff-lcs (>= 1.2.0, < 2.0)
21-
rspec-support (~> 3.13.0)
22-
rspec-mocks (3.13.4)
23-
diff-lcs (>= 1.2.0, < 2.0)
24-
rspec-support (~> 3.13.0)
25-
rspec-support (3.13.3)
2612

2713
PLATFORMS
2814
ruby
@@ -34,7 +20,6 @@ DEPENDENCIES
3420
httpclient
3521
net-ssh
3622
rake
37-
rspec
3823

3924
BUNDLED WITH
4025
2.6.9

Rakefile

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
1-
require "rspec/core/rake_task"
1+
require 'rake/testtask'
22
require 'fileutils'
33
require 'json'
44
require 'time'
55
require 'net/http'
66
require 'uri'
77
require 'csv'
88

9-
RSpec::Core::RakeTask.new(:spec)
9+
# Minitestタスクの定義
10+
Rake::TestTask.new(:test) do |t|
11+
t.libs << "test"
12+
t.test_files = FileList['test/*_test.rb']
13+
t.verbose = true
14+
end
15+
16+
# 短縮エイリアス
17+
task :t => :test
18+
19+
# テストの詳細情報を表示
20+
desc "Run all tests with detailed output"
21+
task :test_verbose do
22+
ENV['TESTOPTS'] = '--verbose'
23+
Rake::Task[:test].invoke
24+
end
25+
26+
# CSV検証のみ実行
27+
desc "Validate CSV format only"
28+
task :test_csv do
29+
ruby "test/csv_test.rb"
30+
end
1031

11-
task :test => :spec
32+
task :default => :test
1233

1334
# Rakeの高度な機能を活用した改善
1435
# - 依存関係の明確化

spec/csv_spec.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/csv_test.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require 'minitest/autorun'
2+
require 'csv'
3+
4+
class CSVTest < Minitest::Test
5+
INSTANCE_CSV = "servers.csv".freeze
6+
7+
def test_csv_has_required_headers
8+
csv = CSV.read(INSTANCE_CSV, headers: true)
9+
10+
# ヘッダーの存在確認
11+
assert csv.headers.include?('name'), "CSV must have 'name' header"
12+
assert csv.headers.include?('description'), "CSV must have 'description' header"
13+
assert csv.headers.include?('pubkey'), "CSV must have 'pubkey' header"
14+
assert csv.headers.include?('branch'), "CSV must have 'branch' header"
15+
end
16+
17+
def test_csv_fields_are_not_nil
18+
CSV.read(INSTANCE_CSV, headers: true).each_with_index do |line, index|
19+
# 各行の必須フィールドが存在することを確認
20+
refute_nil line['name'], "Row #{index + 1}: name must not be nil"
21+
refute_nil line['description'], "Row #{index + 1}: description must not be nil"
22+
refute_nil line['pubkey'], "Row #{index + 1}: pubkey must not be nil"
23+
refute_nil line['branch'], "Row #{index + 1}: branch must not be nil"
24+
end
25+
end
26+
27+
def test_csv_fields_are_not_empty
28+
CSV.read(INSTANCE_CSV, headers: true).each_with_index do |line, index|
29+
# 各フィールドが空文字でないことを確認
30+
refute_empty line['name'].to_s.strip, "Row #{index + 1}: name must not be empty"
31+
refute_empty line['description'].to_s.strip, "Row #{index + 1}: description must not be empty"
32+
refute_empty line['pubkey'].to_s.strip, "Row #{index + 1}: pubkey must not be empty"
33+
refute_empty line['branch'].to_s.strip, "Row #{index + 1}: branch must not be empty"
34+
end
35+
end
36+
37+
def test_pubkey_format
38+
CSV.read(INSTANCE_CSV, headers: true).each_with_index do |line, index|
39+
pubkey = line['pubkey']
40+
next if pubkey.nil? || pubkey.empty?
41+
42+
# SSH公開鍵の基本的なフォーマットチェック
43+
assert_match(/^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256)/, pubkey,
44+
"Row #{index + 1}: pubkey must be a valid SSH public key")
45+
end
46+
end
47+
48+
def test_branch_is_not_empty
49+
CSV.read(INSTANCE_CSV, headers: true).each_with_index do |line, index|
50+
branch = line['branch']
51+
52+
# branchフィールドが空でないことを確認(各道場固有のブランチ名を許可)
53+
refute_nil branch, "Row #{index + 1}: branch must not be nil"
54+
refute_empty branch.to_s.strip, "Row #{index + 1}: branch must not be empty"
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)