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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Lucas Marinho
July 06, 2013
Programming
1
210
RSpec Love
Compartilho 10 dicas para melhorar os seus Specs. Referência: betterspecs.org
Lucas Marinho
July 06, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
CSC307 Lecture 08
javiergs
PRO
0
670
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
MUSUBIXとは
nahisaho
0
130
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
210
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
120
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
CSC307 Lecture 03
javiergs
PRO
1
490
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
64
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
160
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Navigating Team Friction
lara
192
16k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
Design in an AI World
tapps
0
140
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