Sha256: 87d6d9d2c744a1071056e396fb911563d00e4c9bed73bc34895ffaeb3d5650ed

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 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

shared_examples_for 'misaligned' do |prefix, alignment_base, arg, end_kw, name|
  name ||= alignment_base
  it "registers an offense for mismatched #{name} ... end" do
    inspect_source(cop, ["#{prefix}#{alignment_base} #{arg}",
                         end_kw])
    expect(cop.offenses.size).to eq(1)
    regexp = /`end` at 2, \d+ is not aligned with `#{alignment_base}` at 1,/
    expect(cop.messages.first).to match(regexp)
    expect(cop.highlights.first).to eq('end')
    expect(cop.config_to_allow_offenses).to eq('AlignWith' => opposite)
  end
end

shared_examples_for 'aligned' do |alignment_base, arg, end_kw, name|
  name ||= alignment_base
  it "accepts matching #{name} ... end" do
    inspect_source(cop, ["#{alignment_base} #{arg}",
                         end_kw])
    expect(cop.offenses).to be_empty
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/support/shared_examples.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/support/shared_examples.rb
rubocop-0.29.1 spec/support/shared_examples.rb
rubocop-0.29.0 spec/support/shared_examples.rb
rubocop-0.28.0 spec/support/shared_examples.rb
rubocop-0.27.1 spec/support/shared_examples.rb
rubocop-0.27.0 spec/support/shared_examples.rb
rubocop-0.26.1 spec/support/shared_examples.rb
rubocop-0.26.0 spec/support/shared_examples.rb
rubocop-0.25.0 spec/support/shared_examples.rb
rubocop-0.24.1 spec/support/shared_examples.rb
rubocop-0.24.0 spec/support/shared_examples.rb