Sha256: 74277201764b9e907c4786fddca485c82aee9582a2e38588d3ffc0a3e8ba8417

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

# `cop` and `source` must be declared with #let.

shared_examples_for 'accepts' do
  it 'accepts' do
    inspect_source(cop, source)
    expect(cop.offenses).to be_empty
  end
end

shared_examples_for 'mimics MRI 2.1' do |grep_mri_warning|
  if RUBY_ENGINE == 'ruby' && RUBY_VERSION.start_with?('2.1')
    it "mimics MRI #{RUBY_VERSION} built-in syntax checking" do
      inspect_source(cop, source)
      offenses_by_mri = MRISyntaxChecker.offenses_for_source(
        source, cop.name, grep_mri_warning
      )

      # Compare objects before comparing counts for clear failure output.
      cop.offenses.each_with_index do |offense_by_cop, index|
        offense_by_mri = offenses_by_mri[index]
        # Exclude column attribute since MRI does not
        # output column number.
        [:severity, :line, :cop_name].each do |a|
          expect(offense_by_cop.send(a)).to eq(offense_by_mri.send(a))
        end
      end

      expect(cop.offenses.count).to eq(offenses_by_mri.count)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.23.0 spec/support/shared_examples.rb
rubocop-0.22.0 spec/support/shared_examples.rb
rubocop-0.21.0 spec/support/shared_examples.rb
rubocop-0.20.1 spec/support/shared_examples.rb
rubocop-0.20.0 spec/support/shared_examples.rb
rubocop-0.19.1 spec/support/shared_examples.rb
rubocop-0.19.0 spec/support/shared_examples.rb