Skip to content

Commit

Permalink
Sort files to require for coverage reports
Browse files Browse the repository at this point in the history
Dir.glob don't guarantee the order of the files it returns
For example we have model in
app/model/rss_feed.rb and his extension in
app/model/rss_feed/import_export.rb - there is class
defined without inheriting from ApplicationRecord
so when class from import_export.rb is loaded first
is it loaded as RssFeed < Object and when
after this is app/model/rss_feed.rb loaded
it is causing error(this warning is suppressed by
silence_warnings):

TypeError: superclass mismatch for class RssFeed

and then RssFeed < ApplicationRecord is not loaded

Sorting Dir.glob guarantee order so that
files will be first then subdirectories,..
() because '.'.ord < '/'.ord
(sort is also used in eager_load!
https://github.com/rails/rails/blob/master/railties/lib/rails/engine.rb#L475)
  • Loading branch information
lpichler committed Mar 2, 2017
1 parent 8710eed commit 7b3d7b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spec/coverage_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Require all ruby files for accuracte test coverage reports
%w(app lib).each do |path|
Dir.glob(Rails.root.join(path, "**", "*.rb")) do |file|
Dir.glob(Rails.root.join(path, "**", "*.rb")).sort.each do |file|
next if file.include?("/bin/") || file.include?("/spec/") || file.include?("/lib/generators/provider/templates/")
begin
silence_warnings { require file }
Expand Down

0 comments on commit 7b3d7b6

Please sign in to comment.