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
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
dRuby over BLE
makicamel
2
400
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.5k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
300
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
280
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
160
スマートグラスで並列バイブコーディング
hyshu
0
270
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
150
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
220
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
400
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
230
How to Ace a Technical Interview
jacobian
281
24k
Visualization
eitanlees
152
17k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
210
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Leo the Paperboy
mayatellez
7
1.9k
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