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. :)

8 comments:

  1. Woah! I'm really loving the template/theme of this website. It's simple,
    yet effective. A lot of times it's very hard to get that "perfect balance" between usability and appearance. I must say you have done a very good job with this. Additionally, the blog loads extremely quick for me on Opera. Exceptional Blog!

    Here is my webpage: Methadone Clinics
    My page :: Methadone Withdrawl

    ReplyDelete
  2. Hey there would you mind letting me know which webhost you're working with? I've loaded
    your blog in 3 completely different internet browsers and I must say this
    blog loads a lot quicker then most. Can you suggest a good web
    hosting provider at a fair price? Many thanks, I appreciate it!



    Feel free to surf to my page :: dickies industrial cargo pants

    ReplyDelete
  3. Hello wοuld уou minԁ sharing which blog рlatform yοu're working with? I'm gоing to start my
    own blog іn the near future but I'm having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I'm looκing for something unique.
    P.S Sοrry for beіng off-topic but I had to ask!


    My blog ... lightest running shoes ever

    ReplyDelete
  4. My partner and I stumbled over here by a different web page
    and thought I may as well check things out.

    I like what I see so now i am following you. Look forward to looking
    at your web page repeatedly.

    Feel free to visit my website ... camo cargo pants

    ReplyDelete
  5. Тhiѕ dеsign іs wicked! You mоst certaіnly know how to kеep a гeaԁer amused.
    Βеtween your wit and your viԁeοs, Ι was almost moved to
    start my own blog (well, аlmoѕt.
    ..HaHa!) Great jοb. Ӏ really enjoyed what
    you had to saу, and more than thаt, how
    you ρrеsеntеd it. Too coοl!


    Feel fгee to surf tо my webρage: best lightweight running shoes for women
    My website > salomon running shoes

    ReplyDelete
  6. I know this if off topic but I'm looking into starting my own blog and was curious what all is required to get setup? I'm assuming
    having a blog like yours would cost a pretty penny?
    I'm not very web savvy so I'm not 100% sure. Any suggestions or advice would be greatly appreciated. Appreciate it

    My web-site - Methadone Clinics In Ohio

    ReplyDelete
  7. As you'll see, what I did to increase T mostly boils mastered to feeding modify, workout smarter, and exploit many death. For more ==== >>>>>> http://www.healthcaresups.com/spartagen-xt-exposed/
    Spartagen xt

    ReplyDelete