SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Tips for better tests
Oto Brglez / March 2014
otobrglez.opalab.com
#1 Describing methods?
describe 'the authenticate method for User' do
describe 'if the user is an admin' do
describe '.authenticate' do
describe '#admin?' do
#2 Missing some context?
it 'has 200 status code if logged in' do
expect(response).to respond_with 200
end
it 'has 401 status code if not logged in' do
expect(response).to respond_with 401
end
context 'when logged in' do
it { should respond_with 200 }
end
context 'when logged out' do
it { should respond_with 401 }
end
#3 Descriptions...
it 'has 422 status code if an unexpected params will be added' do
context 'when not valid' do
it { should respond_with 422 }
end
#4 Who?
it { expect(assigns('message')).to match /it was born in Maribor/ }
it { expect(assigns('message').creator).to match /Ljubljana/ }
subject { assigns('message') }
it { should match /it was born in Ljubljana/ }
#5 Be lazy...
describe '#type_id' do
before { @resource = FactoryGirl.create :device }
before { @type = Type.find @resource.type_id }
it 'sets the type_id field' do
expect(@resource.type_id).to equal(@type.id)
end
end
describe '#type_id' do
let(:resource) { FactoryGirl.create :device }
let(:type) { Type.find resource.type_id }
it 'sets the type_id field' do
expect(resource.type_id).to equal(type.id)
end
end
#6 See this a lot?
user = User.create(
first_name: 'Oto',
last_name: 'Brglez',
country: 'Slovenia',
email: 'otobrglez@gmail.com' ,
active: true
)
user = FactoryGirl.create :user
#7 Can’t remember...
lambda { model.save! }.to raise_error Mongoid::Errors::DocumentNotFound
expect { model.save! }.to raise_error Mongoid::Errors::DocumentNotFound
#8 But it works just like...
describe 'GET /devices' do
let!(:resource ) { FactoryGirl .create :device, created_from : user.id }
let(:uri) { '/devices' }
context 'when shows all resources' do
let!( :not_owned ) { FactoryGirl .create factory }
it 'shows all owned resources' do
page.driver.get uri
expect(page.status_code).to be( 200)
contains_owned_resource resource
does_not_contain_resource not_owned
end
end
describe '?start=:uri' do
it 'shows the next page' do
page.driver.get uri, start : resource.uri
expect(page.status_code).to be( 200)
contains_resource resources.first
expect(page).to_not have_content resource.id.to_s
end
end
end
describe 'GET /devices' do
let!(:resource) { FactoryGirl.create :device }
let(:uri) { '/devices' }
it_behaves_like 'a listable resource'
it_behaves_like 'a paginable resource'
it_behaves_like 'a searchable resource'
it_behaves_like 'a filterable list'
end
#9 Me, you, him? When?
it 'should not change timings' do
consumption.occur_at.should == valid.occur_at
end
it 'does not change timings' do
expect(consumption.occur_at).to equal(valid.occur_at)
end
#10 I don’t have the time...
rspec spec/models/user_spec.rb
1. bundle exec guard # or zeus, spork, spin
2. rspec spec/models/user_spec.rb -l 10
3. rspec --no-drb spec/models/*
#11 External is slow. :/
require 'open-uri'
file = open('http://otobrglez.opalab.com')
contents = file.read
puts contents
context "blog" do
let(:uri) { 'http://otobrglez.opalab.com' }
before { stub_request(:get, uri).to_return(status: 200, body: fixture('home.html'))
}
it "gets home page" do
# magic here...
expect(page).to have_content 'Oto Brglez'
end
end
What else?
1. Use formatters
2. Test what you see
3. Test edge-cases
4. Learn how to mock/stub
5. Decuple your code
6. Think about CI
7. Keep your tests fast and readable
8. Learn from OS projects
Thanks
Inspired by betterspecs.org and nasty test suites.
Read my blog; and be ql.
- Oto

Mais conteúdo relacionado

Mais procurados

If songs were lines in a conversation. Nick Drake
If songs were lines in a conversation. Nick DrakeIf songs were lines in a conversation. Nick Drake
If songs were lines in a conversation. Nick DrakePseudoplastik
 
Cartilla - Cáncer de mama
Cartilla - Cáncer de mamaCartilla - Cáncer de mama
Cartilla - Cáncer de mamaUNFPA Boliva
 
OE 42 boycott of virani moti's shantidas bapu for pro satpanth activities
OE 42  boycott of virani moti's shantidas bapu for pro satpanth activitiesOE 42  boycott of virani moti's shantidas bapu for pro satpanth activities
OE 42 boycott of virani moti's shantidas bapu for pro satpanth activitiesSatpanth Dharm
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty HammerBen Scofield
 
A Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift LiteralA Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift Literal秋 勇紀
 
Создание собственных сущностей с использованием Entity API
Создание собственных сущностей с использованием Entity APIСоздание собственных сущностей с использованием Entity API
Создание собственных сущностей с использованием Entity APIDrupalForumZP2012
 

Mais procurados (8)

If songs were lines in a conversation. Nick Drake
If songs were lines in a conversation. Nick DrakeIf songs were lines in a conversation. Nick Drake
If songs were lines in a conversation. Nick Drake
 
Cartilla - Cáncer de mama
Cartilla - Cáncer de mamaCartilla - Cáncer de mama
Cartilla - Cáncer de mama
 
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part22. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value) part2
 
OE 42 boycott of virani moti's shantidas bapu for pro satpanth activities
OE 42  boycott of virani moti's shantidas bapu for pro satpanth activitiesOE 42  boycott of virani moti's shantidas bapu for pro satpanth activities
OE 42 boycott of virani moti's shantidas bapu for pro satpanth activities
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
 
A Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift LiteralA Deeper Deep Dive into Swift Literal
A Deeper Deep Dive into Swift Literal
 
Quality code by design
Quality code by designQuality code by design
Quality code by design
 
Создание собственных сущностей с использованием Entity API
Создание собственных сущностей с использованием Entity APIСоздание собственных сущностей с использованием Entity API
Создание собственных сущностей с использованием Entity API
 

Semelhante a Oto Brglez - Tips for better tests

JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom ComponentsMichael Fons
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014Guillaume POTIER
 
Nedap Rails Workshop
Nedap Rails WorkshopNedap Rails Workshop
Nedap Rails WorkshopAndre Foeken
 
Simple Web Apps With Sinatra
Simple Web Apps With SinatraSimple Web Apps With Sinatra
Simple Web Apps With Sinatraa_l
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.Adeoye Akintola
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & liesTareque Hossain
 
Solving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with RailsSolving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with Railsfreelancing_god
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsMatt Follett
 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)Joel Lord
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
 
Fixture Replacement Plugins
Fixture Replacement PluginsFixture Replacement Plugins
Fixture Replacement PluginsPaul Klipp
 
Schema design short
Schema design shortSchema design short
Schema design shortMongoDB
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportBen Scofield
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015Fernando Daciuk
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and DashboardsAtlassian
 

Semelhante a Oto Brglez - Tips for better tests (20)

RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
 
JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom Components
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014
 
Nedap Rails Workshop
Nedap Rails WorkshopNedap Rails Workshop
Nedap Rails Workshop
 
Simple Web Apps With Sinatra
Simple Web Apps With SinatraSimple Web Apps With Sinatra
Simple Web Apps With Sinatra
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & lies
 
Solving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with RailsSolving the Riddle of Search: Using Sphinx with Rails
Solving the Riddle of Search: Using Sphinx with Rails
 
Perl: Hate it for the Right Reasons
Perl: Hate it for the Right ReasonsPerl: Hate it for the Right Reasons
Perl: Hate it for the Right Reasons
 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
 
68837.ppt
68837.ppt68837.ppt
68837.ppt
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
Fixture Replacement Plugins
Fixture Replacement PluginsFixture Replacement Plugins
Fixture Replacement Plugins
 
Schema design short
Schema design shortSchema design short
Schema design short
 
And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 

Mais de Oto Brglez

The Compression Puzzle Challenge
The Compression Puzzle ChallengeThe Compression Puzzle Challenge
The Compression Puzzle ChallengeOto Brglez
 
Becoming S/W Engineer
Becoming S/W EngineerBecoming S/W Engineer
Becoming S/W EngineerOto Brglez
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with ScalaOto Brglez
 
How to over-engineer things and have fun? Building a modern, distributed real...
How to over-engineer things and have fun? Building a modern, distributed real...How to over-engineer things and have fun? Building a modern, distributed real...
How to over-engineer things and have fun? Building a modern, distributed real...Oto Brglez
 
Kdaj lahko uporabimo piškotke?
Kdaj lahko uporabimo piškotke?Kdaj lahko uporabimo piškotke?
Kdaj lahko uporabimo piškotke?Oto Brglez
 
Continuous integration (CI) v praksi
Continuous integration (CI) v praksiContinuous integration (CI) v praksi
Continuous integration (CI) v praksiOto Brglez
 
Ruby in prijatelji
Ruby in prijateljiRuby in prijatelji
Ruby in prijateljiOto Brglez
 
Ruby in ogrodje Rails
Ruby in ogrodje RailsRuby in ogrodje Rails
Ruby in ogrodje RailsOto Brglez
 
Subversion in Redmine implementacija
Subversion in Redmine implementacijaSubversion in Redmine implementacija
Subversion in Redmine implementacijaOto Brglez
 
mojakoda.si - predstavitev
mojakoda.si - predstavitevmojakoda.si - predstavitev
mojakoda.si - predstavitevOto Brglez
 
Šolski Spletni Informacijski Sistem
Šolski Spletni Informacijski SistemŠolski Spletni Informacijski Sistem
Šolski Spletni Informacijski SistemOto Brglez
 
PHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor IntroductionPHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor IntroductionOto Brglez
 
Java Servlet in JSP
Java Servlet in JSPJava Servlet in JSP
Java Servlet in JSPOto Brglez
 

Mais de Oto Brglez (15)

The Compression Puzzle Challenge
The Compression Puzzle ChallengeThe Compression Puzzle Challenge
The Compression Puzzle Challenge
 
Becoming S/W Engineer
Becoming S/W EngineerBecoming S/W Engineer
Becoming S/W Engineer
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
 
How to over-engineer things and have fun? Building a modern, distributed real...
How to over-engineer things and have fun? Building a modern, distributed real...How to over-engineer things and have fun? Building a modern, distributed real...
How to over-engineer things and have fun? Building a modern, distributed real...
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
Kdaj lahko uporabimo piškotke?
Kdaj lahko uporabimo piškotke?Kdaj lahko uporabimo piškotke?
Kdaj lahko uporabimo piškotke?
 
Continuous integration (CI) v praksi
Continuous integration (CI) v praksiContinuous integration (CI) v praksi
Continuous integration (CI) v praksi
 
nanob
nanobnanob
nanob
 
Ruby in prijatelji
Ruby in prijateljiRuby in prijatelji
Ruby in prijatelji
 
Ruby in ogrodje Rails
Ruby in ogrodje RailsRuby in ogrodje Rails
Ruby in ogrodje Rails
 
Subversion in Redmine implementacija
Subversion in Redmine implementacijaSubversion in Redmine implementacija
Subversion in Redmine implementacija
 
mojakoda.si - predstavitev
mojakoda.si - predstavitevmojakoda.si - predstavitev
mojakoda.si - predstavitev
 
Šolski Spletni Informacijski Sistem
Šolski Spletni Informacijski SistemŠolski Spletni Informacijski Sistem
Šolski Spletni Informacijski Sistem
 
PHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor IntroductionPHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor Introduction
 
Java Servlet in JSP
Java Servlet in JSPJava Servlet in JSP
Java Servlet in JSP
 

Último

tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 

Último (20)

tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

Oto Brglez - Tips for better tests

  • 1. Tips for better tests Oto Brglez / March 2014 otobrglez.opalab.com
  • 2. #1 Describing methods? describe 'the authenticate method for User' do describe 'if the user is an admin' do describe '.authenticate' do describe '#admin?' do
  • 3. #2 Missing some context? it 'has 200 status code if logged in' do expect(response).to respond_with 200 end it 'has 401 status code if not logged in' do expect(response).to respond_with 401 end context 'when logged in' do it { should respond_with 200 } end context 'when logged out' do it { should respond_with 401 } end
  • 4. #3 Descriptions... it 'has 422 status code if an unexpected params will be added' do context 'when not valid' do it { should respond_with 422 } end
  • 5. #4 Who? it { expect(assigns('message')).to match /it was born in Maribor/ } it { expect(assigns('message').creator).to match /Ljubljana/ } subject { assigns('message') } it { should match /it was born in Ljubljana/ }
  • 6. #5 Be lazy... describe '#type_id' do before { @resource = FactoryGirl.create :device } before { @type = Type.find @resource.type_id } it 'sets the type_id field' do expect(@resource.type_id).to equal(@type.id) end end describe '#type_id' do let(:resource) { FactoryGirl.create :device } let(:type) { Type.find resource.type_id } it 'sets the type_id field' do expect(resource.type_id).to equal(type.id) end end
  • 7. #6 See this a lot? user = User.create( first_name: 'Oto', last_name: 'Brglez', country: 'Slovenia', email: 'otobrglez@gmail.com' , active: true ) user = FactoryGirl.create :user
  • 8. #7 Can’t remember... lambda { model.save! }.to raise_error Mongoid::Errors::DocumentNotFound expect { model.save! }.to raise_error Mongoid::Errors::DocumentNotFound
  • 9. #8 But it works just like... describe 'GET /devices' do let!(:resource ) { FactoryGirl .create :device, created_from : user.id } let(:uri) { '/devices' } context 'when shows all resources' do let!( :not_owned ) { FactoryGirl .create factory } it 'shows all owned resources' do page.driver.get uri expect(page.status_code).to be( 200) contains_owned_resource resource does_not_contain_resource not_owned end end describe '?start=:uri' do it 'shows the next page' do page.driver.get uri, start : resource.uri expect(page.status_code).to be( 200) contains_resource resources.first expect(page).to_not have_content resource.id.to_s end end end describe 'GET /devices' do let!(:resource) { FactoryGirl.create :device } let(:uri) { '/devices' } it_behaves_like 'a listable resource' it_behaves_like 'a paginable resource' it_behaves_like 'a searchable resource' it_behaves_like 'a filterable list' end
  • 10. #9 Me, you, him? When? it 'should not change timings' do consumption.occur_at.should == valid.occur_at end it 'does not change timings' do expect(consumption.occur_at).to equal(valid.occur_at) end
  • 11. #10 I don’t have the time... rspec spec/models/user_spec.rb 1. bundle exec guard # or zeus, spork, spin 2. rspec spec/models/user_spec.rb -l 10 3. rspec --no-drb spec/models/*
  • 12. #11 External is slow. :/ require 'open-uri' file = open('http://otobrglez.opalab.com') contents = file.read puts contents context "blog" do let(:uri) { 'http://otobrglez.opalab.com' } before { stub_request(:get, uri).to_return(status: 200, body: fixture('home.html')) } it "gets home page" do # magic here... expect(page).to have_content 'Oto Brglez' end end
  • 13. What else? 1. Use formatters 2. Test what you see 3. Test edge-cases 4. Learn how to mock/stub 5. Decuple your code 6. Think about CI 7. Keep your tests fast and readable 8. Learn from OS projects
  • 14. Thanks Inspired by betterspecs.org and nasty test suites. Read my blog; and be ql. - Oto