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

EmptyLineBetweenDefs doesn't register offense for multiline methods with comment headers #2124

Closed
deivid-rodriguez opened this issue Aug 8, 2015 · 3 comments
Labels

Comments

@deivid-rodriguez
Copy link
Contributor

diff --git a/spec/rubocop/cop/style/empty_line_between_defs_spec.rb b/spec/rubocop/cop/style/empty_line_between_defs_spec.rb
index 84d2da1..6c400fb 100644
--- a/spec/rubocop/cop/style/empty_line_between_defs_spec.rb
+++ b/spec/rubocop/cop/style/empty_line_between_defs_spec.rb
@@ -6,6 +6,30 @@ describe RuboCop::Cop::Style::EmptyLineBetweenDefs, :config do
   subject(:cop) { described_class.new(config) }
   let(:cop_config) { { 'AllowAdjacentOneLineDefs' => false } }

+  it 'finds offenses for adjacent multi-liners' do
+    source = ['  class J',
+              '    def n',
+              '    end',
+              '    def o',
+              '    end',
+              '  end']
+    inspect_source(cop, source)
+    expect(cop.offenses.size).to eq(1)
+  end
+
+  it 'finds offenses for adjacent multi-liners with comments' do
+    source = ['  class J',
+              '    # checks something n-related',
+              '    def n',
+              '    end',
+              '    # checks something o-related',
+              '    def o',
+              '    end',
+              '  end']
+    inspect_source(cop, source)
+    expect(cop.offenses.size).to eq(1)
+  end
+
   it 'finds offenses in inner classes' do
     source = ['class K',
               '  def m',

The first spec passes, but the second fails.

@bbatsov bbatsov assigned bbatsov and unassigned bbatsov Aug 9, 2015
@bbatsov bbatsov added the bug label Aug 9, 2015
unmanbearpig added a commit to unmanbearpig/rubocop that referenced this issue Aug 12, 2015
Checking if there are actually empty lines between defs instead of
looking for any lines between `def` nodes.
@unmanbearpig
Copy link
Contributor

Hi guys! I've fixed this issue as well before I found out that it's already fixed. I've fixed it a bit differently and did some refactoring.
What do you think?

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 12, 2015

Discuss this with @lumeet on the existing PR.

@unmanbearpig
Copy link
Contributor

Got it

bbatsov added a commit that referenced this issue Aug 18, 2015
…ments

[Fix #2124] Find only comments between defs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants