sj26 / rspec_junit_formatter

RSpec results that your CI can read
http://rubygems.org/gems/rspec_junit_formatter
MIT License
302 stars 122 forks source link

NoMethodError: undefined method `+@' for "[^":String on Ruby 2.2 #94

Closed marcotc closed 2 years ago

marcotc commented 2 years ago

Since https://github.com/sj26/rspec_junit_formatter/releases/tag/v0.5.0, I started getting this error when using rspec_junit_formatter with Ruby 2.2.10p489:

# bundle exec rspec spec/ddtrace_spec.rb
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
No examples found.
bundler: failed to load command: rspec (/usr/local/bundle/bin/rspec)
NoMethodError: undefined method `+@' for "[^":String
  .../rspec_junit_formatter-0.5.0/lib/rspec_junit_formatter.rb:96:in `<class:RSpecJUnitFormatter>'
  .../rspec_junit_formatter-0.5.0/lib/rspec_junit_formatter.rb:11:in `<top (required)>'
  .../rspec-core-3.10.1/lib/rspec/core/formatters.rb:235:in `require'
  .../rspec-core-3.10.1/lib/rspec/core/formatters.rb:235:in `rescue in custom_formatter'
  .../rspec-core-3.10.1/lib/rspec/core/formatters.rb:232:in `custom_formatter'
  .../rspec-core-3.10.1/lib/rspec/core/formatters.rb:183:in `find_formatter'
  .../rspec-core-3.10.1/lib/rspec/core/formatters.rb:152:in `add'
  .../rspec-core-3.10.1/lib/rspec/core/configuration.rb:974:in `add_formatter'
  .../rspec-core-3.10.1/lib/rspec/core/configuration_options.rb:118:in `block in load_formatters_into'
  .../rspec-core-3.10.1/lib/rspec/core/configuration_options.rb:118:in `each'
  .../rspec-core-3.10.1/lib/rspec/core/configuration_options.rb:118:in `load_formatters_into'
  .../rspec-core-3.10.1/lib/rspec/core/configuration_options.rb:24:in `configure'
  .../rspec-core-3.10.1/lib/rspec/core/runner.rb:132:in `configure'
  .../rspec-core-3.10.1/lib/rspec/core/runner.rb:99:in `setup'
  .../rspec-core-3.10.1/lib/rspec/core/runner.rb:86:in `run'
  .../rspec-core-3.10.1/lib/rspec/core/runner.rb:71:in `run'
  .../rspec-core-3.10.1/lib/rspec/core/runner.rb:45:in `invoke'
  .../rspec-core-3.10.1/exe/rspec:4:in `<top (required)>'

I noticed that CI only runs for Ruby 2.6+.

If the intention is to drop support for Ruby < 2.6, updating https://github.com/sj26/rspec_junit_formatter/blob/7f69b4f00127563798bb74ab19eeca3fcb5be2d4/rspec_junit_formatter.gemspec#L12 with this requirement will allow older Rubies to continue working. Today, gem install rspec_junit_formatter will happily install 0.5.0 in older Rubies, but that version will not work.

sj26 commented 2 years ago

Ah, sorry about that! I've released v0.5.1 with 915c2a4 which should restore backwards compatibility with older rubies, and I'll restrict the supported ruby version in the gemspec for the next version.

sj26 commented 2 years ago

I can't run older rubies in my local environment, and they don't work on GitHub Actions, so please let me know if it's all working now or not 🙏

marcotc commented 2 years ago

@sj26 thank you for the super fast turnaround!

Your changes look good, but they are not reflected in rubygems.org (https://rubygems.org/gems/rspec_junit_formatter/versions/0.5.1): Screen Shot 2022-01-05 at 5 44 12 PM

Did you by any chance upload an older gem build to rubygems?

marcotc commented 2 years ago

By the way, I test old Ruby versions with docker: docker run --rm -it ruby:2.1 /bin/sh.

For this issue, I run gem install rspec_junit_formatter inside the container.

sj26 commented 2 years ago

Sorry I didn’t explain well: I fixed backwards compatibility and released a new version so that the gem will continue to work on old rubies, then I restricted the ruby version for future gem versions so that the same mistake doesn’t creep in. So you should be able to install the current gem version on older rubies and it should run without errors.

Thanks for the Docker tip!