Sha256: f0ff45d4e83ff3397195e33b403201fb6f6b99a0248deb6bbe4620c5cc24a698

Contents?: true

Size: 991 Bytes

Versions: 8

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 offence for def with empty parens' do
    src = ['def func()',
           'end']
    inspect_source(cop, src)
    expect(cop.offences.size).to eq(1)
  end

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

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

  it 'accepts empty parentheses in one liners' do
    src = ["def to_s() join '/' end"]
    inspect_source(cop, src)
    expect(cop.offences).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

8 entries across 8 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.16.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb