Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created August 20, 2013 16:26
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 lfzawacki/6283775 to your computer and use it in GitHub Desktop.
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
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