exercism.io

The change log” targetの108回目を聞いていたら面白そうだったので、早速ためしてみた。

ソーシャルにプログラミングのスキルを高めようってプロジェクトで元々はRuby、今はgoで書かれているらしい。github.comのアカウントがもとからあったので、すんなりセットアップは完了。

トップページから緑のボタンでログイン。

説明にしたがってcliをインストール。

exercism用のフォルダを作って

mkdir フォルダの名前

ログイン

exercism login

githubのアカウント聞かれるので入力
APIはaccountに表示されているのでそれを入力。
保存先フォルダを先ほど作ったフォルダに設定。

あとはexercism コマンドでアサイメントを落としてくるだけ。

exercism fetch

NAME: exercism - A command line tool to interact with http://exercism.io USAGE: exercism [global options] command [command options] [arguments...] VERSION: 1.6.2 COMMANDS: current, c Show the current assignments demo, d Fetch first assignment for each language from exercism.io fetch, f Fetch assignments from exercism.io login, l Save exercism.io api credentials logout, o Clear exercism.io api credentials restore, r Restore completed and current assignments from exercism.io submit, s Submit code to exercism.io on your current assignment unsubmit, u Delete the last submission whoami, w Get the github username that you are logged in as help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --config, -c '/home/kentaro/.exercism.go' path to config file --version, -v print the version --help, -h show help

javascriptはjasmine-nodeを利用するみたいなのでインストール -g は付けないほうがいいらしいけど オフィシャルサイトにもそう書いてあるし、なしだとうまく行かないらしい。

npm install jasmine-node -g

bob_test.spec.js は

var Bob = require(‘./bob’)

となっていたので

テストファイルと同じ階層にbob.jsファイルを作成 本文中に

var Bob = function() {}; module.exports = Bob;

とだけ書いてみて

jasmine-node bob_test.spec.js

F Failures: 1) Bob stating something Message: TypeError: Object [object Object] has no method 'hey' Stacktrace: TypeError: Object [object Object] has no method 'hey' at null. (/javascript/bob/bob_test.spec.js:7:22) Finished in 0.023 seconds 1 test, 1 assertion, 1 failure, 0 skipped

無事に?テストに失敗

it になっているのは次の項目だけなので内容を確認。

it("stating something", function() { var result = bob.hey('Tom-ay-to, tom-aaaah-to.'); expect(result).toEqual('Whatever.'); });

heyメソッドにTom-ay-to, tom-aaaah-to.って渡すと「Whatever.」って返すのね

README.mdを読むとってことなので
He answers ‘Whatever.’ to anything else.
になってるので。

var Bob = function() {};

var Bob = function() { this.hey = function(message) { return "Whatever."; }; };

Finished in 0.009 seconds
1 test, 1 assertion, 0 failures, 0 skipped

成功!!

試しに return “Whatever.”; の内容「1」に変更すると

F Failures: 1) Bob stating something Message: Expected '1' to equal 'Whatever.'. Stacktrace: Error: Expected '1' to equal 'Whatever.'. at null. (/home/kentaro/javascript/bob/bob_test.spec.js:8:20) Finished in 0.019 seconds 1 test, 1 assertion, 1 failure, 0 skipped

なるほどねぇ 終わったら次のテスト、次のテストってこなして終わったら投稿するんだ
 面白い!!

Subscribe to Kentaro

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe