<commit_before>require 'spec_helper'

shared_examples 'Card Error Prep' do

  it 'prepares a card error' do
    StripeMock.prepare_card_error(:card_declined, :new_charge)
    cus = Stripe::Customer.create(email: '<EMAIL>')
    expect { Stripe::Charge.create(
      amount: 900,
      currency: 'usd',
      source: StripeMock.generate_card_token(number: '4242424242424241'),
      description: 'hello'
      )
    }.to raise_error(Stripe::CardError, 'The card was declined')
  end

  it 'is a valid card error' do
    stripe_helper.prepare_card_error

    begin
      Stripe::Customer.create(
        email: '<EMAIL>',
        source: stripe_helper.generate_card_token(number: '123')
      )
    rescue Stripe::CardError => e
      body = e.json_body
      err  = body[:error]

      expect(body).to be_a(Hash)
      expect(err[:type]).to eq 'card_error'
      expect(err[:param]).to eq 'number'
      expect(err[:code]).to eq 'invalid_number'
      expect(err[:message]).to eq 'This card number looks invalid.'
    end
  end
end<commit_msg>prepare_error_examples tests pass<commit_after>require 'spec_helper'
shared_examples 'Card Error Prep' do
  it 'prepares a card error', live: true do
    StripeMock.start
    StripeMock.prepare_card_error(:card_declined, :new_charge)
    cus = Stripe::Customer.create(email: '<EMAIL>')
    expect { Stripe::Charge.create(
      amount: 900,
      currency: 'usd',
      source: StripeMock.generate_card_token(number: '4242424242424241'),
      description: 'hello'
      )
    }.to raise_error(Stripe::CardError, 'The card was declined')
  end

  it 'is a valid card error', live: true do
    begin
      StripeMock.start
      StripeMock.prepare_card_error(:card_declined)
      Stripe::Customer.create(
        email: '<EMAIL>',
        source: stripe_helper.generate_card_token(number: '123')
      )
    rescue Stripe::CardError => e
      body = e.json_body
      err  = body[:error]
      expect(body).to be_a(Hash)
      expect(err[:type]).to eq 'card_error'
      expect(err[:param]).to eq 'number'
      expect(err[:code]).to eq 'invalid_number'
      expect(err[:message]).to eq 'This card number looks invalid.'
      StripeMock.stop
    end
  end
end
{'fraction_non_alphanumeric': 0.11983658647299138, 'fraction_numerical': 0.01997276441216523, 'mean_word_length': 3.2466281310211946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671018', 'n_tokens_mistral': 770, 'n_tokens_neox': 719, 'n_words': 166}