lkdjiin / coco

Code coverage for ruby 2.x
http://lkdjiin.github.com/coco/
MIT License
70 stars 10 forks source link

RuntimeError if Coveralls.io also installed #49

Closed grempe closed 8 years ago

grempe commented 8 years ago

I have been using coveralls.io to have an internet accessible place for code coverage results to be shown. But coveralls does not really provide me with any guidance as to coverage when I run my minutest suite locally.

I wanted to add in coco support for local coverage reports that I can see before I commit and push.

When I added coco support locally w/ version 0.14.0 I get the following RuntimeError (but it does generate a coverage/index.html report). Note also the warning: private_attribute? at the beginning of the test run.

~/src/tss-rb (master ✗)$ rake --trace
** Invoke default (first_time)
** Invoke test (first_time)
** Execute test
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/coco-0.14.0/lib/coco/cover/summary.rb:36: warning: private attribute?
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's default settings.
Run options: --seed 13647

# Running:

...............................................................................................................

Fabulous run in 5.913880s, 18.7694 runs/s, 57.4919 assertions/s.

111 runs, 340 assertions, 0 failures, 0 errors, 0 skips
[Coveralls] Outside the CI environment, not sending data.
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/coco-0.14.0/lib/coco.rb:25:in `result': coverage measurement is not enabled (RuntimeError)
    from /usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/coco-0.14.0/lib/coco.rb:25:in `block in <top (required)>'
rake aborted!
Command failed with status (1): [ruby -w -I"lib:test:lib" -I"/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib" "/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/rake_test_loader.rb" "test/blank_test.rb" "test/tss_combiner_validation_test.rb" "test/tss_hasher_test.rb" "test/tss_python_interop_test.rb" "test/tss_splitter_validation_test.rb" "test/tss_test.rb" "test/tss_util_test.rb" ]
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/testtask.rb:109:in `block (3 levels) in define'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils.rb:57:in `call'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils.rb:57:in `sh'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils_ext.rb:37:in `sh'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils.rb:91:in `ruby'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils_ext.rb:37:in `ruby'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/testtask.rb:105:in `block (2 levels) in define'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/file_utils_ext.rb:58:in `verbose'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/testtask.rb:101:in `block in define'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:248:in `call'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:209:in `block in invoke_prerequisites'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:207:in `each'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:207:in `invoke_prerequisites'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:186:in `block in invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:150:in `invoke_task'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:106:in `each'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:106:in `block in top_level'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:100:in `top_level'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:78:in `block in run'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/usr/local/var/rbenv/versions/2.2.4/bin/rake:23:in `load'
/usr/local/var/rbenv/versions/2.2.4/bin/rake:23:in `<main>'
Tasks: TOP => default => test

My test_helper.rb file looks like the following (I tried reversing the order of require between coveralls and coco, no difference):

# Local code coverage reports
require 'coco'

# Webhook Coverage Service
require 'coveralls'
Coveralls.wear!

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'tss'

require 'minitest/autorun'
require 'minitest/pride'

Any thoughts? Or are the two simply incompatible with each other and I must do conditional inclusion based on environment (rather avoid)?

lkdjiin commented 8 years ago

At first glance I would say that coco and simplecov are not compatible. I don't know coveralls but can you try to disable simplecov to see what's happen?

grempe commented 8 years ago

Well, coveralls is responsible for loading simplecov into the environment and I didn't find a way to stop it from doing that. But I poked inside the coveralls gem and found some internal checks it was doing for the environment to determine whether or not to run. So I added those same checks to my test_helper.rb which so far seemed to do the trick.

# coveralls.io and coco are incompatible. Run each in their own env.
if ENV['TRAVIS'] || ENV["CI"] || ENV["JENKINS_URL"] || ENV['TDDIUM'] || ENV["COVERALLS_RUN_LOCALLY"]
  # coveralls.io : web based code coverage
  require 'coveralls'
  Coveralls.wear!
else
  # coco : local code coverage
  require 'coco'
end

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'tss'

require 'minitest/autorun'
require 'minitest/pride'
grempe commented 8 years ago

Please do note though that I still see the following warning when I run my mintest specs locally with only coco being loaded:

/usr/local/var/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/coco-0.14.0/lib/coco/cover/summary.rb:36: warning: private attribute?
lkdjiin commented 8 years ago

I'm glad you found a way to use coveralls + coco :smile:

I'll look closer to this warning.