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
260
Enterprise Spree - Daniel Honig
spreeconf
1
660
Scaling an eCommerce Business - Adil Wali
spreeconf
1
550
Other Decks in Programming
See All in Programming
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
190
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.1k
命名をリントする
chiroruxx
1
410
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
선언형 UI에서의 상태관리
l2hyunwoo
0
170
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
Go の GC の不得意な部分を克服したい
taiyow
3
790
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
Featured
See All Featured
Fireside Chat
paigeccino
34
3.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
A Tale of Four Properties
chriscoyier
157
23k
Raft: Consensus for Rubyists
vanstee
137
6.7k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
A Philosophy of Restraint
colly
203
16k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
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?