Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.