2020-03-20 14:09:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-15 20:08:33 -04:00
|
|
|
require 'fast_spec_helper'
|
2020-03-20 14:09:31 -04:00
|
|
|
require 'rubocop/rspec/support'
|
|
|
|
require_relative '../../../rubocop/cop/filename_length'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::FilenameLength do
|
2020-03-20 14:09:31 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'does not flag files with names 100 characters long' do
|
|
|
|
expect_no_offenses('puts "it does not matter"', 'a' * 100)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tags files with names 101 characters long' do
|
|
|
|
filename = 'a' * 101
|
|
|
|
|
|
|
|
expect_offense(<<~SOURCE, filename)
|
|
|
|
source code
|
|
|
|
^ This file name is too long. It should be 100 or less
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tags files with names 256 characters long' do
|
|
|
|
filename = 'a' * 256
|
|
|
|
|
|
|
|
expect_offense(<<~SOURCE, filename)
|
|
|
|
source code
|
|
|
|
^ This file name is too long. It should be 100 or less
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tags files with filepath 256 characters long' do
|
|
|
|
filepath = File.join 'a', 'b' * 254
|
|
|
|
|
|
|
|
expect_offense(<<~SOURCE, filepath)
|
|
|
|
source code
|
|
|
|
^ This file name is too long. It should be 100 or less
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tags files with filepath 257 characters long' do
|
|
|
|
filepath = File.join 'a', 'b' * 255
|
|
|
|
|
|
|
|
expect_offense(<<~SOURCE, filepath)
|
|
|
|
source code
|
|
|
|
^ This file path is too long. It should be 256 or less
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
end
|