I have written a Sinatra app (web site), and I would like to collect code coverage information for the site's code. I'm new to Ruby, but Google tells me that rcov is a good code coverage tool. Unfortunately, all the information I can find online shows only how to get code coverage information about test cases - I want code coverage information about my site itself.
The particular site files I want to profile are in the "sdk" and "sdk/vendor" directories, so where I would normally run my site with "ruby site.rb" I instead tried the following:
rcov -Isdk -Isdk/vendor site.rb
It showed the Sinatra start-up text, but then immediately exited instead of waiting for web requests like my Sinatra app normally would.
Can someone tell me the trick of running my site with code coverage enabled? I want to run the site, hit it with a series of requests, and then stop the site; after which I want to look at the accumulated code coverage stats from the whole series of requests.
I'm currently using Ruby 1.8.7.
SimpleCov is perfect for this. If you're using RSpec and Bundler setup is super easy
in your gem file
gem 'simplecov'
then
$ bundle install
In spec/spec_helper.rb (before anything else)
require 'simplecov'
SimpleCov.start
then: $ rspec spec
Simplecov generates a really nice coverage report at coverage/index.html
Maybe you could take a look at SimpleCov, which advertises its simple usage for any kind of coverage analysis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With