Sha256: 9a7ee3ae1bf3f240426e4e1aad117d0105dca1fdc62f259ea30fb7430d38922c

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::LambdaCall, :config do
  subject(:cop) { described_class.new(config) }

  context 'when style is set to call' do
    let(:cop_config) { { 'EnforcedStyle' => 'call' } }

    it 'registers an offence for x.()' do
      inspect_source(cop,
                     ['x.(a, b)'])
      expect(cop.offences.size).to eq(1)
      expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'braces')
    end

    it 'registers an offence for correct + opposite' do
      inspect_source(cop,
                     ['x.call(a, b)',
                      'x.(a, b)'])
      expect(cop.offences.size).to eq(1)
      expect(cop.config_to_allow_offences).to eq('Enabled' => false)
    end

    it 'accepts x.call()' do
      inspect_source(cop, ['x.call(a, b)'])
      expect(cop.offences).to be_empty
    end

    it 'auto-corrects x.() to x.call()' do
      new_source = autocorrect_source(cop, ['a.(x)'])
      expect(new_source).to eq('a.call(x)')
    end
  end

  context 'when style is set to braces' do
    let(:cop_config) { { 'EnforcedStyle' => 'braces' } }

    it 'registers an offence for x.call()' do
      inspect_source(cop,
                     ['x.call(a, b)'])
      expect(cop.offences.size).to eq(1)
      expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'call')
    end

    it 'registers an offence for opposite + correct' do
      inspect_source(cop,
                     ['x.call(a, b)',
                      'x.(a, b)'])
      expect(cop.offences.size).to eq(1)
      expect(cop.config_to_allow_offences).to eq('Enabled' => false)
    end

    it 'accepts x.()' do
      inspect_source(cop, ['x.(a, b)'])
      expect(cop.offences).to be_empty
    end

    it 'auto-corrects x.call() to x.()' do
      new_source = autocorrect_source(cop, ['a.call(x)'])
      expect(new_source).to eq('a.(x)')
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/lambda_call_spec.rb