Module: RSpec::Signal::Symptoms::Route
- Defined in:
- lib/rspec/signal/symptoms/route.rb
Overview
A route that does not exist -- the usual thing sitting behind a suite full of unexplained 404s.
Constant Summary collapse
- NO_ROUTE =
/No route matches (?<target>\[[A-Z]+\]\s*"[^"]*"|\{[^}]*\})/- HELPER =
reader_progress_pathafter the route was renamed or removed. /undefined (?:local variable or method|method) [`'"](?<helper>\w+_(?:path|url))['"`]/
Class Method Summary collapse
- .call(_failure, text) ⇒ Object
- .helper(text) ⇒ Object
-
.normalize(target) ⇒ Object
/readers/48213/progressand/readers/91055/progressare the same missing route, so identifier-shaped segments become:id.
Class Method Details
.call(_failure, text) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/rspec/signal/symptoms/route.rb', line 15 def call(_failure, text) match = NO_ROUTE.match(text) return helper(text) unless match target = normalize(match[:target]) Symptom.new(kind: :route, key: "route:#{target}", label: "no route matches `#{target}`", detail: "no route matches #{target}") end |
.helper(text) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rspec/signal/symptoms/route.rb', line 24 def helper(text) match = HELPER.match(text) return nil unless match name = match[:helper] Symptom.new(kind: :route_helper, key: "route-helper:#{name}", label: "undefined route helper `#{name}`", detail: "undefined `#{name}`") end |
.normalize(target) ⇒ Object
/readers/48213/progress and /readers/91055/progress are the same
missing route, so identifier-shaped segments become :id.
35 36 37 38 39 40 41 |
# File 'lib/rspec/signal/symptoms/route.rb', line 35 def normalize(target) target.to_s .gsub(%r{/\d+(?=/|"|\z)}, "/:id") .gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?=/|"|\z)}i, "/:id") .gsub(/\s+/, " ") .strip end |