Skip to content

Commit

Permalink
Update to ruby/mspec@3cf2d16
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jun 26, 2023
1 parent 4fc8b8f commit f73fa29
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/mspec/spec/runner/context_spec.rb
Expand Up @@ -914,7 +914,7 @@ def example.example(state, spec)

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
Expand Down
51 changes: 50 additions & 1 deletion spec/mspec/tool/remove_old_guards.rb
Expand Up @@ -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)
Expand All @@ -64,7 +109,11 @@ def search(regexp)
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}/)

0 comments on commit f73fa29

Please sign in to comment.