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
Factorybotのtraitとtransientとevaluator
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
mashijifu
August 29, 2024
41
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Factorybotのtraitとtransientとevaluator
mashijifu
August 29, 2024
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Odyssey Design
rkendrick25
PRO
2
880
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Everyday Curiosity
cassininazir
0
360
Transcript
Factorybotͷtraitͱtransient ͱevaluator
traitͱ ʲׂʳ ϑΝΫτϦʔʹଐੑৼΔ͍ΛάϧʔϓԽͯ͠ఆٛ͢Δ͜ͱ͕Ͱ͖Δɻ ʲ༻໘ʳ ܾ·ͬͨଐੑͷςετσʔλΛ࡞͍ͨ͠ͱ͖ɻ
traitαϯϓϧίʔυ(ఆٛ) factory :user do name { “yamada taro" } trait
:email do email { “
[email protected]
” } end trait :age do age { 20 } end end
traitαϯϓϧίʔυ(͍ํ) describe "Api::V1::Mypage::Authorizations", type: :request do //͜ͷΑ͏ʹม࡞Ͱ༻Ͱ͖Δ let(:user) { create(:user,
:email, :age) } end
transientͱ ʲׂʳ Ұ࣌తͳଐੑΛఆٛ͢Δͱ͖ʹ༻Ͱ͖Δɻ ʲ༻໘ʳ ࡞͢ΔςετσʔλͷΛॊೈʹมߋ͍ͨ͠ͱ͖ɻ ಈతʹσʔλΛ࡞Ͱ͖ΔͨΊɺؔ࿈σʔλΛ࣋ͭϞσϧͷςετσʔλΛ࡞ ͍ͨ࣌͠ʹ͑Δɻ
evaluatorͱ ʲׂʳ transient Ͱఆٛͨ͠ଐੑΛɺafter(:create)ͳͲͷίʔϧόοΫͰऔಘ͢Δͷʹ ༻͢Δɻ ʲ༻໘ʳ ίʔϧόοΫͰ transient Ͱఆٛͨ͠ଐੑͷΛ༻͍ͨ͠ͱ͖ɻ
transientͱevaluatorαϯϓϧίʔυ factory :user do transient do has_books_count { 0 }
end after(:create) do |user, evaluator| create_list(:book, evaluator.has_books_count, user: user) if evaluator.has_books_count.positive? end end
·ͱΊ traitɺfactoryʹଐੑৼΔ͍ΛάϧʔϓԽͯ͠ఆٛ͢Δ͜ͱ͕Ͱ͖ΔͨΊɺܾ ·ͬͨଐੑͷςετσʔλΛ࡞͍ͨ࣌͠ʹ༻͢Δɻ transientɺҰ࣌తͳଐੑΛఆٛͰ͖ΔͨΊɺ࡞͢ΔςετσʔλͷΛॊೈʹม ߋ͍ͨ࣌͠ʹ༻͢Δɻ evaluatorɺtransientͰఆٛͨ͠ଐੑΛɺafter(:create)ͳͲͷίʔϧόοΫͰऔಘ Ͱ͖ΔͨΊɺίʔϧόοΫͰ transient Ͱఆٛͨ͠ଐੑͷΛऔಘ͢Δ࣌ʹ༻͢ Δɻ