This blog post will be one many showing how to create Todo the Rails 3 application. The first post will be creating the Rails application and setting up the testing environment.
The app will be called Just ToDo it, just as famous
Nike slogan. And also Gods of DNS where
good to me so the Domain
justtodoit.com is free so I bought it and the final stage of this
Rails posts will be deployment to VPS and pointing to the domain JustToDoIt
(Currently displays my domain metaintellect).
The command to create new Rails application and omitting default testing framework Unit::Test
-T or longer version is
1 2 3 4 5 6 7 8 9
I had capitalized
JustToDoIt before, because the name is used as Ruby class and Pascal case is convention
for Ruby classes.
Then rename folder to
just-todo-it to be more in *nix folder naming convention:
The fun starts when the directory is changed to Rails app directory:
I’ll use vim as a default text editor, for TextMate use
mate and for the Sublime Text 2 use
subl terminal commands for editing files instead of
First open the
Gemfile, we need to add some gems that will be used in the app and also
Edit it to include this gems:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
After changing the
Gemfile run bundler to update and download entered gems:
Main and Production Ruby Gems
- rails - The latest one
3.2.8for this time of writing.
- bcrypt-ruby - Needed for password hashing.
- unicorn - For production, it will run as Rack HTTP Server.
- haml - My favorite View rendering engine.
- thin - Thin as local server instead of default Webrick.
- pg - My default database for production usage.
Test and Development Ruby Gems
- sqlite3 - The database used for development and testing environments.
- rspec-rails - RSpec as default testing framework.
- pry - Using as default Interactive Ruby console instead of
irb. Needs some configuration to be hooked as
- factory_girl_rails - The testing factory framework, used instead of the default Fixtures.
- database_cleaner - Used to speed-up tests, in my case to encapsulate the tests into db transaction.
- awesome_print - Used by Pry to pretty prints Ruby objects in full color exposing their internal structure with proper indentation.
- capybara - for simulating the web interaction in the tests.
- guard-rspec - To refresh and run the tests upon saving via rb-fsevent.
- spork - The server to speed up tests, how?, see provided link.
- guard-spork - Refreshes the spork server on changes, so that we don’t need to.
RSpec will be used as the test framework for the
Just ToDo it app.
Run generator to install RSpec to Rails:
1 2 3 4
1 2 3
Guardfile set the Spork on top and RSpec in bottom:
1 2 3 4 5 6 7 8 9 10 11 12
Bootstrap the Spork:
1 2 3 4
Edit RSpec helper:
And edit to include this content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
It uses Spork server and the aim is to have most things in
prefork block where is
stuff run on load of Spork.
each_run block we want put only necessary things, because it runs each time,
we are now having only reloading of Factory Girl factories, but maybe we will add something
prefork if we would have some troubles with testing data.
DatabaseCleaner is used to start, on before and clean it, on after running. The strategy used for DatabaseCleaner is transaction, meaning to rollback changes after the transaction queries are finished.
The testing environment is now configured, the Guard can be run:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
bundle exec guard to remove displayed warning.
To exit or stop the
guard command use
Pry as Rails Console
And for the end we will set Pry as our default Interactive Ruby console.
At the end of source file add code:
1 2 3 4
Try it out with
.pwd and close the Pry with
1 2 3 4 5
First remove the
README.rdoc file and create markdown
Add simple description:
Initialize the git repository:
See the status:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Then add all files:
1 2 3 4 5 6 7 8 9 10
Commit the files to local repository:
1 2 3 4 5 6
Set Github Remote
The app will be on Github. So after the new repository is created on Github, we can add remote to the local repository:
Push to the Github
After we add remote, it is now safe to push changes to Github remote repository:
1 2 3 4 5 6 7 8 9
It this first part we have created a
JustToDoIt Rails application.
And because we shall use TDD (Test Driven Development) to drive this app, we first configure the testing environment including:
- Factory Girl
- Database Cleaner
And for the end we setup the Pry to be a default for Rails console and commit the source to the Github repository xajler/just-todo-it.
In second post we shall go with the creating the app logic in TDD way!
The code is hosted on GitHub and can be cloned from the xajler/just-todo-it.
Github xajler/just-todo-it commit for this post: