Sha256: 2a8379ff7725d2961d4c6e411476bbbe1c52e5b8bfedc9d09f447b1150154570

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Lint::ParenthesesAsGroupedExpression do
  subject(:cop) { described_class.new }

  it 'registers an offense for method call with space before the ' \
     'parenthesis' do
    inspect_source(cop, ['a.func (x)'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for predicate method call with space ' \
     'before the parenthesis' do
    inspect_source(cop, ['is? (x)'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for math expression' do
    inspect_source(cop, ['puts (2 + 3) * 4'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts a method call without arguments' do
    inspect_source(cop, ['func'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts a method call with arguments but no parentheses' do
    inspect_source(cop, ['puts x'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts a chain of method calls' do
    inspect_source(cop, ['a.b',
                         'a.b 1',
                         'a.b(1)'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts method with parens as arg to method without' do
    inspect_source(cop, ['a b(c)'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts an operator call with argument in parentheses' do
    inspect_source(cop, ['a % (b + c)',
                         'a.b = (c == d)'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts a space inside opening paren followed by left paren' do
    inspect_source(cop, ['a( (b) )'])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.21.0 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.20.1 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.20.0 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.19.1 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.19.0 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb