Skip to content

Commit

Permalink
Test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydorsey committed Mar 30, 2024
1 parent 5293cff commit 470801e
Showing 1 changed file with 23 additions and 48 deletions.
71 changes: 23 additions & 48 deletions spec/parallel_tests/cli_spec.rb
Expand Up @@ -319,6 +319,7 @@ def self.it_prints_nothing_about_rerun_commands(options)
before do
allow(subject).to receive(:puts)
expect(subject).to receive(:load_runner).with("my_test_runner").and_return(ParallelTests::MyTestRunner::Runner)
allow(ParallelTests::MyTestRunner::Runner).to receive(:test_file_name).and_return("test")
expect(ParallelTests::MyTestRunner::Runner).to receive(:tests_in_groups).and_return(
[
['aaa', 'bbb'],
Expand Down Expand Up @@ -363,53 +364,41 @@ def self.it_prints_nothing_about_rerun_commands(options)

context 'when --allow-duplicates' do
let(:results) { { stdout: "", exit_status: 0 } }
let(:processes) { 2 }
let(:common_options) do
{ files: ['test'], allow_duplicates: true, first_is_1: false }
end
before do
allow(subject).to receive(:puts)
expect(subject).to receive(:load_runner).with('my_test_runner').and_return(ParallelTests::MyTestRunner::Runner)
expect(subject).to receive(:load_runner).with("my_test_runner").and_return(ParallelTests::MyTestRunner::Runner)
allow(ParallelTests::MyTestRunner::Runner).to receive(:test_file_name).and_return("test")
expect(subject).to receive(:report_results).and_return(nil)
end

it "calls run_tests multiples times when same file is passed" do
options = common_options.merge(count: 4, only_group: [3, 4], group_by: :filesize)
expect(subject).to receive(:run_tests).once.with(['test'], 0, 1, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['foo'], 1, 1, options).and_return(results)
subject.run(['test', '-n', '4', '--allow-duplicates', '--only-group', '3,4', '-t', 'my_test_runner'])
end

it "calls run_tests multiples times when same file is passed" do
options = common_options.merge(count: 2)
expect(subject).to receive(:run_tests).once.with(['foo'], 3, 2, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 2, 2, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 1, 2, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 0, 2, options).and_return(results)
subject.run(['test', '-n', '2', '--allow-duplicates', '-t', 'my_test_runner'])
before do
expect(ParallelTests::MyTestRunner::Runner).to receive(:tests_in_groups).and_return(
[
['foo'],
['foo'],
['bar']
]
)
end

it "also calls run_tests multiples times when same file is passed" do
options = common_options.merge(count: 4)
expect(subject).to receive(:run_tests).once.with(['foo'], 3, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 2, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 1, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 0, 4, options).and_return(results)
subject.run(['test', '-n', '4', '--allow-duplicates', '-t', 'my_test_runner'])
it "calls run_tests with --only-group" do
options = common_options.merge(count: processes, only_group: [2, 3], group_by: :filesize)
expect(subject).to receive(:run_tests).once.with(['foo'], 0, 1, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['bar'], 1, 1, options).and_return(results)
subject.run(['test', '-n', processes.to_s, '--allow-duplicates', '--only-group', '2,3', '-t', 'my_test_runner'])
end

it "also calls run_tests multiples times when same file is passed" do
options = common_options.merge(count: 4, first_is_1: true)
expect(subject).to receive(:run_tests).once.with(['foo'], 4, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 3, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 2, 4, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['test'], 1, 4, options).and_return(results)
subject.run(['test', '-n', '4', '--first-is-1', '--allow-duplicates', '-t', 'my_test_runner'])
it "calls run_tests with --first-is-1" do
options = common_options.merge(count: processes, first_is_1: true)
expect(subject).to receive(:run_tests).once.with(['foo'], 1, processes, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['foo'], 2, processes, options).and_return(results)
expect(subject).to receive(:run_tests).once.with(['bar'], 3, processes, options).and_return(results)
subject.run(['test', '-n', processes.to_s, '--first-is-1', '--allow-duplicates', '-t', 'my_test_runner'])
end

# # expect(subject).to receive(:run_tests).twice.and_return(results)
# # expect(subject).to receive(:run_tests).twice.and_return(results)
# subject.run(['test', '-n', '3', '--allow-duplicates', '--only-group', '1,2,3', '-t', 'my_test_runner'])
# end
end
end

Expand Down Expand Up @@ -442,20 +431,6 @@ def call(*args)
module ParallelTests
module MyTestRunner
class Runner
class << self
def test_file_name
"test"
end

def tests_in_groups(_tests, _num_groups, _options = {})
[
['test'],
['test'],
['test'],
['foo']
]
end
end
end
end
end

0 comments on commit 470801e

Please sign in to comment.