#027 tddのさわり
description
Transcript of #027 tddのさわり
TDDを勉強してみた広島Ruby勉強会 #027
2013/2/2@CentBoss
at広島市青少年センター生活実習室
113年2月2日土曜日
自己紹介的な何か
• @CentBossの人です
• 広島工業大学の学生です
• プログラミングは初心者レベルです
• 目標は@eielhさんです
• Emacsを勉強してます!
213年2月2日土曜日
今回はあくまでもTDDのさわりなので深いことは喋りません
勉強してきた範囲で喋りますというかBDDじゃね?とかも思ってます
313年2月2日土曜日
あと、初めてLTするのでお手柔らかにお願いします
413年2月2日土曜日
本題
513年2月2日土曜日
そもそもTDDとは?
• test-driven developmentの略
• テスト駆動開発
• →テストをしながら実装を進める開発技法
613年2月2日土曜日
TDDの開発サイクル
Red
GreenRefactor
713年2月2日土曜日
TDDの開発サイクル
• 非常に小さい失敗するテストを書く→Red
• 出来る限りテストをパスできるような最小限のコードを実装する→Green
• コードをきれいにする→Refactor
813年2月2日土曜日
RubyでTDDをするには?
RspecとCucumberと言うものがあるらしい他にもいろいろある感じだけど、今日はこれを選択
というかこれしか使ったことがない
913年2月2日土曜日
RubyでTDDをするには?・Cucumber
アプリケーションの振る舞いをテスト あるコンテキストで(Given)
あるイベントが発生すると(When)
ある結果が期待されます(Then)
・Rspec
オブジェクトの振る舞いをテスト
1013年2月2日土曜日
RubyでTDDをするには?
Red
GreenRefactor
Red
Refactor Green
Cucumber Rspec
1113年2月2日土曜日
RubyでTDDをするには?1.Cucumberで1つのシナリオに焦点を合わせる2.失敗するステップ定義を書く3.Rspecで失敗するサンプルを書く4.Rspecでサンプルを成功させる最低限コードを実装する5.Rspecで書いた最低限コードをリファクタリングする6.Cucumberでリファクタリングする
1213年2月2日土曜日
頑張ってサンプル用意しました!!
1313年2月2日土曜日
RubyでTDDをしてみる• 今回のシナリオ
• 「sample.rbを実行すると”Hiroshima.rb #027”と表示される」
1413年2月2日土曜日
RubyでTDDをしてみる1.Cucumberで1つのシナリオに焦点を合わせる
# language: ja機能: 文字列の表示 シナリオ: sample.rbを実行する もし sample.rbを実行した場合 かつ メッセージが出力される ならば "Hiroshima.rb #027"と表示している
1513年2月2日土曜日
RubyでTDDをしてみる1.Cucumberで1つのシナリオに焦点を合わせる
# language: ja機能: 文字列の表示
シナリオ: sample.rbを実行する # features/sample.feature:4
もしsample.rbを実行した場合 # features/sample.feature:5
かつメッセージが出力される # features/sample.feature:6
ならば"Hiroshima.rb #027"と表示している # features/sample.feature:7
1 scenario (1 undefined)3 steps (3 undefined)0m0.003s
You can implement step definitions for undefined steps with these snippets:
もし /^sample\.rbを実行した場合$/ do pending # express the regexp above with the code you wish you hadend
もし /^メッセージが出力される$/ do pending # express the regexp above with the code you wish you hadend
ならば /^"(.*?)"と表示している$/ do |arg1| pending # express the regexp above with the code you wish you hadend
Step definitionsに書いてね
1613年2月2日土曜日
RubyでTDDをしてみる2.失敗するステップ定義を書く
# coding: utf-8もし /^sample\.rbを実行した場合$/ do
pending # express the regexp above with the code you wish you hadend
もし /^メッセージが出力される$/ do
pending # express the regexp above with the code you wish you hadend
ならば /^"(.*?)"と表示している$/ do |arg1|
pending # express the regexp above with the code you wish you hadend
1713年2月2日土曜日
RubyでTDDをしてみる2.失敗するステップ定義を書く
# language: ja機能: 文字列の表示
シナリオ: sample.rbを実行する # features/sample.feature:4
もしsample.rbを実行した場合 # features/step_definitions/sample_steps.rb:2
TODO (Cucumber::Pending) ./features/step_definitions/sample_steps.rb:3:in `/^sample\.rbを実行した場合$/'
features/sample.feature:5:in `もしsample.rbを実行した場合'
かつメッセージが出力される # features/step_definitions/sample_steps.rb:6
ならば"Hiroshima.rb #027"と表示している # features/step_definitions/sample_steps.rb:10
1 scenario (1 pending)3 steps (2 skipped, 1 pending)
1813年2月2日土曜日
RubyでTDDをしてみる2.失敗するステップ定義を書く
# coding: utf-8もし /^sample\.rbを実行した場合$/ do
@sample = Sample.newend
もし /^メッセージが出力される$/ do
@message = @sample.messageend
ならば /^"(.*?)"と表示している$/ do |arg1|
@message.should == 'Hiroshima.rb #027'end
1913年2月2日土曜日
RubyでTDDをしてみる3.Rspecで失敗するサンプルを書く
require 'sample'
describe "Message" do it "get message" do sample = Sample.new message = sample.message message.should == 'Hiroshima.rb #027' endend
2013年2月2日土曜日
RubyでTDDをしてみる3.Rspecで失敗するサンプルを書く
F
Failures:
1) Message get message Failure/Error: sample = Sample.new NameError: uninitialized constant Sample # ./spec/sample_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.00077 seconds1 example, 1 failure
Failed examples:
rspec ./spec/sample_spec.rb:4 # Message get message
“F”が失敗したということ
2113年2月2日土曜日
RubyでTDDをしてみる4.Rspecでサンプルを成功させる最低限コードを実装する
class Sample def message "Hiroshima.rb #027" endend
2213年2月2日土曜日
RubyでTDDをしてみる4.Rspecでサンプルを成功させる最低限コードを実装する
.
Finished in 0.00037 seconds1 example, 0 failures
“.”が成功したということ
2313年2月2日土曜日
RubyでTDDをしてみる4.Rspecでサンプルを成功させる最低限コードを実装する
# language: ja機能: 文字列の表示
シナリオ: sample.rbを実行する # features/sample.feature:4
もしsample.rbを実行した場合 # features/step_definitions/sample_steps.rb:2
かつメッセージが出力される # features/step_definitions/sample_steps.rb:6
ならば"Hiroshima.rb #027"と表示している # features/step_definitions/sample_steps.rb:10
1 scenario (1 passed)3 steps (3 passed)
2413年2月2日土曜日
RubyでTDDをしてみる5.Rspecで書いた最低限コードをリファクタリングする6.Cucumberでリファクタリングする
今日のところは省略ということで…
2513年2月2日土曜日
↓本日のサンプルはGithubにあります↓https://github.com/moriC/hiroshimarb-tdd
2613年2月2日土曜日
ご清聴ありがとうございました
2713年2月2日土曜日