Sha256: 4fe18d2a489cb7011ea6d994d7db30d978768684d1846a1c7c3b8e7723a75d43

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::DefWithoutParentheses do
  subject(:cop) { described_class.new }

  it 'reports an offence for def with parameters but no parens' do
    src = ['def func a, b',
           'end']
    inspect_source(cop, src)
    expect(cop.offences.size).to eq(1)
  end

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

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

  it 'auto-adds required parens' do
    new_source = autocorrect_source(cop, 'def test param; end')
    expect(new_source).to eq('def test (param); end')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.15.0 spec/rubocop/cop/style/def_without_parentheses_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/def_without_parentheses_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/def_without_parentheses_spec.rb