Bank Application

Specifications

This application simulates banking behaviour. It allows you to start a new account, deposit money into your account, and withdraw money from your account. You can also print an account statement to view all of your transactions in a table.

Quick Start: Set up and start using this application:
  1. Fork and clone this repository and install dependencies
bundle
  1. Open up IRB in your terminal
irb -r ./lib/account.rb
  1. Create a new account
account = Account.new
  1. Deposit some money
account.deposit(3000)
  1. Withdraw some money
account.withdraw(500)
  1. Print an account Statement
account.print_statement

Account statement will print in your console in this format:

date || credit || debit || balance
20/04/2020 || || 500.00 || 2500.00
20/04/2020 || 2000.00 || || 3000.00

To run the unit and feature tests, just type into your terminal:

rspec

### Application Design I designed this application to have 3 classes, each with a single responsibility:

  • Account is the main class that the user interacts with. It is responsible for creating and storing transactions.
  • Transaction is responsible for storing the key information about each transaction. It stores the date of the transaction, the amount and whether the transaction is a credit or debit.
  • Statement is responsible for generating and displaying all the transaction details, including a running balance, in a format the user can easily digest.

Bank diagram

Testing

The application was developed using TDD, resulting in an application with 100% test coverage according to SimpleCov. The Input Output table below was used to plan out each step of the TDD process.

Done Class Input Output
Account .initializes @balance 0
Account .deposit(1000) @balance == 1000
Account @balance == 1000 : .deposit(2000) @balance == 3000
Account @balance == 3000 : .withdraw(500) @balance == 2500
Account .initializes @transactions []
Account .deposit(100) [Transaction.new]
Account .withdraw(100) [Transaction.new]
Account .withdraw(100) [Transaction.new]
Account .print_statement with transactions prints correctly
Account .print_statement without transactions raises error
Transaction when @type == 'credit' .credit? == true
Transaction when @type == 'debit' .credit? == false
Statement .print prints column headers headers printed
Statement .print prints credit transaction credit in 2nd column
Statement .print prints debit transaction debit in 3rd column
Statement .print date in correct format DD/MM/YYY
Statement prints in correct order reverse chronological
feature account.deposit(1000) no error raised
feature account.withdraw(300) no error raised
feature (with transactions) account.print_statement prints to stdout
feature (no transactions) account.print_statement error raised