spec/knapsack/distributors/report_distributor_spec.rb in knapsack-0.5.0 vs spec/knapsack/distributors/report_distributor_spec.rb in knapsack-1.0.0

- old
+ new

@@ -1,16 +1,18 @@ describe Knapsack::Distributors::ReportDistributor do - let(:args) { {} } - let(:default_report) { { 'default_report_spec.rb' => 1.0 } } - - let(:distributor) { described_class.new(args) } - - before do - allow(Knapsack).to receive(:report) { - instance_double(Knapsack::Report, open: default_report) + let(:report) { { 'a_spec.rb' => 1.0 } } + let(:default_args) do + { + report: report, + test_file_pattern: 'spec/**/*_spec.rb', + ci_node_total: '1', + ci_node_index: '0' } end + let(:args) { default_args.merge(custom_args) } + let(:custom_args) { {} } + let(:distributor) { described_class.new(args) } describe '#sorted_report' do subject { distributor.sorted_report } let(:report) do @@ -21,11 +23,10 @@ 'd_spec.rb' => 2.5, 'a_spec.rb' => 1.0, 'b_spec.rb' => 1.5, } end - let(:args) { { report: report } } it do should eql([ ['f_spec.rb', 3.5], ['e_spec.rb', 3.0], @@ -35,33 +36,32 @@ ['a_spec.rb', 1.0], ]) end end - describe '#sorted_report_with_existing_specs' do - subject { distributor.sorted_report_with_existing_specs } + describe '#sorted_report_with_existing_tests' do + subject { distributor.sorted_report_with_existing_tests } - before do - expect(distributor).to receive(:all_specs).exactly(6).times.and_return([ - 'b_spec.rb', - 'd_spec.rb', - 'f_spec.rb', - ]) - end - let(:report) do { 'e_spec.rb' => 3.0, 'f_spec.rb' => 3.5, 'c_spec.rb' => 2.0, 'd_spec.rb' => 2.5, 'a_spec.rb' => 1.0, 'b_spec.rb' => 1.5, } end - let(:args) { { report: report } } + before do + expect(distributor).to receive(:all_tests).exactly(6).times.and_return([ + 'b_spec.rb', + 'd_spec.rb', + 'f_spec.rb', + ]) + end + it do should eql([ ['f_spec.rb', 3.5], ['d_spec.rb', 2.5], ['b_spec.rb', 1.5], @@ -75,14 +75,13 @@ 'a_spec.rb' => 3.0, 'b_spec.rb' => 1.0, 'c_spec.rb' => 1.5, } end - let(:args) { { report: report } } before do - allow(distributor).to receive(:all_specs).and_return(report.keys) + allow(distributor).to receive(:all_tests).and_return(report.keys) end describe '#total_time_execution' do subject { distributor.total_time_execution } @@ -102,11 +101,11 @@ end end describe '#node_time_execution' do subject { distributor.node_time_execution } - let(:args) { { report: report, ci_node_total: 4 } } + let(:custom_args) { { ci_node_total: 4 } } it { should eql 1.375 } end end context do @@ -120,73 +119,68 @@ 'd_spec.rb' => 2.5, 'a_spec.rb' => 1.0, 'b_spec.rb' => 1.5, } end - let(:args) do - { - report: report, - ci_node_total: 3, - } - end + let(:custom_args) { { ci_node_total: 3 } } before do - allow(distributor).to receive(:all_specs).and_return(report.keys) + allow(distributor).to receive(:all_tests).and_return(report.keys) end - describe '#assign_spec_files_to_node' do - before { distributor.assign_spec_files_to_node } + describe '#assign_test_files_to_node' do + before { distributor.assign_test_files_to_node } it do - expect(distributor.node_specs[0]).to eql({ + expect(distributor.node_tests[0]).to eql({ :node_index => 0, :time_left => -0.5, - :spec_files_with_time => [ + :test_files_with_time => [ ["g_spec.rb", 9.0] ] }) end it do - expect(distributor.node_specs[1]).to eql({ + expect(distributor.node_tests[1]).to eql({ :node_index => 1, :time_left => 0.0, - :spec_files_with_time => [ + :test_files_with_time => [ ["f_spec.rb", 3.5], ["d_spec.rb", 2.5], ["a_spec.rb", 1.0], ["b_spec.rb", 1.5] ] }) end it do - expect(distributor.node_specs[2]).to eql({ + expect(distributor.node_tests[2]).to eql({ :node_index => 2, :time_left => 0.5, - :spec_files_with_time => [ + :test_files_with_time => [ ["h_spec.rb", 3.0], ["c_spec.rb", 2.0], ["i_spec.rb", 3.0] ] }) end end - describe '#specs_for_node' do + describe '#tests_for_node' do context 'when node exists' do it do - expect(distributor.specs_for_node(1)).to eql([ + expect(distributor.tests_for_node(1)).to eql([ 'f_spec.rb', 'd_spec.rb', 'a_spec.rb', 'b_spec.rb' ]) end end context "when node doesn't exist" do - it { expect(distributor.specs_for_node(42)).to be_nil } + it { expect(distributor.tests_for_node(42)).to be_nil } end end end end