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
1
180
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
CircleCIを活用して AWSへの継続的デリバリーを 実践する
coconala_engineer
1
110
TDDと今まで
kanayannet
0
140
The Future of C++ Interoperability: Insights from Porting a Game to Swift
teamhimeh
0
280
TCAの Shared Stateって どういう仕組みになってんの?
yimajo
0
330
Ruby製社内ツールのGo移行
bgpat
2
270
ファイル先頭の use の意味、説明できますか? 〜PHP の namespace と autoloading の関係を正しく理解しよう〜 / namespace and autoloading in php
okashoi
2
470
イベントストーミングによるオブジェクトモデリング・オブジェクト指向プログラミングの適用・開発プロセスの変遷・アーキテクチャの変革 / Object modeling with Event Storming.
nrslib
12
3.2k
DDD, necessary but insufficient: physical design principles for microservices
cer
PRO
0
2.2k
脱・初心者!脱・マネコン!AWS CDKを使ってみませんか!?
har1101
0
180
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
19k
デザインシステムで Tailwind CSSとCSS in JSに分散投資をしたら良かった話
fsubal
14
3.4k
チームでモデリングを育てるうえで 考えたこと・気づいたこと / Cultivating Modeling in Teams: Thoughts and Insights
mackey0225
5
2.4k
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
28
12k
What the flash - Photography Introduction
edds
64
11k
Code Reviewing Like a Champion
maltzj
512
39k
The Mythical Team-Month
searls
214
42k
GitHub's CSS Performance
jonrohan
1023
450k
Side Projects
sachag
451
41k
Writing Fast Ruby
sferik
619
59k
How GitHub Uses GitHub to Build GitHub
holman
467
290k
WebSockets: Embracing the real-time Web
robhawkes
59
6.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
343
19k
Atom: Resistance is Futile
akmur
258
25k
What's new in Ruby 2.0
geeforr
335
31k
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