Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / doc / src / documentation / tools / rcov.page
blobb72fe4e252f1e92476b6e806d8f221b94af3a860
1 ---
2 title: RCov
3 ---
4 h2. RCov
6 RSpec has tight integration with "RCov":http://eigenclass.org/hiki.rb?rcov, the excellent code coverage tool for Ruby.
8 h3. Running specs with RCov
10 The easiest way to use RCov with RSpec is from a rake script (Rakefile), using RSpec's
11 "Rake task":rake.html. The snippet below is from RSpec's own Rakefile.
13 <ruby file="../rspec/rake_tasks/examples_with_rcov.rake"/>
15 By adding <code>rcov=true</code> to the rake task, specs will be run with RCov
16 instead of the standard ruby interpreter, and a coverage report like 
17 "this":../../coverage/index.html will be generated with the following command line:
19 <pre>
20 rake examples_with_rcov
21 </pre>
23 Also, because you don't want your example files to be included in the coverage report (you just
24 want them to run), don't forget to add <code>t.rcov_opts = ['--exclude', 'examples']</code>. You
25 can use this to exclude any other files that must be required but should not be measured (just
26 use a comma separated list).
28 h3. Coverage threshold
30 You can guard your codebase's coverage from dropping below a certain threshold
31 by using RSpec's built-in task for verification of the total RCov coverage. 
32 (This is not the same as RCov's --threshold option, which is a filtering mechanism).
34 <ruby file="../rspec/rake_tasks/verify_rcov.rake"/>
36 This will give you a :verify_rcov task that will fail your build if the
37 coverage drops below the threshold you define.
38 If it's too low you're encouraged to write more specs rather than "fix"
39 the threshold value (which should usually only be adjusted upwards).
41 In fact, the task will also fail the build if the coverage raises above the threshold as well.
42 This might seem a bit counterintuitive, but this is when you should go and raise the
43 threshold in your Rakefile. This way you won't miss temporary coverage increases. Crank it up!
44 This is how we got to 100% coverage for RSpec.
46 See "RCov::VerifyTask":../../rdoc/classes/RCov/VerifyTask.html for details.