Coding as a Craft 2.0
  • Introduction
  • Week 1 - Programming Basics - Ruby
    • Understanding the problem statement
    • User stories
    • Pair programming
    • The ATM challenge
      • Step 1 - Setting the stage
      • Step 2 - The core functionality
      • Step 3 - Interacting with objects
      • Step 4 - Refactoring
      • Step 5 - Testing the sad path
      • Step 6 - Cash is King
      • Step 7 - The Account
      • Step 8 - The Person
      • Step 9 - Making it all work together
    • Library Challenge
      • Important Topics
    • Extras
  • Week 2 -Programming Basics - JavaScript
  • Week 3 - TypeScript and Angular
  • Week 4 - Ruby on Rails Basics
  • Week 5 - Working With Legacy Code
  • Week 6 - Midcourse Project
  • Week 7 - Going Mobile
  • Week 8 & 9 - Advanced SaaS Applications
  • Week 10 - Expose and Consume API's
  • Configuring RSpec
Powered by GitBook
On this page
  1. Week 1 - Programming Basics - Ruby
  2. The ATM challenge

Step 8 - The Person

At this step we want to create a Person class and give him 3 attributes: :name, :cash and :account. We will give you a basic set of specs for that class. Your job will be to implement the code that will make these specs pass.

As a ATM operator      
In order to keep track of our costumers     
We want to assign each account to a separate person

Remember, you are free to modify these specs if you find any flaws in it OR if you find another way of testing the same behavior.

!FILENAME spec/person_spec.rb

require './lib/person'
require './lib/atm'

describe Person do

  subject { described_class.new(name: 'Thomas') }

  it 'is expected to have a :name on initialize' do
    expect(subject.name).not_to be nil
  end

  it 'is expected to raise error if no name is set' do
    expect { described_class.new }.to raise_error 'A name is required'
  end

  it 'is expected to have a :cash attribute with value of 0 on initialize' do
    expect(subject.cash).to eq 0
  end

  it 'is expected to have a :account attribute' do
    expect(subject.account).to be nil
  end

  describe 'can create an Account' do
    # As a Person,
    # in order to be able to use banking services to manage my funds,
    # i would like to be able to create a bank account
    before { subject.create_account }
    it 'of Account class ' do
      expect(subject.account).to be_an_instance_of Account
    end

    it 'with himself as an owner' do
      expect(subject.account.owner).to be subject
    end
  end

  describe 'can manage funds if an account been created' do
    let(:atm) { Atm.new }
    # As a Person with a Bank Account,
    # in order to be able to put my funds in the account ,
    # i would like to be able to make a deposit
    before { subject.create_account }
    it 'can deposit funds' do
      expect(subject.deposit(100)).to be_truthy
    end

  describe 'can not manage funds if no account been created' do
    # As a Person without a Bank Account,
    # in order to prevent me from using the wrong bank account,
    # I should NOT be able to to make a deposit.
    it 'can\'t deposit funds' do
      expect { subject.deposit(100) }.to raise_error(RuntimeError, 'No account present')
    end
  end
end

Making all of these tests pass will bring you closer to completing this challenge.

PreviousStep 7 - The AccountNextStep 9 - Making it all work together

Last updated 7 years ago