Skip to content

Instantly share code, notes, and snippets.

@igaiga
Last active July 18, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/470ecbd98829c646c7550f5257fff2c5 to your computer and use it in GitHub Desktop.
Save igaiga/470ecbd98829c646c7550f5257fff2c5 to your computer and use it in GitHub Desktop.
# routesの中でrequest_specで呼ばれないエンドポイントを探す
require "active_support"
require "active_support/core_ext"
require "awesome_print"
### routes
raw_routes_string = ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes).format(ActionDispatch::Routing::ConsoleFormatter.new)
raw_routes = raw_routes_string.split("\n")
raw_routes.shift # 先頭行はヘッダ行なので読み飛ばし
routes = raw_routes.map do |line|
if line =~ /.*\s+?(.+?)#(.+?)\s+?/
controller, action = $1, $2
"#{controller}##{action}"
end
end.compact
### specs
# ApplicationControllerへ以下を足して、事前にrequest_specを実行しておく
# before_action -> { Logger.new('tmp/foo.log').debug("#{controller_name} #{action_name}")}
# $ bin/rspec spec --tag type:request > request_spec_log.txt
specs =[]
File.open('request_spec_log.txt') do |f|
f.gets # 先頭行はヘッダ行なので読み飛ばし
f.each_line do |line|
specs << line.split.last(2).join("#") # "controller#action"
end
end
specs.uniq!
no_test_endpoints = (routes - specs)
no_test_endpoints.sort!
#ap routes
#ap specs
#ap no_test_endpoints
no_test_endpoints.each{|x| puts x }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment