File: test_faker_stripe.rb

package info (click to toggle)
ruby-faker 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,596 kB
  • sloc: ruby: 20,656; sh: 6; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerStripe < Test::Unit::TestCase
  def setup
    @tester = Faker::Stripe
  end

  def test_valid_card
    assert_match(/\A\d{14,16}\z/, @tester.valid_card)
  end

  def test_valid_card_error
    e = assert_raise ArgumentError do
      assert @tester.valid_card(card_type: Faker::Lorem.word)
    end

    assert_match(/\AValid credit cards argument can be left blank or include/, e.message)
  end

  def test_specific_valid_card
    assert_match(/\A\d{16}\z/, @tester.valid_card(card_type: 'visa'))
  end

  def test_valid_token
    assert_match(/\w+/, @tester.valid_token)
  end

  def test_specific_valid_token
    assert_match(/\Atok_visa\z/, @tester.valid_token(card_type: 'visa'))
  end

  def test_invalid_card
    assert_match(/\A\d{16}\z/, @tester.invalid_card)
  end

  def test_invalid_card_error
    e = assert_raise ArgumentError do
      assert @tester.invalid_card(card_error: Faker::Lorem.word)
    end

    assert_match(/\AInvalid credit cards argument can be left blank or include/, e.message)
  end

  def test_specific_error_invalid_card
    assert_match(/\w+/, @tester.invalid_card(card_error: 'zipFail'))
  end

  def test_valid_exp_mo
    assert_match(/\A\d{2}\z/, @tester.month)
  end

  def test_valid_exp_yr
    assert_match(/\A\d{4}\z/, @tester.year)
  end

  def test_valid_ccv
    assert_match(/\A\d{3}\z/, @tester.ccv)
  end

  def test_valid_amex_ccv
    assert_match(/\A\d{4}\z/, @tester.ccv(card_type: 'amex'))
  end
end