Sha256: a38deed6c33c8cde2ae6efb4ab9230f4bfc5fe0fd8f1fd0aca0ac51c84983f00

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

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();',
                                          'something',
                                          'end'])
    expect(new_source).to eq(['def test;',
                              'something',
                              'end'].join("\n"))
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/def_with_parentheses_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/def_with_parentheses_spec.rb