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
420
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
270
Evolving Open Source - Yehuda Katz
spreeconf
2
270
Enterprise Spree - Daniel Honig
spreeconf
1
660
Scaling an eCommerce Business - Adil Wali
spreeconf
1
550
Other Decks in Programming
See All in Programming
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
Spring gRPC について / About Spring gRPC
mackey0225
0
220
チームリードになって変わったこと
isaka1022
0
200
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
1
140
もう僕は OpenAPI を書きたくない
sgash708
4
1.3k
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
46
16k
Rails アプリ地図考 Flush Cut
makicamel
1
120
sappoRo.R #12 初心者セッション
kosugitti
0
250
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.7k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
100
Pulsar2 を雰囲気で使ってみよう
anoken
0
230
負債になりにくいCSSをデザイナとつくるには?
fsubal
9
2.4k
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Designing Experiences People Love
moore
140
23k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Building Adaptive Systems
keathley
40
2.4k
The Language of Interfaces
destraynor
156
24k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
How GitHub (no longer) Works
holman
314
140k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.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?