rubocop / rubocop/ruby-style-guide
Style/BlockDelimiters breaks natural language of rspec matchers
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
RSpec Expectations allow syntax like:
expect { ... some code ... }.to raise_error(MyErrorClass, my_error_message)
However if the code under test is not trivially short, it will need to be split onto multiple lines, e.g. here's some real-world code:
it "should barf if the definition's type is not right" do
expect {
fixture.definition = "sometype #{fixture.name} blah blah"
}.to \
raise_error(
Pacemaker::CIBObject::TypeMismatch,
"Expected #{object_type} type but loaded definition was type sometype"
)
end
but this causes
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
https://github.com/bbatsov/ruby-style-guide#single-line-blocks
complaints from rubocop.
The problem is that changing it to
expect do
... some code ...
end.to raise_error(MyErrorClass, my_error_message)
completely ruins the previously natural language flow of the "expect ... to" statement. So what's the solution?
A related problem is that I'm also struggling to find a combination of line breaks/continuations and indentation which looks good here. Suggestions very welcome.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the RSpec Expectations examples and the Style/BlockDelimiters complaint in this issue, then read the comment thread for any agreed direction. A completed change would document a clear recommendation for formatting multi-line matcher expectations without losing the natural "expect ... to" flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100