Created
October 17, 2012 06:35
-
-
Save tomoyamkung/3904037 to your computer and use it in GitHub Desktop.
[Ruby]Test::Unit を使ったテストケースを生成するスクリプト
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
#! ruby #-*- encoding: utf-8 -*- | |
class GenerateTestCase | |
TEMPLATE = <<-EOS | |
#! ruby | |
#-*_ encoding: utf-8 -*- | |
require 'test/unit' | |
class _CLASS_NAME_Test < Test::Unit::TestCase | |
def setup | |
@obj = _CLASS_NAME_.new | |
end | |
end | |
EOS | |
def camelize string | |
string.split('-').map do |word| | |
word.capitalize | |
end.join | |
end | |
def execute script_name | |
file_name = script_name + "-test.rb" | |
class_name = camelize script_name | |
#puts TEMPLATE.gsub("_CLASS_NAME", class_name) | |
File.write file_name, TEMPLATE.gsub("_CLASS_NAME_", class_name) | |
end | |
end | |
if __FILE__ == $0 | |
obj = GenerateTestCase.new | |
obj.execute(ARGV[0]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment