#027 tddのさわり
DESCRIPTION
広島Ruby勉強会 #027でのプレゼン資料TRANSCRIPT
![Page 1: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/1.jpg)
TDDを勉強してみた広島Ruby勉強会 #027
2013/2/2@CentBoss
at広島市青少年センター生活実習室
113年2月2日土曜日
![Page 2: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/2.jpg)
自己紹介的な何か
• @CentBossの人です
• 広島工業大学の学生です
• プログラミングは初心者レベルです
• 目標は@eielhさんです
• Emacsを勉強してます!
213年2月2日土曜日
![Page 3: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/3.jpg)
今回はあくまでもTDDのさわりなので深いことは喋りません
勉強してきた範囲で喋りますというかBDDじゃね?とかも思ってます
313年2月2日土曜日
![Page 4: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/4.jpg)
あと、初めてLTするのでお手柔らかにお願いします
413年2月2日土曜日
![Page 5: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/5.jpg)
本題
513年2月2日土曜日
![Page 6: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/6.jpg)
そもそもTDDとは?
• test-driven developmentの略
• テスト駆動開発
• →テストをしながら実装を進める開発技法
613年2月2日土曜日
![Page 7: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/7.jpg)
TDDの開発サイクル
Red
GreenRefactor
713年2月2日土曜日
![Page 8: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/8.jpg)
TDDの開発サイクル
• 非常に小さい失敗するテストを書く→Red
• 出来る限りテストをパスできるような最小限のコードを実装する→Green
• コードをきれいにする→Refactor
813年2月2日土曜日
![Page 9: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/9.jpg)
RubyでTDDをするには?
RspecとCucumberと言うものがあるらしい他にもいろいろある感じだけど、今日はこれを選択
というかこれしか使ったことがない
913年2月2日土曜日
![Page 10: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/10.jpg)
RubyでTDDをするには?・Cucumber
アプリケーションの振る舞いをテスト あるコンテキストで(Given)
あるイベントが発生すると(When)
ある結果が期待されます(Then)
・Rspec
オブジェクトの振る舞いをテスト
1013年2月2日土曜日
![Page 11: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/11.jpg)
RubyでTDDをするには?
Red
GreenRefactor
Red
Refactor Green
Cucumber Rspec
1113年2月2日土曜日
![Page 12: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/12.jpg)
RubyでTDDをするには?1.Cucumberで1つのシナリオに焦点を合わせる2.失敗するステップ定義を書く3.Rspecで失敗するサンプルを書く4.Rspecでサンプルを成功させる最低限コードを実装する5.Rspecで書いた最低限コードをリファクタリングする6.Cucumberでリファクタリングする
1213年2月2日土曜日
![Page 13: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/13.jpg)
頑張ってサンプル用意しました!!
1313年2月2日土曜日
![Page 14: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/14.jpg)
RubyでTDDをしてみる• 今回のシナリオ
• 「sample.rbを実行すると”Hiroshima.rb #027”と表示される」
1413年2月2日土曜日
![Page 15: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/15.jpg)
RubyでTDDをしてみる1.Cucumberで1つのシナリオに焦点を合わせる
# language: ja機能: 文字列の表示 シナリオ: sample.rbを実行する もし sample.rbを実行した場合 かつ メッセージが出力される ならば "Hiroshima.rb #027"と表示している
1513年2月2日土曜日
![Page 16: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/16.jpg)
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日土曜日
![Page 17: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/17.jpg)
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日土曜日
![Page 18: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/18.jpg)
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日土曜日
![Page 19: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/19.jpg)
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日土曜日
![Page 20: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/20.jpg)
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日土曜日
![Page 21: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/21.jpg)
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日土曜日
![Page 22: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/22.jpg)
RubyでTDDをしてみる4.Rspecでサンプルを成功させる最低限コードを実装する
class Sample def message "Hiroshima.rb #027" endend
2213年2月2日土曜日
![Page 23: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/23.jpg)
RubyでTDDをしてみる4.Rspecでサンプルを成功させる最低限コードを実装する
.
Finished in 0.00037 seconds1 example, 0 failures
“.”が成功したということ
2313年2月2日土曜日
![Page 24: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/24.jpg)
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日土曜日
![Page 25: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/25.jpg)
RubyでTDDをしてみる5.Rspecで書いた最低限コードをリファクタリングする6.Cucumberでリファクタリングする
今日のところは省略ということで…
2513年2月2日土曜日
![Page 26: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/26.jpg)
↓本日のサンプルはGithubにあります↓https://github.com/moriC/hiroshimarb-tdd
2613年2月2日土曜日
![Page 27: #027 tddのさわり](https://reader030.vdocuments.mx/reader030/viewer/2022013115/55946fff1a28ab990e8b465a/html5/thumbnails/27.jpg)
ご清聴ありがとうございました
2713年2月2日土曜日