Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Created October 17, 2012 06:35
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 tomoyamkung/3904037 to your computer and use it in GitHub Desktop.
Save tomoyamkung/3904037 to your computer and use it in GitHub Desktop.
[Ruby]Test::Unit を使ったテストケースを生成するスクリプト
#! 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