From 8a38f02b65045d72bf50be5fb5c6b179329db061 Mon Sep 17 00:00:00 2001 From: grosser Date: Fri, 4 May 2012 22:29:13 -0700 Subject: [PATCH] do not use --profile parallel when user gave a profile, fixes #120 --- lib/parallel_tests/cucumber/runner.rb | 13 +++++++--- spec/parallel_tests/cucumber/runner_spec.rb | 27 ++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/parallel_tests/cucumber/runner.rb b/lib/parallel_tests/cucumber/runner.rb index d43ba5f2..269d4e8b 100644 --- a/lib/parallel_tests/cucumber/runner.rb +++ b/lib/parallel_tests/cucumber/runner.rb @@ -10,8 +10,7 @@ def self.run_tests(test_files, process_number, options) color, executable, (runtime_logging if File.directory?(File.dirname(runtime_log))), - options[:test_options], - cucumber_opts, + cucumber_opts(options[:test_options]), *test_files ].compact.join(" ") execute_command(cmd, process_number, options) @@ -43,7 +42,15 @@ def self.line_is_result?(line) line =~ /^\d+ (steps|scenarios)/ end - def self.cucumber_opts + def self.cucumber_opts(given) + if given =~ /--profile/ or given =~ /(^|\s)-p / + given + else + [given, profile_from_config].compact.join(" ") + end + end + + def self.profile_from_config config = 'config/cucumber.yml' if File.exists?(config) && File.read(config) =~ /^parallel:/ "--profile parallel" diff --git a/spec/parallel_tests/cucumber/runner_spec.rb b/spec/parallel_tests/cucumber/runner_spec.rb index 8a4fbae0..ee9c1722 100644 --- a/spec/parallel_tests/cucumber/runner_spec.rb +++ b/spec/parallel_tests/cucumber/runner_spec.rb @@ -53,12 +53,27 @@ def call(*args) call(['xxx'],1,:test_options => '-p default') end - it "uses parallel profile if config/cucumber.yml contains it" do - file_contents = 'parallel: -f progress' - ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* foo bar --profile parallel}}.and_return mocked_process - File.should_receive(:exists?).with('config/cucumber.yml').and_return true - File.should_receive(:read).with('config/cucumber.yml').and_return file_contents - call(['xxx'],1, :test_options => 'foo bar') + context "with parallel profile in config/cucumber.yml" do + before do + file_contents = 'parallel: -f progress' + File.stub(:exists?).with('config/cucumber.yml').and_return true + File.stub(:read).with('config/cucumber.yml').and_return file_contents + end + + it "uses parallel profile" do + ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* foo bar --profile parallel xxx}}.and_return mocked_process + call(['xxx'],1, :test_options => 'foo bar') + end + + it "uses given profile via --profile" do + ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* --profile foo xxx$}}.and_return mocked_process + call(['xxx'],1, :test_options => '--profile foo') + end + + it "uses given profile via -p" do + ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* -p foo xxx$}}.and_return mocked_process + call(['xxx'],1, :test_options => '-p foo') + end end it "does not use parallel profile if config/cucumber.yml does not contain it" do