Sha256: a44a45e9558269bc43c5c4fd62df0811ab52fb2b90e3e0962cb247c7b52fbe0f

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  context 'for method calls without parentheses' do
    it 'registers an offense for method call with no space before the ' \
       'first arg' do
      inspect_source(cop, ['something?x',
                           'a.something!y, z'])
      expect(cop.messages)
        .to eq(['Put space between the method name and the first ' \
                'argument.'] * 2)
      expect(cop.highlights).to eq(%w(x y))
    end

    it 'accepts a method call with space before the first arg' do
      inspect_source(cop, ['something? x',
                           'a.something! y, z'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts square brackets operator' do
      inspect_source(cop, ['something[:x]'])
      expect(cop.offenses).to be_empty
    end
  end

  context 'for method calls with parentheses' do
    it 'accepts a method call without space' do
      inspect_source(cop, ['something?(x)',
                           'a.something(y, z)'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts a method call with space after the left parenthesis' do
      inspect_source(cop, ['something?(  x  )'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts setter call' do
      inspect_source(cop, ['self.class.controller_path=(path)'])
      expect(cop.offenses).to be_empty
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.20.0 spec/rubocop/cop/lint/space_before_first_arg_spec.rb