From 4152cb242c1fe94b07aece86951f0024511488bd Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Wed, 17 Aug 2016 23:57:40 +0530 Subject: [PATCH] run stripe feature test only if key is set --- spec/features/ticket_purchases_spec.rb | 56 ++++++++++++++------------ spec/support/external_request.rb | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/spec/features/ticket_purchases_spec.rb b/spec/features/ticket_purchases_spec.rb index d7161961..d2eadfc9 100644 --- a/spec/features/ticket_purchases_spec.rb +++ b/spec/features/ticket_purchases_spec.rb @@ -33,21 +33,23 @@ feature Registration do purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first expect(purchase.quantity).to eq(2) - find('.stripe-button-el').click + if Rails.application.secrets.stripe_publishable_key + find('.stripe-button-el').click - stripe_iframe = all('iframe[name=stripe_checkout_app]').last - sleep(5) - Capybara.within_frame stripe_iframe do - expect(page).to have_content('book your tickets') - page.execute_script(%{ $('input#card_number').val('4242424242424242'); }) - page.execute_script(%{ $('input#cc-exp').val('08/22'); }) - page.execute_script(%{ $('input#cc-csc').val('123'); }) - page.execute_script(%{ $('#submitButton').click(); }) - sleep(20) + stripe_iframe = all('iframe[name=stripe_checkout_app]').last + sleep(5) + Capybara.within_frame stripe_iframe do + expect(page).to have_content('book your tickets') + page.execute_script(%{ $('input#card_number').val('4242424242424242'); }) + page.execute_script(%{ $('input#cc-exp').val('08/22'); }) + page.execute_script(%{ $('input#cc-csc').val('123'); }) + page.execute_script(%{ $('#submitButton').click(); }) + sleep(20) + end + + expect(current_path).to eq(conference_conference_registration_path(conference.short_title)) + expect(page.has_content?("2 #{ticket.title} Tickets for $ 10")).to be true end - - expect(current_path).to eq(conference_conference_registration_path(conference.short_title)) - expect(page.has_content?("2 #{ticket.title} Tickets for $ 10")).to be true end scenario 'purchases ticket but payment fails', feature: true, js: true do @@ -67,21 +69,23 @@ feature Registration do purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first expect(purchase.quantity).to eq(2) - find('.stripe-button-el').click + if Rails.application.secrets.stripe_publishable_key + find('.stripe-button-el').click - stripe_iframe = all('iframe[name=stripe_checkout_app]').last - sleep(5) - Capybara.within_frame stripe_iframe do - expect(page).to have_content('book your tickets') - page.execute_script(%{ $('input#card_number').val('4000000000000341'); }) - page.execute_script(%{ $('input#cc-exp').val('08/22'); }) - page.execute_script(%{ $('input#cc-csc').val('123'); }) - page.execute_script(%{ $('#submitButton').click(); }) - sleep(20) + stripe_iframe = all('iframe[name=stripe_checkout_app]').last + sleep(5) + Capybara.within_frame stripe_iframe do + expect(page).to have_content('book your tickets') + page.execute_script(%{ $('input#card_number').val('4000000000000341'); }) + page.execute_script(%{ $('input#cc-exp').val('08/22'); }) + page.execute_script(%{ $('input#cc-csc').val('123'); }) + page.execute_script(%{ $('#submitButton').click(); }) + sleep(20) + end + + expect(current_path).to eq(conference_payments_path(conference.short_title)) + expect(flash).to eq('Your card was declined. Please try again with correct credentials.') end - - expect(current_path).to eq(conference_payments_path(conference.short_title)) - expect(flash).to eq('Your card was declined. Please try again with correct credentials.') end end end diff --git a/spec/support/external_request.rb b/spec/support/external_request.rb index 2de4ab08..645067aa 100644 --- a/spec/support/external_request.rb +++ b/spec/support/external_request.rb @@ -1,6 +1,6 @@ # Mock external requests to youtube require 'webmock/rspec' -WebMock.disable_net_connect!(allow_localhost: true, allow: %r{stripe.com}) +WebMock.disable_net_connect!(allow_localhost: true, allow: /stripe.com/) RSpec.configure do |config| config.before(:each) do