Sha256: 1c907d143b1f8015d3f02cf22efbf52d91deb48b3e7bf9c0007d4d42c55e12f3

Contents?: true

Size: 1.86 KB

Versions: 11

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 offense for x.()' do
      inspect_source(cop,
                     ['x.(a, b)'])
      expect(cop.offenses.size).to eq(1)
      expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'braces')
    end

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

    it 'accepts x.call()' do
      inspect_source(cop, ['x.call(a, b)'])
      expect(cop.offenses).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 offense for x.call()' do
      inspect_source(cop,
                     ['x.call(a, b)'])
      expect(cop.offenses.size).to eq(1)
      expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'call')
    end

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

    it 'accepts x.()' do
      inspect_source(cop, ['x.(a, b)'])
      expect(cop.offenses).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

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/lambda_call_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.28.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.27.1 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.27.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.26.1 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.26.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.25.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.24.1 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.24.0 spec/rubocop/cop/style/lambda_call_spec.rb
rubocop-0.23.0 spec/rubocop/cop/style/lambda_call_spec.rb