Skip to content

Credit Cards in Forgery

My pull request was accepted, so random credit card type and number generation is now available in the Forgery gem!

Forgery(:credit_card).type
# => "Visa"

Forgery(:credit_card).number
# => "4539750423451972"

Forgery(:credit_card).number(:type => 'Visa', :length => 13)
# => "4556180133982"

A few interesting things I picked up along the way:

Photograph of Hans Peter Luhn, 1952

Hans Peter Luhn, responsible for at least one number in your wallet

  • The anatomy of a credit card number (validation of credit card numbers always seemed like magic to me, but not any longer!):

      6011475432471140

    • 6011 — the IIN or prefix — these belong to different card issuers (for example, this is a Discover Card)
    • 47543247114 — the account number — normally assigned by the issuer to an individual customer, Forgery creates this at random
    • 0 — the check digit — a checksum from the Luhn algorithm
  • This was my first experience writing comments for machine-generated documentation (RDoc). I think it looks great, and could prove very useful on other projects.
  • I learned that one of my go-to Ruby methods for test automation, choice, has been deprecated. Thankfully, it was simply renamed to sample, which is available in backports.
  • This was my first experience with RSpec, too. I like it — it seems very similar to Test::Unit (which I’m more familiar with), but with a more human-readable syntax. As a result, you end up with more meaningful tests and test failures, because behaviors are being defined instead of functions.

Finally, big props to Graham King and Celestino Gomes, whose knowledge and code I borrowed heavily from.

Categories: Development, Testing.

Tags: , ,

No responses (yet)