Skip to content

Commit 1adcc3c

Browse files
committed
1 parent 38b5987 commit 1adcc3c

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

spec/mspec/spec/runner/context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def example.example(state, spec)
914914

915915
it "raises an Exception if unable to find the shared ContextState" do
916916
expect(MSpec).to receive(:retrieve_shared).and_return(nil)
917-
expect { @state.it_should_behave_like "this" }.to raise_error(Exception)
917+
expect { @state.it_should_behave_like :this }.to raise_error(Exception)
918918
end
919919

920920
describe "for nested ContextState instances" do

spec/mspec/tool/remove_old_guards.rb

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,51 @@ def remove_guards(guard, keep)
4646
end
4747
end
4848

49+
def remove_empty_files
50+
each_spec_file do |file|
51+
unless file.include?("fixtures/")
52+
lines = File.readlines(file)
53+
if lines.all? { |line| line.chomp.empty? or line.start_with?('require', '#') }
54+
puts "Removing empty file #{file}"
55+
File.delete(file)
56+
end
57+
end
58+
end
59+
end
60+
61+
def remove_unused_shared_specs
62+
shared_groups = {}
63+
# Dir["**/shared/**/*.rb"].each do |shared|
64+
each_spec_file do |shared|
65+
next if File.basename(shared) == 'constants.rb'
66+
contents = File.binread(shared)
67+
found = false
68+
contents.scan(/^\s*describe (:[\w_?]+), shared: true do$/) {
69+
shared_groups[$1] = 0
70+
found = true
71+
}
72+
if !found and shared.include?('shared/') and !shared.include?('fixtures/') and !shared.end_with?('/constants.rb')
73+
puts "no shared describe in #{shared} ?"
74+
end
75+
end
76+
77+
each_spec_file do |file|
78+
contents = File.binread(file)
79+
contents.scan(/(?:it_behaves_like|it_should_behave_like) (:[\w_?]+)[,\s]/) do
80+
puts $1 unless shared_groups.key?($1)
81+
shared_groups[$1] += 1
82+
end
83+
end
84+
85+
shared_groups.each_pair do |group, value|
86+
if value == 0
87+
puts "Shared describe #{group} seems unused"
88+
elsif value == 1
89+
puts "Shared describe #{group} seems used only once" if $VERBOSE
90+
end
91+
end
92+
end
93+
4994
def search(regexp)
5095
each_spec_file do |file|
5196
contents = File.binread(file)
@@ -64,7 +109,11 @@ def search(regexp)
64109
version += "(?:\\.0)?" if version.count(".") < 2
65110
remove_guards(/ruby_version_is (["'])#{version}\1 do/, true)
66111
remove_guards(/ruby_version_is (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, false)
67-
remove_guards(/ruby_bug "#\d+", (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, true)
112+
remove_guards(/ruby_bug ["']#\d+["'], (["'])[0-9.]*\1 *... *(["'])#{version}\2 do/, true)
113+
114+
remove_empty_files
115+
remove_unused_shared_specs
68116

117+
puts "Search:"
69118
search(/(["'])#{version}\1/)
70119
search(/^\s*#.+#{version}/)

0 commit comments

Comments
 (0)