Skip to content

Commit

Permalink
Run default test folder if no arguments passed (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Mar 25, 2021
1 parent b83e903 commit 4c1fa26
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@

### Added

- None
- Run default test folder if no arguments are passed.

### Fixed

Expand Down
6 changes: 5 additions & 1 deletion lib/parallel_tests/cli.rb
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/parallel_tests/cucumber/runner.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/parallel_tests/gherkin/runner.rb
Expand Up @@ -34,6 +34,10 @@ def test_file_name
@test_file_name || 'feature'
end

def default_test_folder
'features'
end

def test_suffix
/\.feature$/
end
Expand Down
4 changes: 4 additions & 0 deletions lib/parallel_tests/rspec/runner.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/parallel_tests/spinach/runner.rb
Expand Up @@ -9,6 +9,10 @@ def name
'spinach'
end

def default_test_folder
'features'
end

def runtime_logging
# Not Yet Supported
""
Expand Down
4 changes: 4 additions & 0 deletions lib/parallel_tests/test/runner.rb
Expand Up @@ -15,6 +15,10 @@ def test_suffix
/_(test|spec).rb$/
end

def default_test_folder
"test"
end

def test_file_name
"test"
end
Expand Down
18 changes: 12 additions & 6 deletions spec/integration_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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"}}'
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/parallel_tests/cli_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4c1fa26

Please sign in to comment.