From 4c1fa263069bb31ed177acec51925e1e6ac84f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 25 Mar 2021 20:01:54 +0100 Subject: [PATCH] Run default test folder if no arguments passed (#809) --- CHANGELOG.md | 2 +- lib/parallel_tests/cli.rb | 6 +++++- lib/parallel_tests/cucumber/runner.rb | 4 ++++ lib/parallel_tests/gherkin/runner.rb | 4 ++++ lib/parallel_tests/rspec/runner.rb | 4 ++++ lib/parallel_tests/spinach/runner.rb | 4 ++++ lib/parallel_tests/test/runner.rb | 4 ++++ spec/integration_spec.rb | 18 ++++++++++++------ spec/parallel_tests/cli_spec.rb | 6 +++--- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 968097a1..2448bb3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Added -- None +- Run default test folder if no arguments are passed. ### Fixed diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 25f912c9..33930bb8 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -274,7 +274,11 @@ def parse_options!(argv) files, remaining = extract_file_paths(argv) unless options[:execute] - abort "Pass files or folders to run" unless files.any? + if files.empty? + default_test_folder = @runner.default_test_folder + files = [default_test_folder] if File.directory?(default_test_folder) + abort "Pass files or folders to run" if files.empty? + end options[:files] = files.map { |file_path| Pathname.new(file_path).cleanpath.to_s } end diff --git a/lib/parallel_tests/cucumber/runner.rb b/lib/parallel_tests/cucumber/runner.rb index b47e548d..a352b43d 100644 --- a/lib/parallel_tests/cucumber/runner.rb +++ b/lib/parallel_tests/cucumber/runner.rb @@ -12,6 +12,10 @@ def name 'cucumber' end + def default_test_folder + 'features' + end + def line_is_result?(line) super || line =~ SCENARIO_REGEX || line =~ SCENARIOS_RESULTS_BOUNDARY_REGEX end diff --git a/lib/parallel_tests/gherkin/runner.rb b/lib/parallel_tests/gherkin/runner.rb index 408e04e6..0253fd9e 100644 --- a/lib/parallel_tests/gherkin/runner.rb +++ b/lib/parallel_tests/gherkin/runner.rb @@ -34,6 +34,10 @@ def test_file_name @test_file_name || 'feature' end + def default_test_folder + 'features' + end + def test_suffix /\.feature$/ end diff --git a/lib/parallel_tests/rspec/runner.rb b/lib/parallel_tests/rspec/runner.rb index 794cd063..7c8b494c 100644 --- a/lib/parallel_tests/rspec/runner.rb +++ b/lib/parallel_tests/rspec/runner.rb @@ -26,6 +26,10 @@ def runtime_log "tmp/parallel_runtime_rspec.log" end + def default_test_folder + "spec" + end + def test_file_name "spec" end diff --git a/lib/parallel_tests/spinach/runner.rb b/lib/parallel_tests/spinach/runner.rb index b57eeb4c..20971457 100644 --- a/lib/parallel_tests/spinach/runner.rb +++ b/lib/parallel_tests/spinach/runner.rb @@ -9,6 +9,10 @@ def name 'spinach' end + def default_test_folder + 'features' + end + def runtime_logging # Not Yet Supported "" diff --git a/lib/parallel_tests/test/runner.rb b/lib/parallel_tests/test/runner.rb index 92e1d762..5b34ae21 100644 --- a/lib/parallel_tests/test/runner.rb +++ b/lib/parallel_tests/test/runner.rb @@ -15,6 +15,10 @@ def test_suffix /_(test|spec).rb$/ end + def default_test_folder + "test" + end + def test_file_name "test" end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 3b2675af..1293e428 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -54,8 +54,14 @@ def run_tests(test_folder, options = {}) result end - def self.it_fails_without_any_files(type) - it "fails without any files" do + def self.it_runs_the_default_folder_if_it_exists(type, test_folder) + it "runs the default folder if it exists" do + full_path_to_test_folder = File.join(folder, test_folder) + ensure_folder full_path_to_test_folder + results = run_tests("", fail: false, type: type) + expect(results).to_not include("Pass files or folders to run") + + FileUtils.remove_dir(full_path_to_test_folder, true) results = run_tests("", fail: true, type: type) expect(results).to include("Pass files or folders to run") end @@ -402,7 +408,7 @@ def test_unicode end context "RSpec" do - it_fails_without_any_files "rspec" + it_runs_the_default_folder_if_it_exists "rspec", "spec" it "captures seed with random failures with --verbose" do write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}' @@ -426,7 +432,7 @@ def test_unicode expect(result).to include('test_xxx') # verbose output of every test end - it_fails_without_any_files "test" + it_runs_the_default_folder_if_it_exists "test", "test" end context "Cucumber" do @@ -480,7 +486,7 @@ def test_unicode expect(result.scan(/YOUR TEST ENV IS \d?!/).sort).to eq(["YOUR TEST ENV IS !", "YOUR TEST ENV IS 2!"]) end - it_fails_without_any_files "cucumber" + it_runs_the_default_folder_if_it_exists "cucumber", "features" it "collates failing scenarios" do write "features/pass.feature", "Feature: xxx\n Scenario: xxx\n Given I pass" @@ -596,7 +602,7 @@ class A < Spinach::FeatureSteps expect(result.scan(/YOUR TEST ENV IS \d?!/).sort).to eq(["YOUR TEST ENV IS !", "YOUR TEST ENV IS 2!"]) end - it_fails_without_any_files "spinach" + it_runs_the_default_folder_if_it_exists "spinach", "features" end describe "graceful shutdown" do diff --git a/spec/parallel_tests/cli_spec.rb b/spec/parallel_tests/cli_spec.rb index d01a33c8..0e821336 100644 --- a/spec/parallel_tests/cli_spec.rb +++ b/spec/parallel_tests/cli_spec.rb @@ -13,9 +13,9 @@ def call(*args) subject.send(:parse_options!, *args) end - it "fails without file" do - expect(subject).to receive(:abort).with("Pass files or folders to run") - call(["-n3"]) + it "does not fail without file" do + expect(subject).not_to receive(:abort) + call(["-n3", "-t", "rspec"]) end it "cleanups file paths" do