Conversation
PR #1814 で `/event` というデッドリンクが修正されたことを受け、 同様の問題の再発を防ぐため Request spec を追加。 - Nokogiri で /kata ページの内部リンクを全件抽出し、 各パスが 400 未満のレスポンスを返すことを確認 - `/events` のハードコードを `events_path` ヘルパーに改善
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
PR #1814 で
/eventというデッドリンクが修正されました。同様の問題の再発を防ぐため、テストを追加します。
変更内容
spec/requests/docs_spec.rb: Nokogiri で/kataページの内部リンクを全件抽出し、各パスが 400 未満のレスポンスを返すことを確認する Request spec を追加app/views/docs/kata.html.erb: ハードコードされた'/events'をevents_pathヘルパーに改善設計上の判断
Feature spec ではなく Request spec を選択
Capybara を使う Feature spec はブラウザ起動のオーバーヘッドがあり、1リンクの確認には過剰。
Request spec は rack-test でインプロセス実行されるため軽量。
recognize_pathではなく実際のgetでチェックRails.application.routes.recognize_pathを使えばさらに高速になりますが、ルートは存在しても 404 を返すケース(例:
/podcasts/999)を検知できません。実際の
getによるチェックでもリンク 33件を 0.58秒 で処理できるため、現在の方式で十分です。putsによるミニレポートCI ログに
Checked 33 internal linksと表示されることで、チェック対象の件数を把握しやすくしています。テスト確認
/event(デッドリンク)を一時的に戻してテストが RED になることを確認済み: