Sha256: 0bfa91f7fa1e9691475bd5d1a7f5cd134e2a57e4860e799ee1fb8dbac82c5d30

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 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.offences).to be_empty
  end
end

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

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

      expect(cop.offences.count).to eq(offences_by_mri.count)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubocop-0.12.0 spec/support/shared_examples.rb
rubocop-0.11.1 spec/support/shared_examples.rb
rubocop-0.11.0 spec/support/shared_examples.rb
rubocop-0.10.0 spec/support/shared_examples.rb
rubocop-0.9.1 spec/support/shared_examples.rb
sabat-rubocop-0.9.0 spec/support/shared_examples.rb
rubocop-0.9.0 spec/support/shared_examples.rb