ワンクリックで
rspec-behavior-test
古典派テスト(振る舞いテスト)の方針に基づいてRSpecテストを作成する。「テストを書いて」「振る舞いテストを書いて」「specを追加して」などのリクエストで起動する。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
古典派テスト(振る舞いテスト)の方針に基づいてRSpecテストを作成する。「テストを書いて」「振る舞いテストを書いて」「specを追加して」などのリクエストで起動する。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
サブモジュール(front, back, mobile)を各デフォルトブランチに切り替えてpullし、最新状態にする。`/sync-default`や「デフォルトブランチに戻して」「最新に同期して」などのリクエストで起動する。
指定したissue番号でサブモジュールに作業ブランチを作成する。`/checkout-branch 116`のように呼び出す。issue情報からブランチ名を自動生成し、最新のベースブランチから分岐させる。
現在のブランチからGitHub PRを作成する。差分・コミット履歴を分析し、テンプレートに沿ったタイトルとdescriptionを生成する。「PRを作成して」「プルリク作って」などのリクエストで起動する。
現在の作業差分を分析し、適切な粒度でコミットを分割し、自動で add / commit / push まで実行する。「コミットして」「コミットを分けて」「差分を整理して」などのリクエストで起動する。
App Store Connect / Google Playの「このバージョンの最新情報」リリースノートを自動生成する。mobile/app.jsonのexpo.versionを現在バージョンとし、前回バージョンとのGit差分からユーザー向けリリースノートを作成する。「リリースノートを作成して」「ストアの更新情報を書いて」「app-release-notes」などで起動する。
buzzbaseリポジトリ(ippei-shimizu/buzzbase)にGitHub issueを作成し、GitHub Projects "BUZZ BASE"に自動追加する。`/create-issue バグの説明`のように呼び出す。
| name | rspec-behavior-test |
| description | 古典派テスト(振る舞いテスト)の方針に基づいてRSpecテストを作成する。「テストを書いて」「振る舞いテストを書いて」「specを追加して」などのリクエストで起動する。 |
古典派テスト(Classical Testing)の方針に基づき、「振る舞い」を検証するRSpecテストを作成する。
「何をするか(What)」をテストし、「どう実装しているか(How)」はテストしない。
allow(Model).to receive(:method) で内部メソッドをモックするexpect(obj).to have_received(:method) で呼び出し検証するsend で直接テストするback/ サブモジュール(Rails API)
spec/factories/ に定義)auth_headers_for(user)(spec/support/auth_helpers.rb)use_transactional_fixtures = truedocker compose exec -T back bundle exec rspec <spec_path>$ARGUMENTS で指定されたPR番号、ファイルパス、または機能を分析する。
gh pr diff で差分を取得、ファイルパスの場合は直接読むテスト対象の種別に応じて、以下の粒度で設計する。
配置: spec/requests/api/v2/<controller_name>_spec.rb
テストする振る舞い:
RSpec.describe 'Api::V2::Resources', type: :request do
let(:user) { create(:user) }
describe 'GET /api/v2/resources' do
context 'when not authenticated' do
it 'returns 401' do
get '/api/v2/resources'
expect(response).to have_http_status(:unauthorized)
end
end
context 'when authenticated with data' do
let!(:resource) { create(:resource, user:) }
it 'returns the resources' do
get '/api/v2/resources', headers: auth_headers_for(user)
expect(response).to have_http_status(:ok)
json = response.parsed_body
# 出力の構造と値を検証
end
end
end
end
配置: spec/models/<model_name>_spec.rb
テストする振る舞い:
RSpec.describe ModelName, type: :model do
let(:user) { create(:user) }
describe '.class_method_name' do
# テストデータを let! で準備
let!(:record_a) { create(:record, user:, value: 10) }
let!(:record_b) { create(:record, user:, value: 20) }
it 'returns aggregated result' do
result = described_class.class_method_name(user.id)
expect(result.total).to eq(30)
end
it 'filters by parameter' do
result = described_class.class_method_name(user.id, filter: 'value')
expect(result.total).to eq(10)
end
it 'returns nil when no records match' do
result = described_class.class_method_name(user.id, filter: 'nonexistent')
expect(result).to be_nil
end
end
end
配置: spec/services/<service_name>_spec.rb
テストする振る舞い:
RSpec.describe ServiceName do
describe '#execute' do
it 'creates expected records' do
expect { service.execute }
.to change(Record, :count).by(expected_count)
end
it 'sets correct values on created records' do
service.execute
record = Record.find_by(key: value)
expect(record.attribute).to eq(expected)
end
end
end
spec/factories/)を確認して利用する# ゲーム結果 + 試合結果 + 成績の典型的なセットアップ
let!(:game_with_batting) do
gr = create(:game_result, user:)
gr.match_result.update!(
date_and_time: Time.zone.local(2024, 6, 15),
match_type: 'regular'
)
create(:batting_average, game_result: gr, user:,
hit: 3, at_bats: 10, times_at_bat: 12)
gr
end
集計や計算のテストでは、期待値の根拠をコメントで明示する:
expect(result.hit.to_i).to eq(6) # 3+1+2
expect(result[:batting_average]).to eq(0.5) # total_hits(5) / at_bats(10)
テスト作成後は必ず実行して全パスを確認する:
# 新規テストのみ
docker compose exec -T back bundle exec rspec <new_spec_paths> --format documentation
# 全テスト(既存テストが壊れていないことの確認)
docker compose exec -T back bundle exec rspec
失敗した場合は:
describe の文字列はクラスメソッドなら .method_name、インスタンスメソッドなら #method_namecontext は when ... / with ... で条件を記述