require 'spec_helper' describe ParallelTests do test_tests_in_groups(ParallelTests, 'test', '_test.rb') describe :parse_rake_args do it "should return the count" do args = {:count => 2} ParallelTests.parse_rake_args(args).should == [2, '', ""] end it "should default to the prefix" do args = {:count => "models"} ParallelTests.parse_rake_args(args).should == [Parallel.processor_count, "models", ""] end it "should return the count and pattern" do args = {:count => 2, :pattern => "models"} ParallelTests.parse_rake_args(args).should == [2, "models", ""] end it "should return the count, pattern, and options" do args = {:count => 2, :pattern => "plain", :options => "-p default" } ParallelTests.parse_rake_args(args).should == [2, "plain", "-p default"] end end describe :run_tests do it "uses TEST_ENV_NUMBER=blank when called for process 0" do ParallelTests.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process ParallelTests.run_tests(['xxx'],0,{}) end it "uses TEST_ENV_NUMBER=2 when called for process 1" do ParallelTests.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process ParallelTests.run_tests(['xxx'],1,{}) end it "uses options" do ParallelTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest -v}}.and_return mocked_process ParallelTests.run_tests(['xxx'],1,:test_options => '-v') end it "returns the output" do io = open('spec/spec_helper.rb') ParallelTests.stub!(:print) ParallelTests.should_receive(:open).and_return io ParallelTests.run_tests(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/ end end describe :test_in_groups do it "does not sort when passed false do_sort option" do ParallelTests.should_not_receive(:smallest_first) ParallelTests.tests_in_groups [], 1, :no_sort => true end it "does sort when not passed do_sort option" do ParallelTests.stub!(:tests_with_runtime).and_return([]) ParallelTests::Grouper.should_receive(:smallest_first).and_return([]) ParallelTests.tests_in_groups [], 1 end end describe :find_results do it "finds multiple results in test output" do output = < '^a/(y|z)_test').sort.should == [ "#{root}/a/y_test.rb", "#{root}/a/z_test.rb", ] ensure `rm -rf #{root}` end end end describe :summarize_results do it "adds results" do ParallelTests.summarize_results(['1 foo 3 bar','2 foo 5 bar']).should == '8 bars, 3 foos' end it "adds results with braces" do ParallelTests.summarize_results(['1 foo(s) 3 bar(s)','2 foo 5 bar']).should == '8 bars, 3 foos' end it "adds same results with plurals" do ParallelTests.summarize_results(['1 foo 3 bar','2 foos 5 bar']).should == '8 bars, 3 foos' end it "adds non-similar results" do ParallelTests.summarize_results(['1 xxx 2 yyy','1 xxx 2 zzz']).should == '2 xxxs, 2 yyys, 2 zzzs' end it "does not pluralize 1" do ParallelTests.summarize_results(['1 xxx 2 yyy']).should == '1 xxx, 2 yyys' end end it "has a version" do ParallelTests::VERSION.should =~ /^\d+\.\d+\.\d+$/ end end