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 Ford
Search
spreeconf
August 22, 2012
Programming
1
400
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
150
Design Patterns of Successful eCommerce Companies - Adil Wali
spreeconf
0
640
The Magic Tricks of Testing - Sandi Metz
spreeconf
0
240
Evolving Open Source - Yehuda Katz
spreeconf
2
250
Enterprise Spree - Daniel Honig
spreeconf
1
630
Scaling an eCommerce Business - Adil Wali
spreeconf
1
530
Other Decks in Programming
See All in Programming
Semantic search with Django and pgvector
pauloxnet
0
240
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
2
120
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
670
Fragment Composition of GraphQL
quramy
4
790
VS Code をプロダクトにどう取り込むか
onomax
1
360
Milestoner
bkuhlmann
1
410
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
950
PHPはいつから死んでいるかの調査
chiroruxx
1
400
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
120
Elm 0.19.0 Changes
bkuhlmann
0
490
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
300
Featured
See All Featured
Debugging Ruby Performance
tmm1
70
11k
10 Git Anti Patterns You Should be Aware of
lemiorhan
648
58k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
Testing 201, or: Great Expectations
jmmastey
28
6.3k
In The Pink: A Labor of Love
frogandcode
138
21k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
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?