Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created December 18, 2011 13:58
Show Gist options
  • Save karthiks/1493494 to your computer and use it in GitHub Desktop.
Save karthiks/1493494 to your computer and use it in GitHub Desktop.
Steps to creating a Ruby project with RSpec for BDD and Guard for continuous testing

Pre-requisite:

  1. RVM is used
  2. In the version of ruby that is used, bundler gem is installed [ implied that it is global]

Steps:

  1. Create a project structure using bundler bundle gem game_of_life create game_of_life/Gemfile create game_of_life/Rakefile create game_of_life/.gitignore create game_of_life/game_of_life.gemspec create game_of_life/lib/game_of_life.rb create game_of_life/lib/game_of_life/version.rb

  2. Get into the project directory $ cd game_of_life/

  3. Create .rvmrc and containing the following line: rvm use ruby-1.9.2-p290@kata

  4. Open Gemfile and ensure see that the contents are as below:

source "http://rubygems.org"

#Specify your gem's dependencies in game_of_life.gemspec #gemspec ###Commented this line to get rid of bundler error. gem 'rspec' # Adding RSpec to the existing file content

  1. Open spec/spec_helper.rb and make its contents as below $LOAD_PATH.unshift File.dirname(FILE) $LOAD_PATH.unshift File.join(File.dirname(FILE),'..','lib') require 'rspec_autotest_template'

RSpec.configure do |c| #... end

  1. Open Rakefile and make its contents as below so that rake by default runs the Rspec suite require 'rake' require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w(--color --format progress) end

task :default => :spec

  1. Adding Guard to Project

    Add the following to the Gemfile gem 'rspec'

     gem 'guard-rspec'
     gem 'rb-inotify'
     gem 'libnotify'
    

    In terminal run the following: $ bundle install $ guard init //will generate empty guard file which might not be of use to us $ guard init rspec //will be useful as it will create a Guardfile with a watch list based on RSpec framework. Ain't that cool?

       $ guard [start]
       $ bundle exec guard [start]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment