Skip to content

Instantly share code, notes, and snippets.

@shinofara
Created April 21, 2013 14:21
Show Gist options
  • Save shinofara/5429761 to your computer and use it in GitHub Desktop.
Save shinofara/5429761 to your computer and use it in GitHub Desktop.
javascriptの自動テスト化して楽をする!(まだβ版のjasmine-standalone-2.0.0を使ってるよ)導入編 ref: http://qiita.com/items/f1ad4e9331a11be20d66
cd /usr/loca/src/
git clone git://github.com/pivotal/jasmine.git
cd テスト用ディレクトリ(どこでもOK)
sudo cp /usr/local/src/jasmine/dist/jasmine-standalone-2.0.0-alpha.zip ./
unzip jasmine-standalone-2.0.0-alpha.zip -d jasmine
jasmine
|- SpecRunner.html ・・・テストページ
|- lib ・・・jasmineライブラリ
|- spec ・・・テストケース
|- src ・・・テスト用ソース
ruby -rwebrick -e 's = WEBrick::HTTPServer.new(:Port=>39999, :DocumentRoot=>Dir.pwd, :CGIInterpreter=>"/usr/local/bin/ruby -Eutf-8:utf-8");trap("INT"){s.shutdown};s.start'
ruby -rwebrick -e 's = WEBrick::HTTPServer.new(:Port=>39999, :DocumentRoot=>Dir.pwd, :CGIInterpreter=>"/usr/local/bin/ruby -Eutf-8:utf-8");trap("INT"){s.shutdown};s.start'
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Jasmine Spec Runner v2.0.0-alpha</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.0-alpha/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.0-alpha/jasmine.css">
<script type="text/javascript" src="lib/jasmine-2.0.0-alpha/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0-alpha/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-2.0.0-alpha/boot.js"></script>
<!-- include source files here... -->
<!--
<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>
-->
<!-- include spec files here... -->
<!--
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
-->
<script type="text/javascript" src="spec/test.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</head>
<body>
</body>
</html>
describe("Player", function() {
var aa;
//事前処理
beforeEach(function() {
aa = '123';
});
//テストケース
it("A処理のバリデーションチェック", function() {
if (123 !== aa) {
//例外が上がればエラー
throw new Error("int型ではない為エラー");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment