@@ -46,6 +46,51 @@ def remove_guards(guard, keep)
46
46
end
47
47
end
48
48
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
+
49
94
def search ( regexp )
50
95
each_spec_file do |file |
51
96
contents = File . binread ( file )
@@ -64,7 +109,11 @@ def search(regexp)
64
109
version += "(?:\\ .0)?" if version . count ( "." ) < 2
65
110
remove_guards ( /ruby_version_is (["'])#{ version } \1 do/ , true )
66
111
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
68
116
117
+ puts "Search:"
69
118
search ( /(["'])#{ version } \1 / )
70
119
search ( /^\s *#.+#{ version } / )
0 commit comments