run stripe feature test only if key is set

This commit is contained in:
Rishabh Saxena 2016-08-17 23:57:40 +05:30
parent cc09dd76ba
commit 4152cb242c
2 changed files with 31 additions and 27 deletions

View file

@ -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

View file

@ -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