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
Testing Spree Stores and Extensions - M. Scott ...
Search
spreeconf
August 22, 2012
Programming
1
410
Testing Spree Stores and Extensions - M. Scott Ford
spreeconf
August 22, 2012
Tweet
Share
More Decks by spreeconf
See All by spreeconf
Capitalizing on the Micro-preneur Revolution - Eric Koester
spreeconf
0
160
Design Patterns of Successful eCommerce Companies - Adil Wali
spreeconf
0
650
The Magic Tricks of Testing - Sandi Metz
spreeconf
0
260
Evolving Open Source - Yehuda Katz
spreeconf
2
250
Enterprise Spree - Daniel Honig
spreeconf
1
650
Scaling an eCommerce Business - Adil Wali
spreeconf
1
540
Other Decks in Programming
See All in Programming
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
イベント駆動で成長して委員会
happymana
1
330
CSC509 Lecture 09
javiergs
PRO
0
140
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
CSC509 Lecture 12
javiergs
PRO
0
160
Arm移行タイムアタック
qnighy
0
330
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Music & Morning Musume
bryan
46
6.2k
Bash Introduction
62gerente
608
210k
The Cult of Friendly URLs
andyhume
78
6k
Unsuck your backbone
ammeep
668
57k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Faster Mobile Websites
deanohume
305
30k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Transcript
Testing Spree Stores and Extensions M. Scott Ford Software Engineer
Cardagin Networks
About me
None
0:23
None
If my code failed people could die
Structure of the talk Four parts: 1. Why test? 2.
Testing best practices 3. Testing Spree stores 4. Testing Spree extensions
Why Test?
Why is Testing Important?
Safety Critical vs. Mission Critical
Safety Critical If my code fails, people could die.
Safety Critical Aircraft and Spacecraft
Safety Critical Emergency Response Systems
Safety Critical Passenger Rail
Mission Critical If my code fails, business is impacted.
Mission Critical Mars Science Lab Landing
Mission Critical Stock Trading Software
Mission Critical E-Commerce
Why Don't We Test More Often?
Why don't we test more often? "Testing is frustrating."
Why don't we test more often? "I don't see the
benefit"
Why don't we test more often? "I don't have time"
Why Test? Summary Why is Testing Important? Safety critical vs.
Mission critical Why Don't We Test More Often?
Best Practices
Test First vs. Test Last
Different Levels of Testing These are the kinds of tests
that this talk is going to cover Acceptance Integration Unit
Other Kinds of Tests These tests are important, but we
don’t have enough time to go into them here. Security Performance Exploratory
Properties of a Good Test Reads like a story (beginning,
middle, and end) Easy to read and understand what’s being tested
Tool Choice Cucumber vs. RSpec vs. Test::Unit vs. others
Tips for Consultants Don’t list testing as on giant line
item in your estimate Don’t make testing optional Let your client's risk tolerance dictate how much you test
Best Practices Summary Test first vs. test last Properties of
a good test Different levels of testing Tool choice Tips for consultants
Testing Spree Stores http://github/mscottford/sample-store
Getting Started Create a new spree store project with RSpec
and Capybara http://github.com/mscottford/sample-store branch: master
Create a Rails App $ gem install rails -v 3.2.8
$ rails _3.2.8_ new sample-store --skip-test- unit
Add Spree $ echo "gem 'spree', '~> 1.1.0'" >> Gemfile
$ bundle update $ rails g spree:install $ echo "/public/spree" >> .gitignore
Add RSpec and Capybara Gemfile: group :test do gem 'rspec-rails'
gem 'capybara' gem 'database_cleaner' gem 'factory_girl' gem 'faker' end
Add RSpec and Capybara $ bundle update $ rails g
rspec:install
Configure RSpec Add to spec_helper.rb, right before RSpec.configure: require 'database_cleaner'
require 'spree/core/testing_suppo rt/factories' require 'spree/core/testing_suppo rt/env' require 'spree/core/testing_suppo rt/controller_requests' require 'spree/core/url_helpers'
Configure RSpec In spec_helper.rb, change: config.use_transactional_ fixtures = true to:
config.use_transactional_ fixtures = false
Configure RSpec In spec_helper.rb inside RSpec.configure block, add: config.before(:each) do
if example.metadata[:js] DatabaseCleaner.strateg y = :truncation, { :except => [ 'spree_countries', 'spree_zones', 'spree_zone_members', 'spree_states', 'spree_roles' ]} else
Configure RSpec In spec_helper.rb inside RSpec.configure block, add: config.before(:each) do
DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end
Configure RSpec In spec_helper.rb inside RSpec.configure block, add: config.include FactoryGirl::Syntax::Meth
ods config.include Spree::Core::UrlHelpers config.include Spree::Core::TestingSup port::ControllerRequests
A simple test to make sure it's working spec/requests/home_spec.rb: require
'spec_helper' describe 'home' do it 'should load home page' do visit '/' page.should have_content('Home') end end $ bundle exec rake db:test:prepare $ be rspec
Writing an Acceptance Test Example scenario: related products
Demo http://github.com/mscottford/sample-store branch: acceptance-test
Writing an Integration Test Example scenario: Adding a method to
Spree::Product.
Demo http://github.com/mscottford/sample-store branch: integration-test
Writing a unit test Example scenario: Adding a helper method
Testing Spree Stores Summary http://github.com/mscottford/sample-store Getting started - branch: master
Acceptance test - branch: acceptance-test Integration test - branch: integration-test Unit test - branch: unit-test
Testing Spree Extensions http://github.com/mscottford/spree_sample_extension
Getting Started http://github.com/mscottford/spree_sample_extension branch: master $ gem install spree_cmd $
spree extension sample_extension
Writing an Acceptance Test Scenario: Special Pricing
Demo http://github.com/mscottford/spree_sample_extension branch: acceptance-test
Writing an Integration Test Scenario: Special pricing for select products
Demo http://github.com/mscottford/spree_sample_extension branch: integration-test
Writing a unit test Scenario: Adding a helper to remove
duplication
Demo http://github.com/mscottford/spree_sample_extension branch: unit-test
Testing Spree Extensions Summary http://github.com/mscottford/spree_sample_extension Getting started - branch: master
Acceptance test - branch: acceptance-test Integration test - branch: integration-test Unit test - branch: unit-test
Testing Spree Stores and Extensions Summary Why Test? Best Practices
Testing Spree Stores Testing Spree Extensions
Additional resources Read the Spree RSpec tests http://github.com/spree/spree Developing Spree
Extension with TDD http://nebulab.it/en/nebulog/developing-spree- extension-with-tdd
Additional resources Presentation http://github.com/mscottford/testing-spree-stores- and-extensions Sample Store code http://github.com/mscottford/sample-store Sample
Extension code http://github.com/mscottford/spree_sample_extension
Contact info email:
[email protected]
github: mscottford twitter: @mscottford blog: http://mscottford.com
Questions?