dashingrocket / simplecov-cobertura

Ruby SimpleCov Cobertura Formatter
Apache License 2.0
52 stars 38 forks source link

Fix Deprecation Warning: The SimpleCov::Formatter::CoberturaFormatter formatter uses the deprecated formatter interface not supported directly by RSpec 3 #7

Closed zherr closed 5 years ago

zherr commented 5 years ago

Full warning:

Deprecation Warnings:

 The SimpleCov::Formatter::CoberturaFormatter formatter uses the deprecated formatter interface not supported directly by RSpec 3.  To continue to use this formatter you must install the `rspec-legacy_formatters` gem, which provides support for legacy formatters or upgrade the formatter to a compatible version.  Formatter added at: /Users/my-user/.rvm/gems/ruby-2.5.1@app/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'

If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Reproduction steps:

  1. Everything in the README
  2. Rspec v3 or greater
  3. Run bundle exec rspec --format SimpleCov::Formatter::CoberturaFormatter
jessebs commented 5 years ago

Any chance you tar up a sample project that produces the issue?

jessebs commented 5 years ago

The spec file below produces a coverage report in both rspec v2 and v3 with no warning.

require 'simplecov'
require 'simplecov-cobertura'

SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
SimpleCov.start

require_relative '../lib/blah'

RSpec.describe "something" do
  it "does something" do
  end
end

Running your example command provides a different error for me, so I cannot reproduce your original issue

It looks to me as though you are trying to use this gem as an rspec formatter. That's not what it is. It's a formatter for simplecov.

If that is in fact your intent, take a look at the documentation @ https://github.com/colszowka/simplecov which tells you how to integrate simplecov with rspec (or this seems to offer a concise example as well - https://medium.com/the-code-review/display-your-ruby-test-coverage-using-simplecov-gem-and-codeclimate-6db6336fe409).

If I am off-base regarding your intent, please let me know.

zherr commented 5 years ago

Yes! Check this out: bug-7.zip

Once in the project directory, run:

bundle install
bundle exec rspec --format SimpleCov::Formatter::CoberturaFormatter

And you should see the warning.

jessebs commented 5 years ago

The --format flag of rspec is to indicate the format of the rspec output. The simplecov cobertura formatter is NOT an rspec formatter, but is a simplecov formatter.

If you just run bundle exec rspec from your sample project, you will see the simplecov output in coverage/coverage.xml

zherr commented 5 years ago

Thanks @jessebs , you're right! User error. Closing!