$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RSpec Love
Search
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エージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
430
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
150
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
750
JETLS.jl ─ A New Language Server for Julia
abap34
1
410
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.7k
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
130
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
2
220
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
150
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.3k
AIコーディングエージェント(Gemini)
kondai24
0
240
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.2k
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
How GitHub (no longer) Works
holman
316
140k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.3k
Why Our Code Smells
bkeepers
PRO
340
57k
Raft: Consensus for Rubyists
vanstee
141
7.2k
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