Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Spree Stores and Extensions - M. Scott Ford

spreeconf
August 22, 2012

Testing Spree Stores and Extensions - M. Scott Ford

spreeconf

August 22, 2012
Tweet

More Decks by spreeconf

Other Decks in Programming

Transcript

  1. Structure of the talk Four parts: 1. Why test? 2.

    Testing best practices 3. Testing Spree stores 4. Testing Spree extensions
  2. Why Test? Summary Why is Testing Important? Safety critical vs.

    Mission critical Why Don't We Test More Often?
  3. Different Levels of Testing These are the kinds of tests

    that this talk is going to cover Acceptance Integration Unit
  4. Other Kinds of Tests These tests are important, but we

    don’t have enough time to go into them here. Security Performance Exploratory
  5. Properties of a Good Test Reads like a story (beginning,

    middle, and end) Easy to read and understand what’s being tested
  6. 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
  7. Best Practices Summary Test first vs. test last Properties of

    a good test Different levels of testing Tool choice Tips for consultants
  8. Getting Started Create a new spree store project with RSpec

    and Capybara http://github.com/mscottford/sample-store branch: master
  9. Create a Rails App $ gem install rails -v 3.2.8

    $ rails _3.2.8_ new sample-store --skip-test- unit
  10. Add Spree $ echo "gem 'spree', '~> 1.1.0'" >> Gemfile

    $ bundle update $ rails g spree:install $ echo "/public/spree" >> .gitignore
  11. Add RSpec and Capybara Gemfile: group :test do gem 'rspec-rails'

    gem 'capybara' gem 'database_cleaner' gem 'factory_girl' gem 'faker' end
  12. 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'
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. Testing Spree Stores and Extensions Summary Why Test? Best Practices

    Testing Spree Stores Testing Spree Extensions
  20. 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