/README.textile

http://github.com/markbates/cover_me · Textile · 110 lines · 78 code · 32 blank · 0 comment · 0 complexity · 2feb07a05b784027c9dd4a52922811df MD5 · raw file

  1. h1. CoverMe - Code Coverage for Ruby 1.9
  2. Ruby 1.9(.2) is an amazing language to develop applications in. It's faster, more powerful, cleaner, and a huge improvement over Ruby 1.8.x. Because of those reasons every Ruby developer should move to this exciting new version of our language.
  3. When making a move of this size it's important to have the right tools to help us along. Unfortunately, one of the most useful tools as a Ruby developer, RCov, does not work with Ruby 1.9.
  4. RCov, for those unfamiliar analyzes your code and tells you which part of your code was not executed. This is INCREDIBLY useful when hooked up to your test suite. While, it's not the only metric you should use when determining how good your test coverage it, it certainly is a great first step to point out exactly which parts of your code haven't been touched at all!
  5. Enter CoverMe.
  6. h2. History
  7. While working on a Ruby 1.9/Rails 3 project, and loving everything about it (except for the lack of RCov), I came across a "post":http://engineering.attinteractive.com/2010/08/code-coverage-in-ruby-1-9/ by Aaron Patterson (of Nokogiri fame). In this post he quickly outlined a very basic coverage tool using the new built-in Coverage module in Ruby 1.9.
  8. After spending a morning playing with it, I was quickly able to grow the idea into something useful for the project. Later that day the company I was consulting for ("BiddingForGood.com":http://www.biddingforgood.com), and in particular their chief architect, Stuart Garner, told me to take a day or two and clean it up and release it for the world to use, and so here it is.
  9. h2. Features
  10. h3. Index Page
  11. * Sortable column headers (File, Lines, Lines of Code, Tested %).
  12. * Searching/filtering by file name.
  13. * Filtering by coverage percent.
  14. * Color coded list of files to quickly see which ones are 100% covered, > 90% covered, or less than 90% covered.
  15. * Large color coded average coverage percent, for quick reference.
  16. h3. Detail Page
  17. * Line by line coverage report
  18. * Color coded lines to quickly see which lines where executed and which ones were not.
  19. * Side by side viewing with the corresponding test/spec file (if one exists).
  20. h2. Use
  21. CoverMe is pretty easy to use, and has been tested with Ruby 1.9.2 and Rails 3. First, add CoverMe to your Gemfile:
  22. <pre><code>
  23. gem 'cover_me', '>= 1.2.0', :group => :test
  24. </code></pre>
  25. Now make sure to install the gem with Bundler:
  26. <pre><code>
  27. $ bundle install
  28. </code></pre>
  29. All that's left now is to require it as the first line of your 'spec_helper.rb' or 'test_helper.rb' file:
  30. <pre><code>
  31. require 'cover_me'
  32. </code></pre>
  33. Now the next time your run your test suite it will create a series of HTML files in the _coverage_ folder at the root of your project. Open _coverage/index.html_ and you're off and running.
  34. h3. Rails 3
  35. If you are using CoverMe with Rails 3 run the following to get the cover me Rake task:
  36. <pre><code>
  37. $ rails g cover_me:install
  38. </code></pre>
  39. h2. Configuration
  40. CoverMe is easily configurable, under the covers it uses the "Configatron":http://github.com/markbates/configatron library. Here are a few quick config options you might want to play with:
  41. <pre><code>
  42. CoverMe.config do |c|
  43. # where is your project's root:
  44. c.project.root # => "Rails.root" (default)
  45. # what files are you interested in coverage for:
  46. c.file_pattern # => [
  47. /(#{CoverMe.config.project.root}\/app\/.+\.rb)/i,
  48. /(#{CoverMe.config.project.root}\/lib\/.+\.rb)/i
  49. ] (default)
  50. # what files do you want to explicitly exclude from coverage
  51. c.exclude_file_patterns # => [] (default)
  52. # where do you want the HTML generated:
  53. c.html_formatter.output_path # => File.join(CoverMe.config.project.root, 'coverage') (default)
  54. # what do you want to happen when it finishes:
  55. c.at_exit # => Proc.new {
  56. if CoverMe.config.formatter == CoverMe::HtmlFormatter
  57. index = File.join(CoverMe.config.html_formatter.output_path, 'index.html')
  58. if File.exists?(index)
  59. `open #{index}`
  60. end
  61. end
  62. } (default)
  63. end
  64. </code></pre>
  65. h2. Contributors
  66. * Mark Bates
  67. * Andrea Campi
  68. * KITAITI Makoto
  69. * Alex Crichton
  70. * Leif Bladt
  71. * Will Marshall
  72. * Matthew Albright
  73. * Josef Sin
  74. * Lasse Koskela
  75. * Stephen Delano
  76. * George Anderson
  77. * Rob Zolkos
  78. * jmthomas