Tuesday, January 17, 2012

Exercise 46: A Project Skeleton: Learn Ruby the Hard Way: Practicum

In this section, Zed and Rob explain how to set up a skeleton directory to start working with projects. I had a lot of help setting up my Macbook Pro environment to run the various tests that I do in my work life. If I were to be told "OK, we are going to have you set up a whole new environment, and we're going to shut down the one you are using currently. Now go and set up your stuff"... truthfully, I'd be more than half lost!

So what should a skeleton directory contain? It should have all of the basic components necessary to get a new project up and running. It include the project layout, automated tests, modules, and install scripts.

For this project, since my OSX environment is already set up with all of this, I'll use my PC to set this stuff up.

Skeleton Contents: PC/Windows
First, create the structure of your skeleton directory with these commands:

- mkdir projects
-  cd projects/
- mkdir skeleton
- cd skeleton
- mkdir bin
- mkdir lib
- mkdir lib/NAME
- mkdir test

Next we need to setup some initial files:

-  lib/NAME.rb
-  touch lib/NAME/version.rb

Then we can create a NAME.gemspec file in our project's root directory which we can use to install our project later if we want:

Finally we create a simple skeleton file for unit tests (more on that in the next exercise) named test/test_NAME.rb:

Installing Gems

Next, install the following software packages:

git - http://git-scm.com/
rake - http://rake.rubyforge.org/
rvm - https://rvm.beginrescueend.com/
rubygems - http://rubygems.org/pages/download
bundler - http://gembundler.com/

Installing these for Windows was, well, interesting. Outside of a graphical environment for git, most of the other applications were easy to install using the gem install option.

Using The Skeleton

- Make a copy of your skeleton directory. Name it after your new project.
- Rename (move) the NAME directory and NAME.rb file to be the name of your project.
- Edit your NAME.gemspec file to have all the information for your project.
- Rename test/test_NAME.rb to also have your project name.
- Start coding.


This section is incredibly helpful, in that it finally helped me connect the dots on a lot of things I do every day with Cucumber, but couldn't entirely put my finger on what or how I was doing it. there's a lot more I need to do, certainly, and a fair amount of it is just going to require some practice. I'm definitely going to be playing some more with the Windows git interface so I understand what it does and how to use it effectively.
Post a Comment