Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Created April 28, 2015 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrypoydar/04456f39ae670d600584 to your computer and use it in GitHub Desktop.
Save henrypoydar/04456f39ae670d600584 to your computer and use it in GitHub Desktop.
spec/rails_helper.rb, spec/support/network.rb, spec/support/macros/feature_macros.rb
module FeatureMacros
def fill_in_stripe_checkout_form(kind = 'Visa')
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
within_frame stripe_iframe do
case kind
when 'MasterCard'
3.times {page.driver.browser.find_element(:id, 'card_number').send_keys('5555')}
1.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4444')}
when 'Visa_declined'
# 4000 0000 0000 0119
1.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4000')}
2.times {page.driver.browser.find_element(:id, 'card_number').send_keys('0000')}
1.times {page.driver.browser.find_element(:id, 'card_number').send_keys('0119')}
else
4.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4242')}
end
page.driver.browser.find_element(:id, 'cc-exp').send_keys '5'
page.driver.browser.find_element(:id, 'cc-exp').send_keys '24'
page.driver.browser.find_element(:id, 'cc-csc').send_keys '123'
page.driver.browser.find_element(:id, 'submitButton').click
end
sleep 5
end
end
# Puffing Billy caches external requests made by JS calls
# in the DOM. To clear the cache, simply remove the files
# in spec/support/request/cache.
#
# Makes test faster since we hit Google fonts and some Stripe
# calls via the DOM.
#
# Specs that hit the Stripe checkout form are tagged as
# :stripe_checkout_form so they can be ignored in CI and
# only run as needed. These requests have numerous chained calls
# with cache-busting JSONP and slow down the build significantly.
# Let's assume Stripe tests their forms - we don't need to do that
# for them.
Billy.configure do |c|
c.cache = true
c.cache_request_headers = true
c.persist_cache = true
c.cache_path = 'spec/support/request_cache/'
end
Capybara.javascript_driver = :selenium_billy
# We need WebMock in some request specs, but disabling net connections
# completely - even allowing them for localhost - conflicts with Puffing Billy
WebMock.allow_net_connect!
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'shoulda/matchers'
require 'stripe_mock'
require 'billy/rspec'
require 'webmock/rspec'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Database cleaner for this. See hooks.rb
config.use_transactional_fixtures = false
config.include Devise::TestHelpers, type: :controller
config.include FactoryGirl::Syntax::Methods
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
# Extend (outside examples) custom macros for controller specs
config.extend ControllerMacros, type: :controller
# Include (within examples) custom macros for integration specs
config.include FeatureMacros, type: :feature
config.infer_spec_type_from_file_location!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment