Created
September 13, 2013 06:00
-
-
Save JonathonMA/6547155 to your computer and use it in GitHub Desktop.
Sick of boilerplate.
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
#!/usr/bin/env ruby | |
# testfor - gen test for class | |
# | |
# USAGE | |
# | |
# Generate a test skeleton for the Person class | |
# $ testfor Person | |
require 'active_support' | |
require 'active_support/core_ext/string/inflections' | |
require 'highline/import' | |
DEFAULT_UNIT = "model" # maybe lib? | |
class_name = ARGV.shift or abort "must specify a class name" | |
filename = class_name.underscore | |
path = `find app -name #{filename}.rb | head -1`.strip | |
.gsub(/^app/, "test/unit") | |
.gsub(/\.rb$/, "_test.rb") | |
if path.empty? | |
path = "test/unit/#{DEFAULT_UNIT}/#{filename}.rb" | |
end | |
outline = DATA.read.gsub "%{class_name}", class_name | |
say "=" * 80 | |
say outline | |
say "=" * 80 | |
if File.exist? path | |
say "#{path} #{HighLine::RED}already exists#{HighLine::CLEAR}, deal with it." | |
elsif agree "Ok to write this skeleton to #{HighLine::RED}#{path}#{HighLine::CLEAR}?" | |
File.open(path, "w") do |f| | |
f.puts outline | |
end | |
end | |
__END__ | |
require 'test_helper' | |
class %{class_name}Test < ActiveSupport::TestCase | |
test "" do | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment