Created
February 13, 2014 02:09
-
-
Save JKring/8968480 to your computer and use it in GitHub Desktop.
magical route spec generator!
This file contains 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
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