Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RSpec Love
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Lucas Marinho
July 06, 2013
Programming
230
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RSpec Love
Compartilho 10 dicas para melhorar os seus Specs. Referência: betterspecs.org
Lucas Marinho
July 06, 2013
Other Decks in Programming
See All in Programming
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
1
590
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
330
JavaDoc 再入門
nagise
1
430
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
320
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
180
AIで効率化できた業務・日常
ochtum
0
160
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Inside Stream API
skrb
1
810
Creating Composable Callables in Contemporary C++
rollbear
0
180
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.5k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
770
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Claude Code のすすめ
schroneko
67
230k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
My Coaching Mixtape
mlcsv
0
160
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Writing Fast Ruby
sferik
630
63k
Transcript
RSpec Love @lmarinho
None
RSpec Love @lmarinho
None
RSpec Love @lmarinho
RSpec Love @lmarinho
RSpec Love @lmarinho
Code Spec
None
None
DISCLAIMER: É SÓ A MINHA OPINIÃO
None
Use expect foo.should eq(bar) foo.should_not eq(bar)
Use expect expect(foo).to eq(bar) expect(foo).not_to eq(bar)
Use expect .should class Proxy < BasicObject def initialize(target) @target
= target end def method_missing(*args, &block) @target.__send__(*args, &block) end ... end
None
Use describe Referencia estrutura do código testado
Use describe describe MyClass do ... describe ‘#method’ do ...
describe ‘.class_method’ do ...
None
Use context Define um estado ou entrada no sistema
Use context context ‘when the user has no username’ do
... context ‘when the account balance is 0.0’ do ...
None
Contexto Expectativa
Use let Let ajuda a definir nomes relacionados a contextos
Use let let(:email) { ‘
[email protected]
’ }
Use let let(:email) { ‘
[email protected]
’ } let(:user) { User.new(email: email)
} context ‘when there is no email’ do let(:email) { ‘’ } it ‘is invalid’ do expect(user).to be_invalid end end
Use let Prefira ‘let’ a ‘before’, pois o primeiro é
lazy-loaded
None
Use subject Subject ajuda a evitar repetição de referências
Use subject describe User do it ‘has the expected attributes’
do user = User.new expect(user).to respond_to :name expect(user).to respond_to :email expect(user).to respond_to :age end end
Use subject describe User do subject { User.new } it
{ should respond_to :name } it { should respond_to :email } it { should respond_to :age } end
None
Use “skim its” Skim milk < 0.3% gordura Skim it
1 expectation & < 4 LOC
None
Crie métodos Métodos ajudam a evitar repetições desnecessárias
Crie métodos it { should_create_report_named('Volume Evolution') } it { should_create_report_named('Top
Users') } it { should_create_report_named('Top Terms') } it { should_create_report_named('Gender Report') }
Crie métodos Métodos também ajudam a evitar loops em specs
None
Reuse specs É possível reusar specs através de shared_examples
Reuse specs shared_examples ‘a collection’ do let(:collection) { described_class.new([7, 2,
4]) } context ‘when initialized with 3 items’ do it ‘says it has three items’ do expect(collection.size).to eq(3) end end end
Reuse specs describe Array do it_behaves_like ‘a collection’ end describe
Set do it_behaves_like ‘a collection’ end
None
Use factories As vezes...
Use factories Pois FactoryGirl é legal!
None
Use mocks? Mock-based tests are more coupled to the interfaces
in your system, while classical tests are more coupled to the implementation of an object’s collaborators. -- Myron Marston
0
None
Perguntas?
Referências betterspecs.org e links associados