Sha256: da80c46dab89c5c2e890cde3119a7803ab1258cdd9e6f92cb29725f4db675a25

Contents?: true

Size: 991 Bytes

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb