SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 

Último (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

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