Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Master (Unreleased)

- Fix false positive in `RSpec/Pending`, where it would mark the default block `it` as an offense. ([@bquorning])
- Fix issue when `Style/ContextWording` is configured with a Prefix being interpreted as a boolean, like `on`. ([@sakuro])

## 3.5.0 (2025-02-16)

Expand Down Expand Up @@ -1040,6 +1041,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@rrosenblum]: https://github.com/rrosenblum
[@rspeicher]: https://github.com/rspeicher
[@rst-j]: https://github.com/RST-J
[@sakuro]: https://github.com/sakuro
[@samrjenkins]: https://github.com/samrjenkins
[@schmijos]: https://github.com/schmijos
[@seanpdoyle]: https://github.com/seanpdoyle
Expand Down
7 changes: 6 additions & 1 deletion lib/rubocop/cop/rspec/context_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ def expect_patterns
end

def prefixes
Array(cop_config.fetch('Prefixes', []))
Array(cop_config.fetch('Prefixes', [])).tap do |prefixes|
non_strings = prefixes.reject { |pre| pre.is_a?(String) }
unless non_strings.empty?
raise "Non-string prefixes #{non_strings.inspect} detected."
end
end
end
end
end
Expand Down
34 changes: 34 additions & 0 deletions spec/rubocop/cop/rspec/context_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,38 @@
RUBY
end
end

context 'when `Prefixes: [on]' do
let(:cop_config) do
YAML.safe_load(<<-CONFIG)
Prefixes:
- on # evaluates to true
CONFIG
end

it 'fails' do
expect do
expect_no_offenses(<<~RUBY)
context 'on Linux' do
end
RUBY
end.to raise_error(/Non-string prefixes .+ detected/)
end
end

context 'when `Prefixes: ["on"]' do
let(:cop_config) do
YAML.safe_load(<<-CONFIG)
Prefixes:
- "on"
CONFIG
end

it 'does not fail' do
expect { expect_no_offenses(<<~RUBY) }.not_to raise_error
context 'on Linux' do
end
RUBY
end
end
end