Skip to content

Commit

Permalink
Make SAMPLE and SAMPLE_GROUPS consistent with seed for Minitest (#188)
Browse files Browse the repository at this point in the history
* Make SAMPLE and SAMPLE_GROUPS consistent with seed for Minitest

* update changelog

* rubocop offences
  • Loading branch information
stefkin committed Apr 23, 2020
1 parent f16c9e2 commit 88ba58a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## master (unreleased)

- SAMPLE and SAMPLE_GROUP work consistently with seed in RSpec. ([@stefkin][])
- SAMPLE and SAMPLE_GROUP work consistently with seed in RSpec and Minitest. ([@stefkin][])

- Make sure EventProf is not affected by time freezing. ([@palkan][])

Expand Down
3 changes: 3 additions & 0 deletions lib/minitest/test_prof_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.configure_options(options = {})
opts[:top_count] = ENV["EVENT_PROF_TOP"].to_i if ENV["EVENT_PROF_TOP"]
opts[:per_example] = true if ENV["EVENT_PROF_EXAMPLES"]
opts[:fdoc] = true if ENV["FDOC"]
opts[:sample] = true if ENV["SAMPLE"] || ENV["SAMPLE_GROUPS"]
end
end
end
Expand Down Expand Up @@ -39,5 +40,7 @@ def self.plugin_test_prof_init(options)

reporter << TestProf::EventProfReporter.new(options[:io], options) if options[:event]
reporter << TestProf::FactoryDoctorReporter.new(options[:io], options) if options[:fdoc]

::TestProf::MinitestSample.call if options[:sample]
end
end
16 changes: 6 additions & 10 deletions lib/test_prof/recipes/minitest/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@ def sample_examples(sample_size)
end
end
end
end

# Overrides Minitest.run
def run(*)
if ENV["SAMPLE"]
MinitestSample.sample_examples(ENV["SAMPLE"].to_i)
elsif ENV["SAMPLE_GROUPS"]
MinitestSample.sample_groups(ENV["SAMPLE_GROUPS"].to_i)
def call
if ENV["SAMPLE"]
::TestProf::MinitestSample.sample_examples(ENV["SAMPLE"].to_i)
elsif ENV["SAMPLE_GROUPS"]
::TestProf::MinitestSample.sample_groups(ENV["SAMPLE_GROUPS"].to_i)
end
end
super
end
end
end

Minitest.singleton_class.prepend(TestProf::MinitestSample)
16 changes: 16 additions & 0 deletions spec/integrations/sample_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
expect(output).to include("1 runs, 1 assertions, 0 failures, 0 errors, 0 skips")
end

specify "SAMPLE=2 with seed" do
outputs = Array
.new(10) { run_minitest("sample", env: {"SAMPLE" => "2", "TESTOPTS" => "-v --seed 42"}) }
.map { |output| output.gsub(/Finished in.*/, "") }

expect(outputs.uniq.size).to eq 1
end

specify "SAMPLE_GROUPS=1" do
output = run_minitest("sample", env: {"SAMPLE_GROUPS" => "1"})

Expand All @@ -81,5 +89,13 @@

expect(output).to include("4 runs, 4 assertions, 0 failures, 0 errors, 0 skips")
end

specify "SAMPLE_GROUPS=2 with seed" do
outputs = Array
.new(10) { run_minitest("sample", env: {"SAMPLE_GROUPS" => "2", "TESTOPTS" => "-v --seed 42"}) }
.map { |output| output.gsub(/Finished in.*/, "") }

expect(outputs.uniq.size).to eq 1
end
end
end

0 comments on commit 88ba58a

Please sign in to comment.