Created
August 20, 2013 16:26
-
-
Save lfzawacki/6283775 to your computer and use it in GitHub Desktop.
Read a Rails model file and print to stdout an rspec describe block for each method
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
def warn_and_exit | |
puts "Prints to stdout a describe block for each method in the model file." | |
puts "\tusage \"#{__FILE__}\" [MODEL_FILE]" | |
exit 0 | |
end | |
warn_and_exit if ARGV.size != 1 | |
content = IO.read(ARGV[0]) | |
methods = content.scan /^\s*def\s+([^\s\(]+).*$/ | |
methods.flatten.each do |m| | |
puts "describe '\##{m}' do" | |
puts "" | |
puts "end" | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment