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

Cop idea: Excluding multi-line statements from RSpec/ExampleLength inspection #1261

Closed
j-miyake opened this issue Apr 19, 2022 · 3 comments
Closed

Comments

@j-miyake
Copy link
Contributor

j-miyake commented Apr 19, 2022

RSpec/ExampleLength detects this code as an offense.

it do
  expect(object).to(
    have_received(:some_method).with(
      value1,
      value2,
      value3,
      value4,
      keyword_arg1: value5,
      keyword_arg2: value6
    )
  )
end

Modifying the code like the below solves the offense, but I feel this one is less readable than the original one. (Especially when the name of each argument varies a lot.)

it do
  expect(object).to(
    have_received(:some_method).with(
      value1, value2, value3, value4,
      keyword_arg1: value5,
      keyword_arg2: value6
    )
  )
end

Should we add another option, or is there any way to avoid the offense by some configuration?

In the discussion where CountAsOne was introduced, this opinion makes sense to me.

I thought that maybe what we really want is to limit the number of top-level statements inside an example.
#1125

@pirj
Copy link
Member

pirj commented Apr 19, 2022

What about a 100-lines long:

expect(object).to have_received(:some_method).with(
  be_present,
  match(include(have_attributes(
   # lengthly list of 30 lines

Would such a declarative example still count as short?

@j-miyake
Copy link
Contributor Author

Your point is valid. Then it seems better to disable the cop for each test case by case rather than adding another feature to the cop, right? (Offenses like above may be considered a signal of the need for refactoring, though.)

@pirj
Copy link
Member

pirj commented Apr 20, 2022

I'm open to consider introduction of an option given an example that would not contribute to the example readability while breaking the default line length constraint.

@pirj pirj closed this as completed Apr 20, 2022
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

2 participants