Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RSpec #TechLunch
Search
Livesense Inc.
PRO
April 23, 2014
Technology
64
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RSpec #TechLunch
2012/04/04(水) @ Livesense TechLunch
発表者:塩足 拓也
Livesense Inc.
PRO
April 23, 2014
More Decks by Livesense Inc.
See All by Livesense Inc.
新規商品の開発におけるAIの活用 〜挑戦は人間にしかできない〜
livesense
PRO
0
26
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
180
Rubyはただの⾔語に⾮ず
livesense
PRO
0
600
28新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
0
180
27新卒_総合職採用_会社説明資料
livesense
PRO
0
7.8k
27新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
0
13k
株式会社リブセンス・転職会議 採用候補者様向け資料
livesense
PRO
0
610
株式会社リブセンス 会社説明資料(報道関係者様向け)
livesense
PRO
1
1.8k
データ基盤の負債解消のためのリプレイス
livesense
PRO
0
740
Other Decks in Technology
See All in Technology
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
410
レガシーコードに対する loop engineering的なAI開発プロセス導入について
kubell_hr
0
230
In-Context Learning再入門。ICLの勾配降下的解釈の研究動向を追ってみる。
dai08srhg
1
280
The future of architectural work
ufried
0
160
令和の今、あらためて IAM を考える。アクセスキーを「無くせない現実」との向き合い方
kazzpapa3
0
160
AWSを利用する上で知っておきたい名前解決の話 2026
nagisa53
3
1.7k
自律的なチームを作るためにTechPMがやらないこと
ny7760
1
510
公共分野での生成AI活用
toru_kubota
1
160
SLOを阻む不安
sraku2159
0
220
セキュリティ専任チームなしで攻撃を先回りするSREが実践したSIEM on Amazon OpenSearch Service
cscengineer
PRO
0
200
GCASアップデート(202607-202610)
techniczna
1
110
リアクションエンジニア ― 小さなリアクションから、話しかけやすい組織をつくる ―
ryuguyana
1
130
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.6k
The Language of Interfaces
destraynor
162
27k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3.1k
Building AI with AI
inesmontani
PRO
1
1.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
390
Designing for Timeless Needs
cassininazir
1
550
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Transcript
RSpec Takuya Shiotari
TDDとは テストの対象となるコードを書く前にテストを書く開発手法 1. 失敗するテストコードを書く 2. テストがパスする最小限のコードを書く 3. リファクタリング 開発サイクル RED/GREEN/REFACTOR
▪ コードをクリーンな状態に保つことができる ▪ テストの実践ではない ▪ 高品質なコードをテスト担当者に引き渡すために使用する手法
BDDとは ▪ TDDの派生 ▪ 振る舞い(要求仕様)を自然言語で併記しなが らテストコードを記述 ▪ テスト≒要求仕様 ▪ BDDフレームワーク
◦ ストーリーフレームワーク(Cucumber) ◦ スペックフレームワーク(RSpec)
BDDの原則 ▪ 十分といったら十分 ◦ 必要最低限のことを行うべき ◦ それ以上の労力は無駄 ▪ ステークホルダーに価値をもたらす ◦
目に見える価値をもたらすためにあるべき ▪ すべては振る舞いから ◦ アプリケーションの振る舞いをステークホルダーの視点 に立って説明できるのと同様に、低レベルのコードの振 る舞いを、それを利用する他のコードという視点から説 明する
RSpec導入理由 ▪ プログラムの変更によってデグレードしてないか不安 ▪ コードのサイズが大きくなるとリファクタリングが難しい ▪ ドキュメントをBTSやツールで管理しても他のドキュメントや ソフトウェアと一致しなくなる ▪ 過度な設計をしたくない
⇒テストコードと要求仕様を併記するので常に一致 ⇒自動化したリグレッションテスト ⇒カバレッジが100%のテストがあれば安心してリファクタリング できる ⇒具象的なコードから始まり抽象化するため、適切な抽象化 で抑えられる
RSpec ▪ 2005年にSteven Bakerによって開発 ▪ 振舞を記述するためのDSLを提供するフレームワーク ▪ RSpecは全てがユニットテスト TDDの場合 RSpecの場合
アサーション (コードの検証) エクスペくテーション (期待すること) テスト サンプルコード テストケース サンプルグループ
RSpecのインストール $ gem install rspec ▪ 単独で利用する場合 ▪ railsで利用する場合 group
:develop, :test do gem 'rspec-rails' end RAILS_ROOT/Gemfile
サンプルスペックファイル describe Stack do before do @stack = Stack.new @stack.push
:item end describe "#peek" do it "should return the top element" do @stack.peek.should == :item end it "should not remove the top element" do @stack.peek @stack.size.should == 1 end end end stack_spec.rb フック サンプルコード サンプルコード サンプル グループ
スペックファイルの構成
RSpecの実行 フィルタ サンプルコード サンプルコード サンプル グループ $ rspec stack_spec.rb -c
.. Finished in 0.00063 seconds 2 examples, 0 failures ▪ 単独で利用する場合 ▪ railsで利用する場合 $ bundle exec rspec spec/views/home/index.html.erb_spec.rb .................... Finished in 10.79 seconds 20 examples, 0 failures
specdoc形式のフォーマット $ rspec stack_spec.rb -c -fd Stack #peek should return
the top element should not remove the top element Finished in 0.00072 seconds 2 examples, 0 failures
考察 ▪ 考え方になれるまで大変 ▪ Mockの使い方が鍵 ▪ RSpec単体では遅い ⇒ sporkを使って高速化 ▪
RSpec on Railsでは全てを単体テストにできる ので関心が自然に分離される ▪ eureeekaは英語で記述したが、日本語にしても よかったかも…
次回
RSpec gemの構成 ▪ rspec-core ◦ describeやitなどの実行可能なサンプルを記述できる構 造を提供 ▪ rspec-expectations ◦
サンプル内でオブジェクトの期待する結果を表現 ▪ rspec-mocks ◦ rspec-mocksはテストダブルフレームワーク ◦ テストダブル、メソッドスタブ、メッセージエクスペくテー ションをサポート
RSpec::Core ▪ describe ◦ サンプルグループを宣言 ▪ it ◦ サンプルを宣言 ▪
pending ◦ サンプルを保留扱いとして宣言 ▪ before、after ◦ サンプルの実行前後をフック
RSpec::Expectations ▪ should(matcher)とshould_not(matcher) ◦ matcher.matches?(self)がtrueの場合:次の行へ ◦ matcher.matches?(self)がfalseの場合:例外発生 ▪ RSpecに組み込まれているマッチャ ◦
equal、include、respond_to, raise_error ▪ 述語マッチャ ◦ be_empty、be_instance_of ▪ 演算子を使った式 ◦ result.should.==(3) → result.should == 3 ◦ result.should.(be.<(7)) → result.should be < 7
RSpec::Mocks ▪ テストダブル ◦ サンプルにおいて別のオブジェクトの代役を務めるオブジェクト ▪ メソッドスタブ ◦ サンプルコードの実行中にあらかじめ定義されたレスポンスを返すようにプ ログラムできるメソッド
▪ メッセージエクスペくテーション ◦ 一度も呼び出されないとエラーになるメソッドスタブ ▪ 役割に焦点を合わせる ▪ やり取りに焦点を合わせる ▪ インターフェースの発見 ▪ 依存関係を実装せずに作業をすすめる ▪ 依存関係からの分離 ▪ 不確定性からの分離