Thursday, May 31, 2012

-bash: mongod: command not found

export PATH=$PATH:/usr/local/mongodb/bin
For Mongodb 2.0.3
mongod --dbpath /Users/bparanj/data/mongodb
The dbpath is the path to the mongodb.config file
which contains :

Deploying to a VPS

To get the working I had to do :

1. apt-get install sqlite3 libsqlite3-dev
2. Add : gem 'pg' and gem 'unicorn' to Gemfile

Wednesday, May 30, 2012

undefined local variable or method `autotest' for main:Object

This error happens when you have this : require autotest/fsevent
in your ~/.autotest file, change it to : require 'autotest/fsevent'

Thursday, May 10, 2012

Data Driven Unit Test

How do you avoid loops in your specs?

Like Alex points out, this is a test smell according to Gerard Mezos. In .NET they have something called as data driven unit test. In Ruby we can accomplish the same thing using the following:

  def data_driven_spec(container)
    container.each do |element|

and in your test you can do :

  it "should return back slash pre-pended to all special characters" do
    SPECIAL_CHARACTERS = ["?", "^", "$", "/", "\\", "[", "]", "{", "}", "(", ")", "+", "*", "." ]
    data_driven_spec(SPECIAL_CHARACTERS) do |special_character|
      result = Regexpgen::Component.match_this_character(special_character)
      result.should == "\\#{special_character}"    

The code is taken from my regexpgen ruby gem. My test differs from the message that goes in to the it method. I have raised the level of abstraction, whereas Alex substitues the a variable to vary the message.

Wednesday, May 09, 2012

`bin_path': can't find gem rspec-core

use rspec instead spec for running the spec file.

Creating a Ruby gem with RSpec as the test framework

1. bundle gem 'your-gem-name'
2. Run : rspec --init from your gem directory to generate the spec/spec_helper.rb and .rspec files.

.rspec has the configuration such as color and format of the output when specs are run.

Tuesday, May 01, 2012

irb tricks

1. touch ~/.irbrc
2. Edit the .irbrc and add the following code:

require 'pp'
require 'rubygems'

class Object
  def ls
  def pwd
  def cd(dir)

alias p pp

3. Now whenever you open an irb session you can now list the directory contents by doing ls, print working directory by pwd and change directory by doing cd "directory-name".