Showing posts with label ROR. Show all posts
Showing posts with label ROR. Show all posts

Monday, November 8, 2010

How to: write rcov test

'rcov' is a ruby test coverage tool which tells you how effective is the test by giving you the complete coverage of the test that you have written.

You can use it in any of your projects and check your test effectiveness.

First install the gem

$gem install rcov

Next generate the rcov documents like below

$rcov -I lib spec/*.rb --exclude ^spec,/gems/ -T --no-html

The above parameters tell rcov to include lib directory as well as all files inside spec dir and exclude all the gems.
Also, it displays the output in terminal and doesn't generate the html file. You can take the --no-html flag off if you like an interactive html view which is inside the coverage folder.

You can achieve the same with rake task also like below:

Include the 'rcov_custom' file in the rake file.

# In Rake
require File.expand_path(File.dirname(__FILE__) + '/lib/tasks/rcov_custom')

Next you write the following in the file.
# rcov_test.rb
desc "Custom rcov"
RSpec::Core::RakeTask.new(:rcov_custom) do |t|
t.rcov = true
t.rcov_opts = %w{--exclude gems\/,spec\/ -T}
end

In terminal, check the rake tasks.

$Rake -T

You should see a custom rake task named 'Custom rcov'.
Finally, generate the rcov test whenever you feel like with the rake command.

$rake rcov_custom

Hope your code is 100% covered up by your test. :)

Monday, August 30, 2010

Ruby on Rails on Windows

So, you guys wanna kick start Ruby on Rails (ROR) on Windows as you can’t afford a Mac or you can’t get to work with *nix platform. Then this step by step guide just for you and what a better day to start as with the grand launch of .

Well, there’re two popular ways to install ROR on a PC with Windows OS, one is a normal installation with exe setup files and another(recommended) is through cygwin in a *nix environment under windows. I will discuss the latter one in next post.

Steps:

1)  Download Ruby Installer (1.9.2 or 1.8.7) and run through the wizard with all the defaults to install Ruby. If you don’t have a preferred IDE or editor, windows ruby comes with scite, which is pretty cool.

2)  Next, we’ll need to install some gems (standard Ruby package manager or ruby plugin libraries). So just download the RubyGems zip file, extract, then run “ruby setup.rb” in your newly installed Ruby prompt or just double click the setup.rb file. If your RubyGems system is old, update it by running (in cmd or Ruby CLI)

gem update —system

3) We will be using SQLite instead of mySQL to minimize pain.   Download the pre-compiled version of sqlite-3_7_2 (install) from the SQLite web site and sqlitedll-3_7_2.zip, unzip it and copy sqlite3.dll and sqlite3.def to your ruby/bin directory (or copy to c:\Windows\System32).

4) Now that SQLite3 is installed, just install the gem:
gem install sqlite3-ruby

5) Install all of latest Rails (gem) and its dependencies through the command line:

gem install rails –pre

6) Test ROR by Creating your application skeleton and start the server: 

rails new path/to/your/new/application
cd path/to/your/new/application
rails server

You're running Ruby on Rails! Follow the instructions on http://localhost:3000.

image

Click about your application’s environment to see the details. If you see the above screen, you’re successfully running ROR. Cheers.

6) Finally don’t forget to read the first 2 sections of this tutorial to get going http://guides.rubyonrails.org/getting_started.html

Now enjoy Ruby on Rails.