Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles authored Sep 26, 2024
2 parents 82e9d17 + 5959ad6 commit 9802d19
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 15 deletions.
22 changes: 11 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,34 @@ RSpec:
- expect_no_offenses
- expect_offense

RSpec/DescribeClass:
Exclude:
- spec/project/**/*.rb

RSpec/ExampleLength:
CountAsOne:
- heredoc
Max: 11

RSpec/DescribeClass:
Exclude:
- spec/project/**/*.rb

RSpec/MultipleExpectations:
Max: 2

RSpec/SpecFilePathFormat:
Exclude:
- spec/rubocop/cop/rspec/mixin/**/*.rb

# `expect_offense` does not use Kernel#format or String#%
Style/FormatStringToken:
Exclude:
- spec/rubocop/**/*.rb

Style/RequireOrder:
Enabled: true

RSpec/SpecFilePathFormat:
Exclude:
- spec/rubocop/cop/rspec/mixin/**/*.rb

Style/NumberedParameters:
Enabled: true
EnforcedStyle: disallow

Style/RequireOrder:
Enabled: true

# Enable RuboCop's pending cops up to v1.63

Gemspec/DeprecatedAttributeAssignment: {Enabled: true}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Master (Unreleased)

- Add `RSpec/StringAsInstanceDoubleConstant` to check for and correct strings used as instance_doubles. ([@corsonknowles])
- Fix false-positive for `RSpec/UnspecifiedException` when a method is literally named `raise_exception`. ([@aarestad])
- Fix false-positive for `RSpec/UnspecifiedException` when `not_to raise_error` is used within a block. ([@aarestad], [@G-Rath])

## 3.0.5 (2024-09-07)

Expand Down Expand Up @@ -901,6 +903,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.

<!-- Contributors (alphabetically) -->

[@aarestad]: https://github.com/aarestad
[@abrom]: https://github.com/abrom
[@ahukkanen]: https://github.com/ahukkanen
[@akiomik]: https://github.com/akiomik
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/change_by_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def on_send(node)
# rubocop:disable Metrics/MethodLength
def register_offense(node, change_node)
if compound_expectations?(node)
add_offense(node.source_range,
add_offense(node,
message: message_compound(change_node)) do |corrector|
autocorrect_compound(corrector, node)
end
else
add_offense(node.source_range,
add_offense(node,
message: message(change_node)) do |corrector|
autocorrect(corrector, node, change_node)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/expect_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def on_send(node) # rubocop:disable Metrics/MethodLength
expect_literal(node) do |actual, send_node, matcher, expected|
next if SKIPPED_MATCHERS.include?(matcher)

add_offense(actual.source_range) do |corrector|
add_offense(actual) do |corrector|
next unless CORRECTABLE_MATCHERS.include?(matcher)
next if literal?(expected)

Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/cop/rspec/unspecified_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def empty_exception_matcher?(node)
end

def find_expect_to(node)
node.each_ancestor(:send).find do |ancestor|
node.each_ancestor.find do |ancestor|
break if ancestor.block_type?
next unless ancestor.send_type?

expect_to?(ancestor)
end
end
Expand Down
56 changes: 56 additions & 0 deletions spec/rubocop/cop/rspec/unspecified_exception_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@
}.to raise_error(my_exception)
RUBY
end

it 'allows a subject function to be named raise_error' do
expect_no_offenses(<<~RUBY)
def raise_exception
raise StandardError
end
expect {
raise_error
}.to raise_error(StandardError)
RUBY
end

it 'allows a subject function to be named raise_exception' do
expect_no_offenses(<<~RUBY)
def raise_exception
raise StandardError
end
expect {
raise_exception
}.to raise_error(StandardError)
RUBY
end
end

context 'with raise_exception matcher' do
Expand Down Expand Up @@ -198,5 +222,37 @@
^^^^^^^^^^^^^^^ Specify the exception being captured
RUBY
end

it 'does not confuse blocks with chains' do
expect_no_offenses(<<~RUBY)
expect do
expect { foo }.not_to raise_error
end.to change(Foo, :count).by(3)
RUBY
end

it 'allows a subject function to be named raise_exception' do
expect_no_offenses(<<~RUBY)
def raise_error
raise StandardError
end
expect {
raise_exception
}.to raise_exception(StandardError)
RUBY
end

it 'allows a subject function to be named raise_error' do
expect_no_offenses(<<~RUBY)
def raise_error
raise StandardError
end
expect {
raise_error
}.to raise_exception(StandardError)
RUBY
end
end
end

0 comments on commit 9802d19

Please # to comment.