Skip to content

Commit

Permalink
Merge pull request #15 from fluxfederation/rspec_sorting
Browse files Browse the repository at this point in the history
Proactively sort splittable specs to be processed first
  • Loading branch information
aclemons authored Apr 15, 2020
2 parents 24ae8cb + 45998f8 commit 162dbcc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## Unreleased
### Updated
- Proactively sort splittable rspec files so all splittable files are processed first

## [1.0.15] - 2020-04-07
### Updated
- Support parsing results when using the --retry flag with cucumber
Expand Down
2 changes: 1 addition & 1 deletion lib/nitra/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def map_files_to_frameworks(files)

def load_files_from_framework_list
@files_by_framework = configuration.frameworks.inject({}) do |result, (framework_name, framework_patterns)|
files = Nitra::Workers::Worker.worker_classes[framework_name].files(framework_patterns)
files = Nitra::Workers::Worker.worker_classes[framework_name].files(configuration, framework_patterns)
result[framework_name] = files unless files.empty?
result
end
Expand Down
2 changes: 1 addition & 1 deletion lib/nitra/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def framework_name
self.name.split("::").last.downcase
end

def files(patterns)
def files(configuration, patterns)
Dir[*patterns].sort_by {|f| File.size(f)}.reverse
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/nitra/workers/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def minimal_file
EOS
end

# sort spec files so splittable files get split first
def files(configuration, patterns)
sorted_files = super(configuration, patterns)

return sorted_files unless configuration.split_rspec_files

# [[splittable_file], [not_splittable_file]].flatten
sorted_files.partition do |file|
configuration.split_rspec_files_regex && file.name =~ configuration.split_rspec_files_regex
end.flatten
end

##
# Run an rspec file.
#
Expand Down

0 comments on commit 162dbcc

Please sign in to comment.