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:
The anatomy of a credit card number (validation of credit card numbers always seemed like magic to me, but not any longer!):
- 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.