Skip to content

Instantly share code, notes, and snippets.

@oieioi
Created October 5, 2014 18:29
Show Gist options
  • Save oieioi/c1946bffce497f76e3c7 to your computer and use it in GitHub Desktop.
Save oieioi/c1946bffce497f76e3c7 to your computer and use it in GitHub Desktop.
CoffeeScript の class 名から mocha テストを生成する
#!/bin/sh
DIR=~/repos/hogehoge/
match=' class .+extends'
for filepath in `git grep -l -E "$match"`
do
classname_raw=`grep -o -E "$match" $filepath`
classname=`echo $classname_raw| cut -d' ' -f2`
# 最後の/から.まで
# hogehoge/huga/bar/piyo.txt
# のとき piyo.txt
filename=`echo $filepath|awk -F'/' '{print $NF}'`
# piyo
filename_without_ext=`echo $filename|awk -F'.' '{print $1}'`
# txt
extention=`echo $filename|awk -F'.' '{print $2}'`
# hogehoge/huga/bar/
path=`echo $filepath|awk -F'/' '{path="";for(nu=1;nu<NF;nu++){path=path $nu "/"}print path}'`
mkdir -p $DIR$path
newfile=$DIR$path$filename_without_ext.spec.$extention
if test -e $newfile; then
echo $newfile exists
else
touch $newfile
echo $newfile created
cat << EOS >$newfile
require = '../$path$filename_without_ext'
describe '$classname', ->
it 'initialize'
EOS
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment