Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint/UnreachableLoop false positive with should_receive and raise in block #9237

Closed
mmb opened this issue Dec 16, 2020 · 0 comments
Closed

Comments

@mmb
Copy link

mmb commented Dec 16, 2020

Expected behavior

rubocop should not identify this as an unreachable loop.

Actual behavior

rubocop identifies this as an unreachable loop.

Steps to reproduce the problem

test_spec.rb:

# frozen_string_literal: true

class SomeClass; end

describe 'test' do
  it 'test' do
    SomeClass.should_receive(:test).exactly(2).times { raise StandardError }
  end
end
For /private/tmp: Default configuration from /Users/me/.rvm/gems/ruby-2.4.2/gems/rubocop-1.6.1/config/default.yml
Inspecting 1 file
Scanning /private/tmp/test_spec.rb
Loading cache from /Users/me/.cache/rubocop_cache/0fe4423234f49f9a7a29f384c05d385bdc87c27f/6d7a3b621ca1730e04accd938619e4bdab66cfb1/cbd2ebc1b9a3baa10e15b9523bb86be7ea95cc25
W

Offenses:

test_spec.rb:7:5: W: Lint/UnreachableLoop: This loop will have at most one iteration.
    SomeClass.should_receive(:test).exactly(2).times { raise StandardError }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
Finished in 0.10298199998214841 seconds

RuboCop version

$ rubocop -V
warning: parser/current is loading parser/ruby24, which recognizes
warning: 2.4.10-compliant syntax, but you are running 2.4.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
1.6.1 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.4.2 x86_64-darwin18)
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Dec 16, 2020
…chableLoop` to allow for block methods that share a name with an `Enumerable` method.
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

No branches or pull requests

1 participant