Sha256: 65a2ab1930d76e9c5cc2be2588cadd0fdd0e8a8a50d309ced18950f6719a695f

Contents?: true

Size: 703 Bytes

Versions: 6

Compression:

Stored size: 703 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

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

  it 'registers an offense for a Proc.new call' do
    inspect_source(cop, ['f = Proc.new { |x| puts x }'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts the proc method' do
    inspect_source(cop, ['f = proc { |x| puts x }'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts the Proc.new call outside of block' do
    inspect_source(cop, ['p = Proc.new'])
    expect(cop.offenses).to be_empty
  end

  it 'auto-corrects Proc.new to proc' do
    corrected = autocorrect_source(cop, ['Proc.new { test }'])
    expect(corrected).to eq 'proc { test }'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/proc_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/proc_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/proc_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/proc_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/proc_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/proc_spec.rb