Sha256: db9ac63b760a53ea3360eac2f87877efad189ba1ae181a8a8197e92bc2222476

Contents?: true

Size: 1.63 KB

Versions: 10

Compression:

Stored size: 1.63 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::Cop::Style::LeadingCommentSpace do
  subject(:cop) { described_class.new }

  it 'registers an offense for comment without leading space' do
    inspect_source(cop,
                   ['#missing space'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'does not register an offense for # followed by no text' do
    inspect_source(cop,
                   ['#'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for more than one space' do
    inspect_source(cop,
                   ['#   heavily indented'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for more than one #' do
    inspect_source(cop,
                   ['###### heavily indented'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for only #s' do
    inspect_source(cop,
                   ['######'])
    expect(cop.offenses).to be_empty
  end

  it 'does not register an offense for #! on first line' do
    inspect_source(cop,
                   ['#!/usr/bin/ruby',
                    'test'])
    expect(cop.offenses).to be_empty
  end

  it 'registers an offense for #! after the first line' do
    inspect_source(cop,
                   ['test', '#!/usr/bin/ruby'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts rdoc syntax' do
    inspect_source(cop,
                   ['#++',
                    '#--',
                    '#:nodoc:'])

    expect(cop.offenses).to be_empty
  end

  it 'auto-corrects missing space' do
    new_source = autocorrect_source(cop, '#comment')
    expect(new_source).to eq('# comment')
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

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