Skip to content

Instantly share code, notes, and snippets.

@shicholas
Last active August 29, 2015 14:01
Show Gist options
  • Save shicholas/810d8debe5579b5058fb to your computer and use it in GitHub Desktop.
Save shicholas/810d8debe5579b5058fb to your computer and use it in GitHub Desktop.
Checkout Specs
RSpec.shared_examples 'not advance without payment info' do
it 'does not let user advance without payment info' do
click_button 'Preview'
expect(page).to have_content 'Must input payment info'
end
end
require 'features_spec_helper'
feature 'Checkout#Payment' do
before do
include_context 'checkout up to payment'
end
describe 'failing conditions that do not take user to #confirm' do
user_can 'not advance without payment info'
user_can 'not advance with failed Braintree payment'
end
describe 'succeeding conditions that take user to #confirm' do
user_can 'advance with successful VISA'
user_can 'advance with successful Mastercard'
user_can 'advance with successful Paypal'
end
end
RSpec.configure do |c|
c.alias_it_should_behave_like_to :user_can, 'user can:'
end

I think our checkout specs are tangled because they try to encapsulate a lot of actions within each test (i.e. a specify or it block). I think we should instead break each direction a user could go into an RSpec shared example and write one test per checkout state (i.e. address, shipping, payment, confirmation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment