Sha256: e37876b4cfabc7ef3180a6fb6304712119c9eac335d05fbc6e0db62c9dc367bc

Contents?: true

Size: 991 Bytes

Versions: 4

Compression:

Stored size: 991 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::DefWithParentheses do
  subject(:cop) { described_class.new }

  it 'reports an offense for def with empty parens' do
    src = ['def func()',
           'end']
    inspect_source(cop, src)
    expect(cop.offenses.size).to eq(1)
  end

  it 'reports an offense for class def with empty parens' do
    src = ['def Test.func()',
           'end']
    inspect_source(cop, src)
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts def with arg and parens' do
    src = ['def func(a)',
           'end']
    inspect_source(cop, src)
    expect(cop.offenses).to be_empty
  end

  it 'accepts empty parentheses in one liners' do
    src = ["def to_s() join '/' end"]
    inspect_source(cop, src)
    expect(cop.offenses).to be_empty
  end

  it 'auto-removes unneeded parens' do
    new_source = autocorrect_source(cop, "def test();\nsomething\nend")
    expect(new_source).to eq("def test;\nsomething\nend")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.25.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.24.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.24.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.23.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb