Skip to content

Commit

Permalink
Merge pull request #209 from 8675309/PDK-429_JS
Browse files Browse the repository at this point in the history
(PDK-429) add tests argument to rake spec
  • Loading branch information
bmjen committed Nov 14, 2017
2 parents 278f3fa + dc8133e commit d7e38b3
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/puppetlabs_spec_helper/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@

pattern = 'spec/{aliases,classes,defines,unit,functions,hosts,integration,type_aliases,types}/**/*_spec.rb'


desc "Run spec tests on an existing fixtures directory"
RSpec::Core::RakeTask.new(:spec_standalone) do |t|
RSpec::Core::RakeTask.new(:spec_standalone) do |t, args|
t.rspec_opts = ['--color']

t.rspec_opts << ENV['CI_SPEC_OPTIONS'] unless ENV['CI_SPEC_OPTIONS'].nil?

if ENV['CI_NODE_TOTAL'] && ENV['CI_NODE_INDEX']
ci_total = ENV['CI_NODE_TOTAL'].to_i
ci_index = ENV['CI_NODE_INDEX'].to_i
raise "CI_NODE_INDEX must be between 1-#{ci_total}" unless ci_index >= 1 && ci_index <= ci_total

files = Rake::FileList[pattern].to_a
per_node = (files.size / ci_total.to_f).ceil
t.pattern = files.each_slice(per_node).to_a[ci_index - 1] || files.first
t.pattern = if args.extras.nil? || args.extras.empty?
files.each_slice(per_node).to_a[ci_index - 1] || files.first
else
args.extras.join(",")
end
else
t.pattern = pattern
if args.extras.nil? || args.extras.empty?
t.pattern = pattern
else
t.pattern = args.extras.join(",")
end
end
end

Expand Down Expand Up @@ -401,10 +404,10 @@ def max_thread_limit
end

desc "Run spec tests and clean the fixtures directory if successful"
task :spec do
task :spec do |t, args|
begin
Rake::Task[:spec_prep].invoke
Rake::Task[:spec_standalone].invoke
Rake::Task[:spec_standalone].invoke(*args.extras)
ensure
Rake::Task[:spec_clean].invoke
end
Expand Down

0 comments on commit d7e38b3

Please sign in to comment.