I am rather new to rails, and I am using rspec to write unit tests, integration tests and functional tests.
We want to integrate TDD in our team. While it is a great way to plan how to write functionality, for me it doesn't feel at all like a proper unit test, when it comes to code coverage.
I would like to have insight in the coverage of our unit tests. If I write a method, it should be tested in such a way that the following is ensured:
if
/unless
statements) is produced during the test.I want to be able to get insight in how my tests are doing in terms of these two requirements, i.e. to see my code and see what lines and expressions are being tested and which are not. Is there a tool / gem that you could recommend me that gives me this information?
To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
Test coverage using SimpleCov SimpleCov is a code coverage analysis tool for Ruby. It uses Ruby's built-in Coverage library to gather code coverage data. Add simplecov to your Gemfile and run bundle install: 1gem 'simplecov', require: false, group: :test.
Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.
This is exactly what you are looking for: https://github.com/colszowka/simplecov
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