Sha256: 4d40c9fd779efa578965642b20556e41dbd1f361ddf9390f37d44b379a9305ed

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

# encoding: utf-8

require 'spec_helper'

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

  let(:config) do
    RuboCop::Config.new(
      { 'AllCops' => { 'Include' => includes } },
      '/some/.rubocop.yml'
    )
  end

  let(:includes) { [] }
  let(:source) { ['print 1'] }
  let(:processed_source) { parse_source(source) }

  before do
    allow(processed_source.buffer)
    .to receive(:name).and_return(filename)
    _investigate(cop, processed_source)
  end

  context 'with camelCase file names ending in .rb' do
    let(:filename) { '/some/dir/testCase.rb' }

    it 'reports an offense' do
      expect(cop.offenses.size).to eq(1)
    end
  end

  context 'with camelCase file names without file extension' do
    let(:filename) { '/some/dir/testCase' }

    it 'reports an offense' do
      expect(cop.offenses.size).to eq(1)
    end
  end

  context 'with snake_case file names ending in .rb' do
    let(:filename) { '/some/dir/test_case.rb' }

    it 'reports an offense' do
      expect(cop.offenses).to be_empty
    end
  end

  context 'with snake_case file names without file extension' do
    let(:filename) { '/some/dir/test_case' }

    it 'does not report an offense' do
      expect(cop.offenses).to be_empty
    end
  end

  context 'with snake_case file names with non-rb extension' do
    let(:filename) { '/some/dir/some_task.rake' }

    it 'does not report an offense' do
      expect(cop.offenses).to be_empty
    end
  end

  context 'with snake_case file names with multiple extensions' do
    let(:filename) { 'some/dir/some_view.html.slim_spec.rb' }

    it 'does not report an offense' do
      expect(cop.offenses).to be_empty
    end
  end

  context 'when the file is specified in AllCops/Include' do
    let(:includes) { ['**/Gemfile'] }

    context 'with a non-snake_case file name' do
      let(:filename) { '/some/dir/Gemfile' }

      it 'does not report an offense' do
        expect(cop.offenses).to be_empty
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

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