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 1 - Setting the stage

PreviousThe ATM challengeNextStep 2 - The core functionality

Last updated 7 years ago

The first thing we need to do is to set up the necessary tools we'll be using. We know that we'll be using Ruby as the programming language. That is already set up on our system.

We also know that we'll be trying to write our application using Test Driven Development - or at least try to do that. For that we'll need a testing framework. Enter RSpec - the most frequently used testing library for Ruby applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly. The user story for the unit test is:

As a programmer         
In order to work in a test driven way         
I want unit test my code

In order to be able to use it we need to install it. There are two ways to install libraries (gems). A direct install from your terminal (gem install rspec) or by adding a gem as a dependency to your application using . It is pretty simple, you just add a gem to a specific file named Gemfile.

Let's do that.

Create a new Gemfile from your terminal in the folder that you want to use for your application.

$ touch Gemfile

Add the following content to that file.

Gemfile

source 'https://rubygems.org'

gem 'rspec'

Save and head over to your terminal window and run the bundle install command.

If you get an error message and the system complains about not finding Bundler, just run this command to install it.

$ gem install bundler

Please note that the gem name is bundler while the command used to run it is bundle.

And run bundle install again.

That installs RSpec.

The next step is to initialize RSpec and configure it for our needs.

$ rspec --init

Edit the .rspec file and add --format documentation to see a more verbose rspec output. Your .rspec file needs to look like this.

.rspec

--format documentation
--color
--require spec_helper

Now, if you go back to your terminal and run the rspec command, you should see something like this.

$ rspec
No examples found.

Finished in 0.00028 seconds (files took 0.40297 seconds to load)
0 examples, 0 failures

Alright, that means we are set and ready to test.

Using Git

Let me put down some ground rules about version control. Commit often, write good commit messages and push up to your GitHub account. That is the only way for us coaches to see your progress. It does not matter if the code is working. We still want to see it. BAD CODE is better then NO CODE!

At this stage you need to set up a git repository. I suggest that you create a GitHub repository, copy the address and add it as a remote to your local repository (We are about to create one).

In your terminal, initialize a new git repository with the init command.

$ git init
Initialized empty Git repository in /your/path/atm/.git/
✔ ~/your/path/atm [master|…2]

Next, you need to create a .gitignore file. That file is used to keep information about files we want to EXCLUDE from version control.

$ touch .gitignore

Add at this to that file.

.gitignore

.DS_Store

.DS_Store (Desktop Services Store) is a OSX file that stores custom attributes of its containing folder, such as the position of icons or the choice of a background image. We don't want to track those files with git.

Now, perform the following steps.

$ git remote add origin <your git repo url>
$ git add . 
$ git commit -am "<your message>"
$ git push origin master
Bundler