Sha256: 14cafd2184863bb1287404fdeb5bb572a6c26db15b591a5980fdf884c0b44b35

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

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

    it 'auto-corrects extra space' do
      new_source = autocorrect_source(cop, ['something  x',
                                            'a.something   y, z'])
      expect(new_source).to eq(['something x',
                                'a.something y, z'].join("\n"))
    end

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

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

    it 'accepts setter call' do
      inspect_source(cop, ['something.x =',
                           '  y'])
      expect(cop.offenses).to be_empty
    end

    it 'accepts multiple space containing line break' 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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/single_space_before_first_arg_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/single_space_before_first_arg_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/single_space_before_first_arg_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/single_space_before_first_arg_spec.rb