How to use call method of ParallelTests.MyTestRunner Package

Best Parallel_tests_ruby code snippet using


Source:cli_spec.rb Github


Full Screen

...4describe ParallelTests::CLI do5 subject { }6 describe "#parse_options" do7 let(:defaults){ {:files => ["test"]} }8 def call(*args)9 subject.send(:parse_options!, *args)10 end11 it "fails without file" do12 expect(subject).to receive(:abort).with("Pass files or folders to run")13 call(["-n3"])14 end15 it "cleanups file paths" do16 expect(call(["./test"])).to eq(defaults)17 end18 it "parses execute" do19 expect(call(["--exec", "echo"])).to eq(execute: "echo")20 end21 it "parses excludes pattern" do22 expect(call(["test", "--exclude-pattern", "spec/"])).to eq(defaults.merge(:exclude_pattern => /spec\//))23 end24 it "parses regular count" do25 expect(call(["test", "-n3"])).to eq(defaults.merge(:count => 3))26 end27 it "parses count 0 as non-parallel" do28 expect(call(["test", "-n0"])).to eq(defaults.merge(:non_parallel => true))29 end30 it "parses non-parallel as non-parallel" do31 expect(call(["test", "--non-parallel"])).to eq(defaults.merge(:non_parallel => true))32 end33 it "finds the correct type when multiple are given" do34 call(["test", "--type", "test", "-t", "rspec"])35 expect(subject.instance_variable_get(:@runner)).to eq(ParallelTests::RSpec::Runner)36 end37 it "parses nice as nice" do38 expect(call(["test", "--nice"])).to eq(defaults.merge(:nice => true))39 end40 it "parses --verbose" do41 expect(call(["test", "--verbose"])).to eq(defaults.merge(:verbose => true))42 end43 it "parses --verbose-process-command" do44 expect(call(['test', '--verbose-process-command'])).to eq(45 defaults.merge(verbose_process_command: true)46 )47 end48 it "parses --verbose-rerun-command" do49 expect(call(['test', '--verbose-rerun-command'])).to eq(50 defaults.merge(verbose_rerun_command: true)51 )52 end53 it "parses --quiet" do54 expect(call(["test", "--quiet"])).to eq(defaults.merge(:quiet => true))55 end56 it "fails if both --verbose and --quiet are present" do57 expect { call(["test", "--verbose", "--quiet"]) }.to raise_error(RuntimeError)58 end59 it "parses --suffix" do60 expect(call(["test", "--suffix", "_(test|spec).rb$"])).to eq(defaults.merge(:suffix => /_(test|spec).rb$/))61 end62 it "parses --first-is-1" do63 expect(call(["test", "--first-is-1"])).64 to eq(defaults.merge(:first_is_1 => true))65 end66 context "parse only-group" do67 it "group_by should be set to filesize" do68 expect(call(["test", "--only-group", '1'])).to eq(defaults.merge(only_group: [1], group_by: :filesize))69 end70 it "allows runtime" do71 expect(call(["test", "--only-group", '1', '--group-by', 'runtime'])).to eq(defaults.merge(only_group: [1], group_by: :runtime))72 end73 it "raise error when group_by isn't filesize" do74 expect{75 call(["test", "--only-group", '1', '--group-by', 'steps'])76 }.to raise_error(RuntimeError)77 end78 it "with multiple groups" do79 expect(call(["test", "--only-group", '4,5'])).to eq(defaults.merge(only_group: [4,5], group_by: :filesize))80 end81 it "with a single group" do82 expect(call(["test", "--only-group", '4'])).to eq(defaults.merge(:only_group => [4], group_by: :filesize))83 end84 end85 context "single and isolate" do86 it "single_process should be an array of patterns" do87 expect(call(["test", "--single", '1'])).to eq(defaults.merge(single_process: [/1/]))88 end89 it "single_process should be an array of patterns" do90 expect(call(["test", "--single", '1', "--single", '2'])).to eq(defaults.merge(single_process: [/1/, /2/]))91 end92 it "isolate should set isolate_count defaults" do93 expect(call(["test", "--single", '1', "--isolate"])).to eq(defaults.merge(single_process: [/1/], isolate: true))94 end95 it "isolate_n should set isolate_count and turn on isolate" do96 expect(call(["test", "-n", "3", "--single", '1', "--isolate-n", "2"])).to eq(97 defaults.merge(count: 3, single_process: [/1/], isolate_count: 2)98 )99 end100 end101 context "when the -- option separator is used" do102 it "interprets arguments as files/directories" do103 expect(call(%w(-- test))).to eq( files: %w(test))104 expect(call(%w(-- ./test))).to eq( files: %w(test))105 expect(call(%w(-- test test2))).to eq( files: %w(test test2))106 expect(call(%w(-- --foo test))).to eq( files: %w(--foo test))107 expect(call(%w(-- test --foo test2))).to eq( files: %w(test --foo test2))108 end109 it "corectly handles arguments with spaces" do110 expect(call(['--', 'file name with space'])).to eq( files: ['file name with space'])111 end112 context "when the -o options has also been given" do113 it "merges the options together" do114 expect(call(%w(-o '-f' -- test --foo test2))).to eq( files: %w(test --foo test2), test_options: "'-f'")115 end116 end117 context "when a second -- option separator is used" do118 it "interprets the first set as test_options" do119 expect(call(%w(-- -r foo -- test))).to eq( files: %w(test), test_options: '-r foo')120 expect(call(%w(-- -r foo -- test test2))).to eq( files: %w(test test2), test_options: '-r foo')121 expect(call(%w(-- -r foo -o out.log -- test test2))).to eq( files: %w(test test2), test_options: '-r foo -o out.log')122 end123 context "when existing test_options have previously been given" do124 it "appends the new options" do125 expect(call(%w(-o '-f' -- -r foo.rb -- test))).to eq( files: %w(test), test_options: "'-f' -r foo.rb")126 end127 it "corectly handles argument values with spaces" do128 argv = ["-o 'path with spaces1'", '--', '--out', 'path with spaces2', '--', 'foo']129 expected_test_options = "'path with spaces1' --out path\\ with\\ spaces2"130 expect(call(argv)).to eq( files: %w(foo), test_options: expected_test_options)131 end132 end133 end134 end135 end136 describe "#load_runner" do137 it "requires and loads default runner" do138 expect(subject).to receive(:require).with("parallel_tests/test/runner")139 expect(subject.send(:load_runner, "test")).to eq(ParallelTests::Test::Runner)140 end141 it "requires and loads rspec runner" do142 expect(subject).to receive(:require).with("parallel_tests/rspec/runner")143 expect(subject.send(:load_runner, "rspec")).to eq(ParallelTests::RSpec::Runner)144 end145 it "requires and loads runner with underscores" do146 expect(subject).to receive(:require).with("parallel_tests/my_test_runner/runner")147 expect(subject.send(:load_runner, "my_test_runner")).to eq(ParallelTests::MyTestRunner::Runner)148 end149 it "fails to load unfindable runner" do150 expect{151 expect(subject.send(:load_runner, "foo")).to eq(ParallelTests::RSpec::Runner)152 }.to raise_error(LoadError)153 end154 end155 describe ".report_failure_rerun_commmand" do156 let(:single_failed_command) { [{exit_status: 1, command: 'foo', seed: nil, output: 'blah'}] }157 it "prints nothing if there are no failures" do158 expect($stdout).not_to receive(:puts)159 subject.send(:report_failure_rerun_commmand,160 [161 {exit_status: 0, command: 'foo', seed: nil, output: 'blah'}162 ],163 {verbose: true}164 )165 end166 def self.it_prints_nothing_about_rerun_commands(options)167 it 'prints nothing about rerun commands' do168 expect {169 subject.send(:report_failure_rerun_commmand, single_failed_command, options)170 }.to_not output(/Use the following command to run the group again/).to_stdout171 end172 end173 describe "failure" do174 context 'without options' do175 it_prints_nothing_about_rerun_commands({})176 end177 context 'with verbose disabled' do178 it_prints_nothing_about_rerun_commands(verbose: false)179 end180 context "with verbose rerun" do181 it "prints command if there is a failure" do182 expect {183 subject.send(:report_failure_rerun_commmand, single_failed_command, verbose_rerun_command: true)184 }.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nfoo\n").to_stdout185 end186 end187 context 'with verbose' do188 it "prints a message and the command if there is a failure" do189 expect {190 subject.send(:report_failure_rerun_commmand, single_failed_command, verbose: true)191 }.to output("\n\nTests have failed for a parallel_test group. Use the following command to run the group again:\n\nfoo\n").to_stdout192 end193 it "prints multiple commands if there are multiple failures" do194 expect {195 subject.send(:report_failure_rerun_commmand,196 [197 {exit_status: 1, command: 'foo', seed: nil, output: 'blah'},198 {exit_status: 1, command: 'bar', seed: nil, output: 'blah'},199 {exit_status: 1, command: 'baz', seed: nil, output: 'blah'},200 ],201 {verbose: true}202 )203 }.to output(/foo\nbar\nbaz/).to_stdout204 end205 it "only includes failures" do206 expect {207 subject.send(:report_failure_rerun_commmand,208 [209 {exit_status: 1, command: 'foo --color', seed: nil, output: 'blah'},210 {exit_status: 0, command: 'bar', seed: nil, output: 'blah'},211 {exit_status: 1, command: 'baz', seed: nil, output: 'blah'},212 ],213 {verbose: true}214 )215 }.to output(/foo --color\nbaz/).to_stdout216 end217 it "prints the command with the seed added by the runner" do218 command = 'rspec --color spec/foo_spec.rb'219 seed = 555220 subject.instance_variable_set(:@runner, ParallelTests::Test::Runner)221 expect(ParallelTests::Test::Runner).to receive(:command_with_seed).with(command, seed).222 and_return("my seeded command result --seed #{seed}")223 single_failed_command[0].merge!(seed: seed, command: command)224 expect {225 subject.send(:report_failure_rerun_commmand, single_failed_command, verbose: true)226 }.to output(/my seeded command result --seed 555/).to_stdout227 end228 end229 end230 end231 describe "#final_fail_message" do232 before do233 subject.instance_variable_set(:@runner, ParallelTests::Test::Runner)234 end235 it 'returns a plain fail message if colors are nor supported' do236 expect(subject).to receive(:use_colors?).and_return(false)237 expect(subject.send(:final_fail_message)).to eq("Tests Failed")238 end239 it 'returns a colorized fail message if colors are supported' do240 expect(subject).to receive(:use_colors?).and_return(true)241 expect(subject.send(:final_fail_message)).to eq("\e[31mTests Failed\e[0m")242 end243 end244 describe "#run_tests_in_parallel" do245 context "specific groups to run" do246 let(:results){ {:stdout => "", :exit_status => 0} }247 let(:common_options) {248 { files: ["test"], group_by: :filesize, first_is_1: false }249 }250 before do251 allow(subject).to receive(:puts)252 expect(subject).to receive(:load_runner).with("my_test_runner").and_return(ParallelTests::MyTestRunner::Runner)253 allow(ParallelTests::MyTestRunner::Runner).to receive(:test_file_name).and_return("test")254 expect(ParallelTests::MyTestRunner::Runner).to receive(:tests_in_groups).and_return([255 ['aaa','bbb'],256 ['ccc', 'ddd'],257 ['eee', 'fff']258 ])259 expect(subject).to receive(:report_results).and_return(nil)260 end261 it "calls run_tests once when one group specified" do262 expect(subject).to receive(:run_tests).once.and_return(results)263['test', '-n', '3', '--only-group', '1', '-t', 'my_test_runner'])264 end265 it "calls run_tests twice when two groups are specified" do266 expect(subject).to receive(:run_tests).twice.and_return(results)267['test', '-n', '3', '--only-group', '1,2', '-t', 'my_test_runner'])268 end269 it "run only one group specified" do270 options = common_options.merge(count: 3, only_group: [2])271 expect(subject).to receive(:run_tests).once.with(['ccc', 'ddd'], 0, 1, options).and_return(results)272['test', '-n', '3', '--only-group', '2', '-t', 'my_test_runner'])273 end274 it "run last group when passing a group that is not filled" do275 count = 3276 options = common_options.merge(count: count, only_group: [count])277 expect(subject).to receive(:run_tests).once.with(['eee', 'fff'], 0, 1, options).and_return(results)278['test', '-n', count.to_s, '--only-group', count.to_s, '-t', 'my_test_runner'])279 end280 it "run twice with multiple groups" do281 skip "fails on jruby" if RUBY_PLATFORM == "java"282 options = common_options.merge(count: 3, only_group: [2,3])283 expect(subject).to receive(:run_tests).once.with(['ccc', 'ddd'], 0, 1, options).and_return(results)284 expect(subject).to receive(:run_tests).once.with(['eee', 'fff'], 1, 1, options).and_return(results)285['test', '-n', '3', '--only-group', '2,3', '-t', 'my_test_runner'])286 end287 end288 end289 describe "#display_duration" do290 def call(*args)291 subject.send(:detailed_duration, *args)292 end293 it "displays for durations near one minute" do294 expect(call(59)).to eq(nil)295 expect(call(60)).to eq(" (1:00)")296 expect(call(61)).to eq(" (1:01)")297 end298 it "displays for durations near one hour" do299 expect(call(3599)).to eq(" (59:59)")300 expect(call(3600)).to eq(" (1:00:00)")301 expect(call(3601)).to eq(" (1:00:01)")302 end303 it "displays the correct string for miscellaneous durations" do304 expect(call(9296)).to eq(" (2:34:56)")305 expect(call(45296)).to eq(" (12:34:56)")306 expect(call(2756601)).to eq(" (765:43:21)") # hours into three digits? Buy more CI hardware...307 expect(call(0)).to eq(nil)308 end309 end310end311module ParallelTests312 module MyTestRunner313 class Runner314 end315 end316end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Parallel_tests_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?