Skip to content

Instantly share code, notes, and snippets.

@JKring
Created February 13, 2014 02:09
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 JKring/8968480 to your computer and use it in GitHub Desktop.
Save JKring/8968480 to your computer and use it in GitHub Desktop.
magical route spec generator!
controllers = %x[ls app/controllers].split("\n").map { |c| c.gsub(".rb", "") }
controllers.each do |controller|
filename = "#{ Rails.root }/tmp/routing/#{ controller.gsub("controller", "routes_spec.rb") }"
%x[touch #{ filename }]
File.open(filename, 'w') do |f|
f.write("require 'spec_helper'\n\n")
methods = controller.classify.constantize.new.public_methods - ApplicationController.new.public_methods
f.write("describe 'routes for #{ controller.classify }' do\n\n")
methods.each do |m|
unless m.to_s.starts_with?("_one_time")
f.write("\tit 'can route to #{ m }' do\n")
f.write("\t\texpect(post: '/#{ controller.gsub("_controller", "" ) }/#{ m }').to be_routable\n")
f.write("\tend\n\n")
end
end
f.write("end\n\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment