Skip to content

Instantly share code, notes, and snippets.

@Genki-S
Created April 11, 2015 03:36
Show Gist options
  • Save Genki-S/cef9766b6ead493a2218 to your computer and use it in GitHub Desktop.
Save Genki-S/cef9766b6ead493a2218 to your computer and use it in GitHub Desktop.
require 'coverage'
Coverage.start
require './a_method.rb' # => true
a_method
p Coverage.result # => {"/Users/.../a_method.rb"=>[1, 1, 1, 10, nil, 1, nil]}
# Does not produce coverage because `Coverage.result` clears out the coverage
# p Coverage.result # coverage measurement is not enabled (RuntimeError)
# Does not produce coverage because the file `a_method.rb` is not loaded
Coverage.start
a_method
p Coverage.result # => {"/Users/.../a_method.rb"=>[]}
# Does not produce coverage because the file `a_method.rb` is not loaded
Coverage.start
require './a_method.rb' # => false
a_method
p Coverage.result # => {"/Users/.../a_method.rb"=>[]}
# Unload `a_method.rb`
$".delete_if { |s| s.include?('a_method.rb') }
# Does produce coverage because the file `a_method.rb` is loaded
Coverage.start
require './a_method.rb' # => true
a_method
p Coverage.result # => {"/Users/.../a_method.rb"=>[1, 1, 1, 10, nil, 1, nil]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment