Skip to content

Instantly share code, notes, and snippets.

@BrentonEarl
Forked from tarynsauer/Rakefile
Last active August 29, 2015 14:11
Show Gist options
  • Save BrentonEarl/45819c44c75e90fefb68 to your computer and use it in GitHub Desktop.
Save BrentonEarl/45819c44c75e90fefb68 to your computer and use it in GitHub Desktop.
Automatically creates unit test files using "rake generate:test NAME=test_name and puts them in the test/ directory
namespace :generate do
desc "Add new Unit Test file"
task :test do
unless ENV.has_key?('NAME')
raise "Must specify a unit test file name, e.g., rake generate:test NAME=test_name"
end
unit_test_path = "test/" + ENV['NAME'].downcase + "_test.rb"
if File.exist?(unit_test_path)
raise "ERROR: Test file '#{unit_test_path}' already exists."
end
puts "Creating #{unit_test_path}"
File.open(unit_test_path, 'w+') do |f|
f.write("require 'test_helper'\n\n")
f.write("# Rename the test class\n")
f.write("class TestNameOfTest < Minitest::Test\n\n")
f.write("end")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment