This commit is contained in:
Benoit Daloze 2023-06-26 15:55:09 +02:00
Родитель 4fc8b8f06d
Коммит f73fa29927
2 изменённых файлов: 51 добавлений и 2 удалений

Просмотреть файл

@ -914,7 +914,7 @@ RSpec.describe ContextState, "#it_should_behave_like" do
it "raises an Exception if unable to find the shared ContextState" do
expect(MSpec).to receive(:retrieve_shared).and_return(nil)
expect { @state.it_should_behave_like "this" }.to raise_error(Exception)
expect { @state.it_should_behave_like :this }.to raise_error(Exception)
end
describe "for nested ContextState instances" do

Просмотреть файл

@ -46,6 +46,51 @@ def remove_guards(guard, keep)
end
end
def remove_empty_files
each_spec_file do |file|
unless file.include?("fixtures/")
lines = File.readlines(file)
if lines.all? { |line| line.chomp.empty? or line.start_with?('require', '#') }
puts "Removing empty file #{file}"
File.delete(file)
end
end
end
end
def remove_unused_shared_specs
shared_groups = {}
# Dir["**/shared/**/*.rb"].each do |shared|
each_spec_file do |shared|
next if File.basename(shared) == 'constants.rb'
contents = File.binread(shared)
found = false
contents.scan(/^\s*describe (:[\w_?]+), shared: true do$/) {
shared_groups[$1] = 0
found = true
}
if !found and shared.include?('shared/') and !shared.include?('fixtures/') and !shared.end_with?('/constants.rb')
puts "no shared describe in #{shared} ?"
end
end
each_spec_file do |file|
contents = File.binread(file)
contents.scan(/(?:it_behaves_like|it_should_behave_like) (:[\w_?]+)[,\s]/) do
puts $1 unless shared_groups.key?($1)
shared_groups[$1] += 1
end
end
shared_groups.each_pair do |group, value|
if value == 0
puts "Shared describe #{group} seems unused"
elsif value == 1
puts "Shared describe #{group} seems used only once" if $VERBOSE
end
end
end
def search(regexp)
each_spec_file do |file|
contents = File.binread(file)
@ -64,7 +109,11 @@ version = Regexp.escape(ARGV.fetch(0))
version += "(?:\\.0)?" if version.count(".") < 2
remove_guards(/ruby_version_is (["'])#{version}\1 do/, true)
remove_guards(/ruby_version_is (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, false)
remove_guards(/ruby_bug "#\d+", (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, true)
remove_guards(/ruby_bug ["']#\d+["'], (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, true)
remove_empty_files
remove_unused_shared_specs
puts "Search:"
search(/(["'])#{version}\1/)
search(/^\s*#.+#{version}/)