Pages

Tuesday, February 24, 2015

Testing with Ruby

To get started with Ruby testing, I am using RSpec ruby framework.
http://rspec.info/

To use RSpec, first you will need to have the gem "guard" which is a command line tool to work with RSpec.
$ gen install guard.

$ bundle exec guard list
This will give you a list of frameworks installed and ready for guard to work with.

After that run
$ bundle exec guard.

This will take you to the guard prompt . Do the following to run all tests.

$ guard(main)> all rspec.

You are up and running!

Ruby Installation

Introduction:

Assumes:
* You already have a Ruby project which you want to set up with little or no Ruby knowledge.
* You are on OS X.

I am off to learning Ruby for my new project. It makes me both excited and scared at the same time as I love learning new languages and tools but Ruby is a different beast than any I have tamed before. My understanding of Ruby leads me to believe that Ruby is:

1. A server side language.
2. Very different syntax than C, C++, and Java.
3. Is more than Ruby itself; there are gems and rails I don't know about.
4. It can be used to host apps on cloud servers like AWS.

It is a personal journey and like any other beginner, I am pretty sure the above four bullets will need to be modified once I develop more understanding.

Installing Ruby:

I have started by watching the following course videos:
https://onemonth.com/courses/one-month-rails

Installing Ruby using homebrew resulted in the installation of ruby 2.2.0p0 (2014-12-25 revision 49005). Turns out I need 2.1.5. So using the rbenv to make changes and install the specific version:
https://github.com/sstephenson/rbenv#installation

$ rbenv install 2.1.5

in ~/.bash_profile, add
export PATH="/Users/{home}/.rbenv/versions/2.1.5/bin/":$PATH
where {home} is your own user name.

$ rbenv rehash

$ eval "$(rbenv init -)"

$ gem install bundler

(Deviating but a necessary step is: $brew install qt; $brew linkapps qt) .

Run "$ bundle install" from your Ruby project folder in which "Gemfiles" exist.

Getting Postgres running:

Install Postgress.app from http://postgresapp.com/.

Use commands:

$ createuser -s -r postgres
$ rake db:create
$ rake db:migrate
to create and get the db running.

Install Pow.cx:
From http://pow.cx, install Pow.cx. This utility will get your Ruby server app running without setting up a whole lot of configuration. Just create a symlink to your app in .pow as mentioned on the page.

There you go. If you have symlinked your project to "myapp" you should be able to type http://myapp.dev in your browser and see your app running.