Created
July 29, 2012 14:58
-
-
Save rahult/3199383 to your computer and use it in GitHub Desktop.
Offline Credit Card Validator Specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby Version: ruby-1.9.2-p290 | |
# Author: Rahul Trikha | |
# Email: [email protected] | |
# Run: ruby credit_card_validator_spec.rb | |
# Include the latest version of minitest | |
# Must and won't predicates do not work with the | |
# shipped version of minitest with ruby | |
# Please install the latest minitest gem before running the specs | |
# $ gem install minitest -v=3.3.0 | |
gem 'minitest' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
require_relative 'credit_card_validator' | |
describe CreditCardValidator do | |
before do | |
@validator = CreditCardValidator.new | |
end | |
describe "when asked about validity of a AMEX card" do | |
it "should respond true for a valid card" do | |
@validator.card = "378282246310005" | |
@validator.must_be :valid? | |
end | |
it "should respond false for a invalid card" do | |
@validator.card = "37828224631000" | |
@validator.wont_be :valid? | |
end | |
end | |
describe "when asked about validity of a Discover card" do | |
it "should respond true for a valid card" do | |
@validator.card = "6011111111111117" | |
@validator.must_be :valid? | |
end | |
it "should respond false for a invalid card" do | |
@validator.card = "601111111111111" | |
@validator.wont_be :valid? | |
end | |
end | |
describe "when asked about validity of a MasterCard card" do | |
it "should respond true for a valid card" do | |
@validator.card = "5105105105105100" | |
@validator.must_be :valid? | |
end | |
it "should respond false for a invalid card" do | |
@validator.card = "5105105105105106" | |
@validator.wont_be :valid? | |
end | |
it "should respond false for a invalid card" do | |
@validator.card = "510510510510510" | |
@validator.wont_be :valid? | |
end | |
end | |
describe "when asked about validity of a VISA card" do | |
it "should respond true for a valid card" do | |
@validator.card = "4111111111111111" | |
@validator.must_be :valid? | |
end | |
it "should respond true for a valid card" do | |
@validator.card = "4012888888881881" | |
@validator.must_be :valid? | |
end | |
it "should respond false for a invalid card" do | |
@validator.card = "4111111111111" | |
@validator.wont_be :valid? | |
end | |
end | |
describe "when asked about validity of a Unkown card" do | |
it "should respond false for a invalid card" do | |
@validator.card = "9111111111111111" | |
@validator.wont_be :valid? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment