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
Fixtureを活用して Rspecを爆速にしたい
Search
つかも
July 16, 2026
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Fixtureを活用して Rspecを爆速にしたい
Rails Tokyo (20260716)
https://railstokyo.connpass.com/event/393733/
つかも
July 16, 2026
More Decks by つかも
See All by つかも
20251127_スキーマってなんですか?
kame82
0
280
20251110_話題の音声入力で技術書を読んでみたよ
kame82
0
220
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
The SEO identity crisis: Don't let AI make you average
varn
0
590
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
The agentic SEO stack - context over prompts
schlessera
0
970
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Transcript
FIXTURE を活用して RSPEC を爆速にしたい 2025/07/16 RailsTokyo#5
Introduction つかも Software Engineer X: @kamteyaso Github: @kame82 トラックボール付き分割キーボード(DYA2) Work
Health Teach系の企業(Ruby, TS) 購買管理系の企業(Ruby) Best buy
None
・ RailsのFixtureを 使ったことある人? Question 質問
Today’s goals 本日のゴール ・・ TARGET: Fixtureについてよく知らない方 FactoryBotしか使った事がない方 GOAL: Fixtureという機能を知る Railsにおけるバックエンドテスト基盤の選択肢を増やす
少しでもFixtureが良いなと思ってもらえることを目指します!
Fixture Test FactoryBot Builder Develop Seed Viewer Today’s goals 本日のゴール
・・
Background きっかけ ・・・ FactoryBotの高速化のためには Build strategyの使い分けが重要という話らしい
The build strategy of FactoryBot FactoryBotのBuild strategy ・・・・ 本当に早くなるんだろうか...? 200
generated records / run × 3 assertion tests × 10 runs → 30 examples,/ Finished in xx seconds
Regarding Factory-based test speed FactoryBotのテスト実行速度 ・・・・・
Regarding Factory-based test speed FactoryBotのテスト実行速度 ・・・・・・ create 1.64 seconds build_stubbed
build
Regarding Factory-based test speed FactoryBotのテスト実行速度 ・・・・・・ create 1.64 seconds build_stubbed
build 0.91296 seconds 0.59623 seconds
・・・・・・・ それ、Fixture にやらせてください Regarding Fixture-based test speed Fixtureのテスト実行速度
Regarding Fixture-based test speed Fixtureのテスト実行速度 ・・・・・・・・
Benchmark two methods FactoryBotのテスト実行速度 ・・・・・・・・・ create 2.09 seconds build_stubbed build
0.91296 seconds 0.59623 seconds Fixture 0.05408 seconds
テスト実行 Spec 1 Spec 2 Spec 3 create(:user) create(:user) create(:user)
create(:result) create(:result) create(:result) テスト実行 Spec 1 Spec 2 Spec 3 create(:user) create(:result) FactoryBot Why fixtures are so fast なぜ速いのか ・・・・・・・・・・ Fixture
Regarding fixtures Fixtureとは ・・・・・・・・・・・
Regarding Fixture-based test Fixtureのデータ定義 ・・・・・・・・・・・・
User Regarding Fixture-based test Fixtureのデータ定義 ・・・・・・・・・・・・・ Result
Compare the test code コード量比較 ・・・・・・・・・・・・・・ FactoryBot Fixture
Compare the test code コード量比較 ・・・・・・・・・・・・・・ Fixture
Fixture FactoryBot Benchmark two methods FixtureとFactoryBotのメリデメ ・・・・・・・・・・・・・・・ 柔軟なデータ作成が可能 依存関係が見えやすい DB書き込みが増えて遅くなりガチ
テストコードを削減できる テスト実行速度が早くなる 依存関係や変更影響が見えにくい
Fixture FactoryBot 0 1 2 3 柔軟性 前提の明示性 共通データの再利用性 変更影響の局所化
実行速度 0 1 2 3 柔軟性 前提の明示性 共通データの再利用性 変更影響の局所化 実行速度 Benchmark two methods FixtureとFactoryBotのメリデメ ・・・・・・・・・・・・・・・ 柔軟なデータ作成が可能 依存関係が見えやすい DB書き込みが増えて遅くなりガチ テストコードを削減できる テスト実行速度が早くなる 依存関係や変更影響が見えにくい
Fixture & FactoryBotの戦い The Battle of Fixtures vs. FactoryBot ・・・・・・・・・・・・・・・・
Fixture FactoryBot 0 1 2 3 柔軟性 前提の明示性 共通データの再利用性 変更影響の局所化
実行速度 Benchmark two methods FixtureとFactoryBotのメリデメ ・・・・・・・・・・・・・・・・・
Fixture Test FactoryBot Builder Develop Seed ・・・・・・・・・・・・・・・・・・ My QA System
Architecture Fixtureを用いたQAデータ基盤 Viewer
My QA System Architecture Fixtureを用いたテスト基盤 :共通の基盤となるデータで活用 :状態の変化が激しいレコードで活用 主にRequest specにて活躍 例)
アカウント認証のテストで使用するUserデータ Model specおよび、各種テストで広範に活躍 例) Userデータを作成するときのバリデーション ・・・・・・・・・・・・・・・・・・・ FactoryBot Fixture
Fixture My QA System Architecture Fixtureを用いたテスト基盤 基盤となるデータ Test ・・・・・・・・・・・・・・・・・・・・ Products
FactoryBot 付随するデータ Order
My QA System Architecture Fixtureを用いたテスト基盤 Fixtureの体験を向上するため,2つの仕組みを構築 Fixture Builder Fixture Viewer
・・・・・・・・・・・・・・・・・・・・・
Fixture Test FactoryBot Builder Develop Seed ・・・・・・・・・・・・・・・・・・・・・・ My QA System
Architecture Fixtureを用いたQAデータ基盤 Viewer
My QA System Architecture Fixtureを用いたテスト基盤 Fixtureの体験を向上するため,2つの仕組みを構築 Fixture Builder Fixture Viewer
・・・・・・・・・・・・・・・・・・・・・・・
Fixture Test FactoryBot Builder My QA System Architecture Fixtureを用いたQAデータ基盤 ・・・・・・・・・・・・・・・・・・・・・・・・
FixtureBuilder FixtureBuilder FactoryBot Fixture DB Fixtureのバリデーションが効かないデメリットを回避 ・・・・・・・・・・・・・・・・・・・・・・・・・
FixtureBuilder FixtureBuilder FactoryBot Fixture set A DB Scenario A Scenario
B Scenario C Fixture set B Fixture set C アカウント作成前 アカウント作成後 継続利用中 ・Company ・User ・Result ・Company ・User A,B,C... ・Result A,B, C... ・Company ・User A,B,C... ・Result A,B, C... ・Company ・User A,B,C... ・Result A,B, C... ・・・・・・・・・・・・・・・・・・・・・・・・・・
FixtureBuilder FixtureBuilder ・・・・・・・・・・・・・・・・・・・・・・・・・・・
My QA System Architecture Fixtureを用いたテスト基盤 Fixtureの体験を向上するため,2つの仕組みを構築 Fixture Builder Fixture Viewer
・・・・・・・・・・・・・・・・・・・・・・・・・・・・
Fixture FactoryBot Builder My QA System Architecture Fixtureを用いたQAデータ基盤 Viewer ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
FixtureViewer FixtureViewer シナリオ一覧 基盤のメインデータ 細々としたFixtureデータ ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
FixtureViewer FixtureViewer ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
My QA System Architecture Fixtureを用いたテスト基盤 Testのみならず、 開発環境(やQA環境)でのデータとしても活用できる Fixture Test FactoryBot
Builder Develop Seed Viewer ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
My QA System Architecture Fixtureによるテストコード削減効果 ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
Fixture FactoryBot 0 1 2 3 柔軟性 前提の明示性 共通データの再利用性 変更影響の局所化
実行速度 Benchmark two methods FixtureとFactoryBotを一緒に使おう デメリットを最小化し、メリットを最大化 ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
Today’s goals 本日のゴール TARGET: Fixtureについてよく知らない方 FactoryBotしか使った事がない方 GOAL: Fixtureという機能を知る Railsにおけるバックエンドテスト基盤の選択肢を増やす 少しでもFixtureが良いなと思ってもらえることを目指します!
|オススメ動画| ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
35 examples, 0 failures Thank you