title: Setting Stripe API key to test env for RSpec
body: <p>How do you set a Stripe API key to the test environment for RSpec? </p>
  
  <p>I am trying to test whether a user could bypass the Stripe charge in the following <a href="https://stripe.com/docs/checkout#integration-custom" rel="nofollow">Custom Checkout</a> action, effectively POSTing to the resource and writing to the database (e.g. using cURL or some other tool).</p>
  
  <pre><code>  def create
  
      customer = Stripe::Customer.create(
          :email        =&gt; params[:stripeEmail],
          :card         =&gt; params[:stripeToken],
      )
      charge = Stripe::Charge.create(
          :customer     =&gt; customer.id,
          :amount       =&gt; 1000,
      )
  
      if charge["paid"] == true
        @customer.create(email: params[:stripeEmail],
                         first_name: params[:first_name],
                         last_name:  params[:last_name],
                         agreed_to_terms: params[:agreed_to_terms],
                         )
        UserMailer.welcome_email(@customer).deliver_now
        redirect_to root_url
      else
        flash[:error] = "Something went wrong! Please try again."
        redirect_to error_url
      end
  
    rescue Stripe::CardError =&gt; e
      flash[:error] = e.message
      redirect_to :back
    end
  </code></pre>
  
  <p>But the spec requires me to provide an API key.</p>
  
  <pre><code>  describe 'POST #create' do
  
      context "with valid credentials" do
        it "but without Stripe, redirects to root_url" do
          @product = create(:valid_credentials)
          post :create, {first_name: "John", last_name: "Doe", stripeEmail: "john@doe.com", agreed_to_terms: true}
          expect(response).to redirect_to root_url
        end
      end
  </code></pre>
  
  <p>as seen below </p>
  
  <pre><code>No API key provided. Set your API key using "Stripe.api_key = &lt;API-KEY&gt;". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email support@stripe.com if you have any questions.
  </code></pre>