gitで複数のauthor, committerの使い分け
環境変数で設定すっと上書きしてくれる
% git config --help
user.email
Your email address to be recorded in any newly created commits. Can be overridden by the GIT_AUTHOR_EMAIL, GIT_COMMITTER_EMAIL, and EMAIL environment variables. See git-commit-tree(1).user.name
Your full name to be recorded in any newly created commits. Can be overridden by the GIT_AUTHOR_NAME and GIT_COMMITTER_NAME environment variables. See git-commit-tree(1).
.zshrc.local
export GIT_AUTHOR_NAME='foo' export GIT_AUTHOR_EMAIL='foo@example.com' export GIT_COMMITTER_NAME='foo' export GIT_COMMITTER_EMAIL='foo@example.com'
.zshrc
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
The Platinum Searcher
Go言語でag(The Silver Searcher)ライクな高速検索ツールをつくった。EUC-JP/Shift-JISも検索できマス。 · THINKING MEGANE
ダウンロードしたバイナリが動かなかったのでビルドしてみる
とりあえず、GOPATH は適当。
% brew install go % export GOPATH=~/src/gocode % go get github.com/monochromegane/the_platinum_searcher % co ~/src/gocode/src/github.com/monochromegane/the_platinum_searcher % go build -o ~/bin/pt
.zshrc とか
if [ -x "`which go`" ]; then export GOROOT=`go env GOROOT` export GOPATH=$HOME/.go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin fi
Mavericksでphp5.2.17コンパイルエラー
make: *** [ext/dom/node.lo] Error 1
libxml2まわりの不具合の模様
https://mail.gnome.org/archives/xml/2012-August/msg00028.html
https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
https://gist.github.com/oppara/8281560
% cd /path/to/src % patch -p0 < php-5.2_libxml2.patch
JenkinsでCakeBehat
Behat/Minkのテストはブラウザでアクセスされるので、テスト時はtestデータソースを使用するように工夫が必要。
The Opera blog
あと、アクセス先のテスト用DBの初期化、後始末が必要。
も一つ、ciサーバ内で完結するなら、ciサーバ上でのwebサーバ設定が必要。
もしくは、ciサーバ上から別サーバ上にアクセスする場合、git hook時に別サーバ上のソースの更新とDBの(ry
面倒なので、ciサーバで完結できるようにする
実装
ホスト名がtestから始まっていた場合は、testデータソースを使用する。
app/Config/database.php
<?php public function __construct() { $env = env('CAKE_ENV'); if ($this->__isCakeBehatAccess()) { $env = 'test'; } if (property_exists(__CLASS__, $env)) { $this->default = $this->{$env}; } else { $this->default = $this->production; } } private function __isCakeBehatAccess() { $server = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''; if (strpos($server, 'test') === 0) { return true; } return false; }
テスト用DBの初期化、後始末を行う
app/Test/features/bootstrap/FeatureContext.php
<?php /** * @BeforeSuite */ public static function setup($event) { $fmt = '(cd %s && bash ./Console/cake Migrations.migration run all -c test)'; $cmd = sprintf($fmt, APP); exec($cmd); } /** * @AfterSuite */ public static function teardown($event) { $tables = array(); $db = ConnectionManager::getDataSource('test'); $db->cacheSources = false; $usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix']; if ($usePrefix) { foreach ($db->listSources() as $table) { if (!strncmp($table, $usePrefix, strlen($usePrefix))) { $tables[] = substr($table, strlen($usePrefix)); } } } else { $tables = $db->listSources(); } $fmt = 'DROP TABLE %s;'; foreach ($tables as $t) { $sql = sprintf($fmt, $db->fullTableName($t)); $db->execute($sql); } }
設定とか
app/Config/behat.yaml
default: context: parameters: # TODO base_urlがDRYじゃない base_url: 'http://test.example.com/' extensions: Behat\MinkExtension\Extension: base_url: 'http://test.example.com/' goutte: ~ selenium2: wd_host: "http://localhost:8643/wd/hub"
<?xml version="1.0" encoding="utf-8"?> <project name="project" default="behat"> <target name="behat" depends="init, start_phontomjs, submodule_update, cakebehat, stop_phontomjs"></target> <target name="init" > <delete dir= "./reports" includeemptydirs= "true" /> <mkdir dir= "./reports" /> </target> <target name="submodule_update"> <exec executable="git" > <arg line="submodule update --init --recursive" /> </exec> </target> <target name="cakebehat" depends= "install_behat, change_tmp_permision"> <exec executable="./lib/Cake/Console/cake" > <arg line=" CakeBehat.bdd --config ./app/Config/behat.yml --profile default --format junit --out ./reports/" /> </exec> </target> <target name="change_tmp_permision"> <exec command="find tmp -type d | xargs chmod 0777" dir="./app/" /> </target> <target name="install_behat" depends= "install_composer"> <exec command="php composer.phar install" dir="./app/Plugin/CakeBehat" /> </target> <target name="install_composer"> <exec command="curl http://getcomposer.org/installer | php" dir="./app/Plugin/CakeBehat" /> </target> <target name="start_phontomjs"> <exec command="/usr/local/bin/phantomjs --webdriver=8643 >/dev/null 2>&1 &" /> </target> <target name="stop_phontomjs"> <exec command="killall phantomjs" /> </target> </project>
全体的にかなり力技。もっとスマートなやり方があるんじゃまいか?
他のテストでphantomjsが走ってたら、killallはまずい。。
CakeBehat
https://github.com/oppara/CakeBehat
もろもろ動かなかったのでとりあえずフォーク
インストールとか
直の場合
% cd /path/to/cake_root/app/Plugin % git clone https://github.com/oppara/CakeBehat.git
submoduleの場合
% cd /path/to/cake_root % git submodule add https://github.com/oppara/CakeBehat.git app/Plugin/CakeBehat % git submodule update --init app/Plugin/CakeBehat
composer, behatとかのインストール
% cd /path/to/cake_root/app/Plugin/CakeBehat % curl http://getcomposer.org/installer | php % php composer.phar install
app/Config/bootstrap.php に以下を追加
CakePlugin::loadAll();
確認(CakeBehatのメニューが表示されること)
% cd /path/to/cake_root/app % ./Console/cake Welcome to CakePHP v2.4.1 Console --------------------------------------------------------------- App : app Path: /srv/httpd/cake.local/app/ --------------------------------------------------------------- Current Paths: -app: app -working: /srv/httpd/cake.local/app -root: /srv/httpd/cake.local -core: /srv/httpd/cake.local/lib Changing Paths: Your working path should be the same as your application path. To change your path use the '-app' param. Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp Available Shells: [CakeBehat] bdd, init
実行
初期化(behat.ymlとfeaturesディレクトリのコピー)
% cd /path/to/cake_root/app % ./Console/cake CakeBehat.init Welcome to CakePHP v2.4.1 Console --------------------------------------------------------------- App : app Path: /srv/httpd/cake.local/app/ --------------------------------------------------------------- copy /srv/httpd/cake.local/app/Plugin/CakeBehat/features to Cake app/Test... copy behat.yml to App/Config...
実行
% cd /path/to/cake_root/app % ./Console/cake CakeBehat.bdd Welcome to CakePHP v2.4.1 Console --------------------------------------------------------------- App : app Path: /srv/httpd/cake.local/app/ --------------------------------------------------------------- シナリオがありません ステップがありません 0m0.034s
フィーチャ、ステップ例
# language: ja フィーチャ: ログイン シナリオ: ログインとログアウトが出来ること 前提"/login" を表示している ならば PHPエラーが表示されていないこと かつ "ログイン" と表示されていること かつ "email" フィールドに "admin@example.com" と入力する かつ "password" フィールドに "password" と入力する もし "ログイン" ボタンをクリックする ならば PHPエラーが表示されていないこと かつ "HOME" と表示されていること もし "ログアウト" のリンク先へ移動する ならば PHPエラーが表示されていないこと かつ "ログイン" と表示されていること
<?php $steps->Given('/^PHPエラーが表示されていないこと$/', function($world) { return array( new Behat\Behat\Context\Step\Then('"Warning" と表示されていないこと'), new Behat\Behat\Context\Step\Then('"Notice" と表示されていないこと') ); });