Skip to content

Instantly share code, notes, and snippets.

@jcotzin
Created June 27, 2016 14:15
Show Gist options
  • Save jcotzin/5b43afaa003c529a470146f717151a80 to your computer and use it in GitHub Desktop.
Save jcotzin/5b43afaa003c529a470146f717151a80 to your computer and use it in GitHub Desktop.
require './bank_account'
describe BankAccount do
it "is created with an opening balance and the name of the client" do
account = BankAccount.new(500, "Sarah")
expect(account).to be_a(BankAccount) #be_a specifies that it's a certain class
end
it "can report it's balance" do
account = BankAccount.new(500, "Sarah")
expect(account.balance).to eq(500) #eq checks that they're equal
end
it "can make deposits" do
account = BankAccount.new(500, "Sarah")
account.deposit(500)
expect(account.balance).to eq(1000)
end
it "can make withdawls" do
account = BankAccount.new(500, "Sarah")
account.withdrawl(200)
expect(account.balance).to eq(300)
end
it "can transfer funds to another bank account" do
account1 = BankAccount.new(500, "Sarah")
account2 = BankAccount.new(500, "Mark")
account1.transfer(200, account2)
expect(account1.balance).to eq(300)
expect(account2.balance).to eq(700)
end
it "throws an error if minimum opening balance of 200 is not met" do
expect {BankAccount.new(100, "Sarah")}.to raise_error(ArgumentError)
end
it "allows the user to change the minimum balance" do
BankAccount.minimum_balance = 500
expect{ BankAccount.new(300, "Sarah")}.to raise_error(ArgumentError)
expect{ BankAccount.new(500, "Sarah")}.to_not raise_error(ArgumentError)
end
it "allows the user to add overdraft fees and to change it" do
BankAccount.overdraft_fee = 25
account = BankAccount.new(500, "Sarah")
account.withdrawl(600)
expect(account.balance).to eq(-125)
end
it "allows user to view transaction history" do
account = BankAccount.new(500, "Sarah")
account.withdrawl(600)
expect(account.balance).to eq({new_account: 500, withdrawl: 600, overdraft: 25})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment