SlideShare a Scribd company logo
http://www.thinknetica.com
RSpec & Friends 2:
Parallel Tests
Controllers
Shared Groups
1
http://www.thinknetica.com
Parallel Tests
# Gemfile
group :development do
gem 'parallel_tests'
end
# Создаем и обновляем схему БД
rake parallel:create
rake parallel:prepare
# database.yml
test:
database: th_demo_test<%= ENV['TEST_ENV_NUMBER'] || ''%>
# Запускаем
DISABLE_SPRING=1 rake parallel:spec
2
http://www.thinknetica.com
Controllers
# Read/Delete methods
describe "GET #index" do
let(:params) { {} }
subject { get :index, params }
context "pagination" do
let(:params) { { page: 1, per_page: 2 } }
it "returns 2 items" do
expect(subject.body).to have_json_size(2).at_path("items")
end
end
end
3
http://www.thinknetica.com
Controllers
# Update methods
describe "POST #create" do
let(:form_params) { {} }
let(:params) do
{ format: :json, item: attributes_for(:item).merge(form_params) }
end
subject { post :create, params }
context "invalid params" do
let(:form_params) { { name: nil } }
it "doesn't create new item" do
expect { subject }.not_to change(Item, :count)
end
end
end
4
http://www.thinknetica.com
Shared Groups
5
Shared
Examples
Shared
Context
http://www.thinknetica.com
Shared Contexts
6
#./spec/shared_context/shared_users.rb
shared_context "users", users: true do
let(:user) { create(:user) }
let(:john) { create(:user, name: "John") }
let(:jack) { create(:user, name: "Jack") }
end
# подключение контекста
include_context "users"
# или с помощью тэгов
context "with users", :users do
# здесь нам доступны user, john и jack
end
http://www.thinknetica.com
 Примеры
7
shared_context "controller", type: :controller do
include_context "users"
end
shared_context "russian locale", ru: true do
around(:each) { |ex| I18n.with_locale(:ru, &ex) }
end
shared_context "english locale", en: true do
around(:each) { |ex| I18n.with_locale(:en, &ex) }
end
http://www.thinknetica.com
Shared Examples
8
# ./spec/shared_examples/valid_examples.rb
shared_examples "valid object" do
specify { is_expected.to be_valid }
end
#./spec/models/user_spec.rb
it_behaves_like "valid object"
# равносильно следующему коду
context "valid object" do
specify { is_expected.to be_valid }
end
http://www.thinknetica.com
 Примеры
9
shared_examples "invalid params" do |message, model: false, code:
403|
context message do
specify { expect(subject).to have_http_status(code) }
if model
specify { expect { subject }.not_to change(model, :count) }
end
end
end
include_examples "invalid params", "missing name", model: Item do
let(:form_params) { { name: nil } }
end

More Related Content

PDF
RSpec. Part 1
PDF
Rails-3-app-auto-generator-20100817
PDF
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
PDF
Damage Control
PDF
Ansible -new kid in configuration management world
KEY
Javascript orientado a testes
PPT
Redmine Betabeers SVQ
RSpec. Part 1
Rails-3-app-auto-generator-20100817
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Damage Control
Ansible -new kid in configuration management world
Javascript orientado a testes
Redmine Betabeers SVQ

What's hot (20)

PDF
The Peanut Butter Cup of Web-dev: Plack and single page web apps
KEY
Quality Use Of Plugin
PPTX
21.search in laravel
PDF
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
PDF
Documentation vs test about cucumber but not only for vegetarians
PDF
Adventurous Merb
KEY
Zen: Building Maintainable Catalyst Applications
PPT
シックス・アパート・フレームワーク
PPTX
Ruby on Rails + AngularJS + Twitter Bootstrap
PDF
Using Angular with Rails
PPTX
Lightning talk- testing
PPT
JavaScript on Rails 튜토리얼
KEY
The Joy of Gems: Cooking up Rails Plugins
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
PPTX
SPA using Rails & Backbone
PDF
Making and Breaking Web Services with Ruby
 
PDF
Continuous Deployment at Scale, Rootconf 2016
PPT
introduction to galaxy
PDF
Rails::Engine
PDF
Using ArcGIS Server with Ruby on Rails
The Peanut Butter Cup of Web-dev: Plack and single page web apps
Quality Use Of Plugin
21.search in laravel
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
Documentation vs test about cucumber but not only for vegetarians
Adventurous Merb
Zen: Building Maintainable Catalyst Applications
シックス・アパート・フレームワーク
Ruby on Rails + AngularJS + Twitter Bootstrap
Using Angular with Rails
Lightning talk- testing
JavaScript on Rails 튜토리얼
The Joy of Gems: Cooking up Rails Plugins
Rails 2.3 and Rack - NHRuby Feb 2009
SPA using Rails & Backbone
Making and Breaking Web Services with Ruby
 
Continuous Deployment at Scale, Rootconf 2016
introduction to galaxy
Rails::Engine
Using ArcGIS Server with Ruby on Rails
Ad

Viewers also liked (20)

PDF
Когда технологий много - iForum 2013
PPTX
Rails Concerns
PDF
Как сделать контрибут в Ruby on Rails
PDF
PDF
Assets Pipeline
PPT
Александр Тищенко - "Антикризисная презентация"
PDF
Debbug Rails Application For Dummies
PDF
Фронтенд для рубиста
PDF
10 reasons I love RubyOnRails
ODP
Alexander Dymo - IT Jam 2009 - Ruby: Beaty Or The Beast
PDF
Deploy.rb, Ilya Zykin, Rails club2016
PDF
RSpec. Part 3
ODP
Ruby on Rails for noobs
PPTX
развертывание среды Rails (антон веснин, Locum Ru)
PPTX
Призма24 - Маркетплейсы.
ODP
I18n ruby-приложений
PDF
Секретный доклад о React Router - OdessaJS 2014
PDF
Alexander Dymo - RubyConf 2014 - Ruby Performance Secrets and How to Uncover ...
PPTX
Why does code style matter?
PDF
Immutable servers with Packer/Chef/AWS
Когда технологий много - iForum 2013
Rails Concerns
Как сделать контрибут в Ruby on Rails
Assets Pipeline
Александр Тищенко - "Антикризисная презентация"
Debbug Rails Application For Dummies
Фронтенд для рубиста
10 reasons I love RubyOnRails
Alexander Dymo - IT Jam 2009 - Ruby: Beaty Or The Beast
Deploy.rb, Ilya Zykin, Rails club2016
RSpec. Part 3
Ruby on Rails for noobs
развертывание среды Rails (антон веснин, Locum Ru)
Призма24 - Маркетплейсы.
I18n ruby-приложений
Секретный доклад о React Router - OdessaJS 2014
Alexander Dymo - RubyConf 2014 - Ruby Performance Secrets and How to Uncover ...
Why does code style matter?
Immutable servers with Packer/Chef/AWS
Ad

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
PPTX
Lesson notes of climatology university.
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Presentation on HIE in infants and its manifestations
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
Institutional Correction lecture only . . .
master seminar digital applications in india
Lesson notes of climatology university.
102 student loan defaulters named and shamed – Is someone you know on the list?
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Presentation on HIE in infants and its manifestations
STATICS OF THE RIGID BODIES Hibbelers.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Final Presentation General Medicine 03-08-2024.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

RSpec. Part 2