rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

New cop to disallow before and a single test case

Open fatkodima opened this issue 1 year ago • 2 comments

It makes little sense to write the test code like

context 'when something' do
  before do
    # some setup
  end

  it 'tests something' do # <--- only one test case
    # some testing
  end
end

The test is now unnecessary segregated. When more before blocks precedes it outside of the context it is even harder to combine all these pieces.

Better is to write it like

context 'when something' do
  it 'tests something' do
    # some setup
    # some testing
  end
end

fatkodima avatar Nov 27 '24 19:11 fatkodima

Using DSL elements such as context, before, and it appropriately can be viewed as valid. So, it’s doubtful whether this should be regarded as "redundant" or as an appropriate use of vocabulary, as it depend on individual judgment. Forcing these to fit into a single line universally doesn’t seem reasonable. Even if this cop will be implemented, it should be disabled by default.

koic avatar Jan 08 '25 12:01 koic

IMO, I am reluctant to add this cop. Our project goal is to enforce the guidelines and best practices outlined in the community RSpec style guide. Currently, I am skeptical about whether this approach qualifies as a best practice. As a first step, it might be better to start by discussing in the RSpec Style Guide.

ydah avatar Jan 08 '25 15:01 ydah