rspec-style-guide icon indicating copy to clipboard operation
rspec-style-guide copied to clipboard

Empty lines around multi-line `let` and `let!` blocks

Open ydakuka opened this issue 2 years ago • 2 comments
trafficstars

There is no information which style is preferred.

let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end
let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end
let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end

or

let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end

let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end

let :user do
  build(:user, profile: profile).tap do |user|
    user.save validate: false
  end
end

ydakuka avatar Jul 08 '23 11:07 ydakuka

It would be quite hard to formalize, as the boundaries are blurry.

Would

let(:user) do
  create(:user, <a lot of attributes that forced the author to use the multi-line syntax because of the max line length limitation>)
end
let(:another_user) { create(:user) } # nothing fancy

Why separate the two?

And on the other hand,

let(:user) { create(:user) }

# the line above intentionally left blank as it separates unrelated setup
let(:multiplier) { 3 }
let(:divisor) { 5 }

pirj avatar Oct 10 '23 21:10 pirj

Would you want to have this applied to all multiline blocks? If so, see https://github.com/rubocop/ruby-style-guide/issues/823

andyw8 avatar Oct 10 '23 22:10 andyw8