Skip to content

Fix NoMethodError in formatters= for non-Array arguments#1224

Open
koic wants to merge 1 commit into
simplecov-ruby:mainfrom
koic:fix_formatters_setter_regression
Open

Fix NoMethodError in formatters= for non-Array arguments#1224
koic wants to merge 1 commit into
simplecov-ruby:mainfrom
koic:fix_formatters_setter_regression

Conversation

@koic

@koic koic commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

simplecov 1.0.0 broke a formatter configuration pattern the README documented for years:

SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
  SimpleCov::Formatter::HTMLFormatter,
  SimpleCov::Formatter::JSONFormatter,
])

MultiFormatter.new returns a Class, not an Array, so the 1.0.0 setter raised NoMethodError on formatters.empty?. Up to 0.22.x the setter handed the value straight to MultiFormatter.new, whose internal Array() call normalized single formatters transparently.

This surfaced in ruby/ruby CI, where net-imap's test helper still uses the pattern above: https://github.com/ruby/ruby/actions/runs/29193505325/job/86652245625?pr=17830

Restore the 0.22.x tolerance by normalizing the setter input with Array(). As a side effect formatters = nil now opts out of formatting, consistent with the formatter false / formatters [] opt-out semantics introduced in 1.0.0.

simplecov 1.0.0 broke a formatter configuration pattern the README documented for years:

```ruby
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
  SimpleCov::Formatter::HTMLFormatter,
  SimpleCov::Formatter::JSONFormatter,
])
```

`MultiFormatter.new` returns a `Class`, not an `Array`, so the 1.0.0 setter raised `NoMethodError` on
`formatters.empty?`. Up to 0.22.x the setter handed the value straight to `MultiFormatter.new`,
whose internal `Array()` call normalized single formatters transparently.

This surfaced in ruby/ruby CI, where net-imap's test helper still uses the pattern above:
https://github.com/ruby/ruby/actions/runs/29193505325/job/86652245625?pr=17830

Restore the 0.22.x tolerance by normalizing the setter input with `Array()`.
As a side effect `formatters = nil` now opts out of formatting, consistent with the `formatter false` /
`formatters []` opt-out semantics introduced in 1.0.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant