require 'rails_helper' RSpec.describe 'Creating a new site subscription' do let(:site) { Site.make! } # Make sure you yield with the example object - we need it. it 'creates a new Stripe subscription' do |example| # Instead of using VCR directly, let's use our new helper method. # The yielded object here isn't actually the VCR cassette, but the # StripeContext wrapper. stripe_cassette(example) do |cassette| # This is what gets called in the controller. It'd be nice if this # was tested via Capybara, but I'm using Stripe's Checkout button, # and I don't want to deal with Capybara, JS, and VCR. SubscribeSiteWorker.perform_async site.id, cassette.card_token site.reload customer = Stripe::Customer.retrieve site.user.stripe_customer_id subscription = customer.subscriptions.retrieve site.stripe_subscription_id expect(subscription).to be_present expect(subscription.plan.id).to eq(ENV['STRIPE_PLAN_ID']) expect(site.status).to eq('active') end end end