rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
802 stars 276 forks source link

FilePath deficiencies #1701

Open pirj opened 1 year ago

pirj commented 1 year ago
  1. https://github.com/rubocop/rubocop-rspec/pull/1698#discussion_r1296729996 Would it detect:

    RSpec.describe 'MyClass' do
    RSpec.describe ::MyClass do
  2. https://github.com/rubocop/rubocop-rspec/pull/1698#discussion_r1296733977 refactor to avoid nested loops?

ydah commented 6 months ago

In the following case, I often use rspec-request_describer to write a request spec. So in the case of String, I don't think it will necessarily match the file path. WDYT? Is there a way to know that in the case of string, it always indicates Class?

RSpec.describe 'MyClass' do
pirj commented 6 months ago

Why? It could be /get_users_spec.rb as per request_descriptor naming schema, even with dynamic parts. Or /widget_management_spec.rb if you follow the example naming from rspec-rails examples http://rspec.info/features/6-1/rspec-rails/request-specs/request-spec/

I like it more descriptive and human-readable, with explicit URL defined in ‘def request’ or subject. And i don’t see why the file name should not match the top-level docstring.

ydah commented 6 months ago

rspec-request_describer is a plugin for RSpec, but it is useful to use it as follows, but if you use such a plug-in, it may not be a big problem because Exclude will not change the behavior in the first place before and after the change

# `RSpec::RequestDescriber` provides `subject` from its top-level description.
# subject will be `get('/users')`.
RSpec.describe 'GET /users' do
  it 'returns 200' do
    subject
    expect(response).to have_http_status(200)
  end
end