Sha256: 7621aed7dc473200073c6d7c0e26281f33c66a3ab1f78d3757365c524641c524

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

        it 'registers an offence for method call with space before the ' +
          'parenthesis' do
          inspect_source(cop, ['a.func (x)'])
          expect(cop.offences).to have(1).item
        end

        it 'registers an offence for predicate method call with space ' +
          'before the parenthesis' do
          inspect_source(cop, ['is? (x)'])
          expect(cop.offences).to have(1).item
        end

        it 'registers an offence for math expression' do
          inspect_source(cop, ['puts (2 + 3) * 4'])
          expect(cop.offences).to have(1).item
        end

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

        it 'accepts a method call with arguments but no parentheses' do
          inspect_source(cop, ['puts x'])
          expect(cop.offences).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.offences).to be_empty
        end

        it 'accepts method with parens as arg to method without' do
          inspect_source(cop, ['a b(c)'])
          expect(cop.offences).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.offences).to be_empty
        end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.13.1 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb
rubocop-0.13.0 spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb