-
-
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
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
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