-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: make --spec-path option available to skipped-tests-estimate cli …
…command
- Loading branch information
1 parent
2d4ca81
commit 60ef421
Showing
5 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../../../lib/datadog/ci/cli/cli" | ||
|
||
RSpec.describe Datadog::CI::CLI do | ||
describe ".exec" do | ||
subject(:exec) { described_class.exec(action) } | ||
|
||
context "when action is 'skippable-tests'" do | ||
let(:action) { "skippable-tests" } | ||
|
||
it "executes the skippable tests percentage command" do | ||
expect(Datadog::CI::CLI::Command::SkippableTestsPercentage).to receive(:new).and_call_original | ||
expect_any_instance_of(Datadog::CI::CLI::Command::SkippableTestsPercentage).to receive(:exec) | ||
|
||
exec | ||
end | ||
end | ||
|
||
context "when action is 'skippable-tests-estimate'" do | ||
let(:action) { "skippable-tests-estimate" } | ||
|
||
it "executes the skippable tests percentage estimate command" do | ||
expect(Datadog::CI::CLI::Command::SkippableTestsPercentageEstimate).to receive(:new).and_call_original | ||
expect_any_instance_of(Datadog::CI::CLI::Command::SkippableTestsPercentageEstimate).to receive(:exec) | ||
|
||
exec | ||
end | ||
end | ||
|
||
context "when action is not recognised" do | ||
let(:action) { "not-recognised" } | ||
|
||
it "prints the usage information" do | ||
expect { exec }.to output(<<~USAGE).to_stdout | ||
Usage: bundle exec ddcirb [command] [options]. Available commands: | ||
skippable-tests - calculates the exact percentage of skipped tests and prints it to stdout or file | ||
skippable-tests-estimate - estimates the percentage of skipped tests and prints it to stdout or file | ||
USAGE | ||
end | ||
end | ||
end | ||
end |
74 changes: 74 additions & 0 deletions
74
spec/datadog/ci/cli/command/skippable_tests_percentage_estimate_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../../../../lib/datadog/ci/cli/command/skippable_tests_percentage_estimate" | ||
|
||
RSpec.describe Datadog::CI::CLI::Command::SkippableTestsPercentageEstimate do | ||
subject(:command) { described_class.new } | ||
|
||
describe "#exec" do | ||
subject(:exec) { command.exec } | ||
|
||
# inputs | ||
let(:verbose) { false } | ||
let(:spec_path) { "spec" } | ||
let(:argv) { [] } | ||
|
||
# outputs | ||
let(:failed) { false } | ||
let(:result) { "result" } | ||
let(:action) { double("action", call: result, failed: failed) } | ||
|
||
before do | ||
allow(::Datadog::CI::TestOptimisation::SkippablePercentage::Estimator).to receive(:new).with( | ||
verbose: verbose, | ||
spec_path: spec_path | ||
).and_return(action) | ||
|
||
stub_const("ARGV", argv) | ||
end | ||
|
||
context "when no CLI options are given" do | ||
let(:argv) { [] } | ||
|
||
it "executes the action, validates it, and outputs the result" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when file option is given" do | ||
let(:argv) { ["-f", "output.txt"] } | ||
|
||
it "writes the result to the file" do | ||
expect(File).to receive(:write).with("output.txt", "result") | ||
|
||
exec | ||
end | ||
end | ||
|
||
context "when verbose option is given" do | ||
let(:argv) { ["--verbose"] } | ||
let(:verbose) { true } | ||
|
||
it "passes the verbose option to the action" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when spec-path option is given" do | ||
let(:argv) { ["--spec-path=spec/models"] } | ||
let(:spec_path) { "spec/models" } | ||
|
||
it "passes the spec-path option to the action" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when the action fails" do | ||
let(:failed) { true } | ||
|
||
it "exits with status 1" do | ||
expect { exec }.to raise_error(SystemExit) | ||
end | ||
end | ||
end | ||
end |
85 changes: 85 additions & 0 deletions
85
spec/datadog/ci/cli/command/skippable_tests_percentage_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../../../../lib/datadog/ci/cli/command/skippable_tests_percentage" | ||
|
||
RSpec.describe Datadog::CI::CLI::Command::SkippableTestsPercentage do | ||
subject(:command) { described_class.new } | ||
|
||
describe "#exec" do | ||
subject(:exec) { command.exec } | ||
|
||
# inputs | ||
let(:rspec_options) { [] } | ||
let(:verbose) { false } | ||
let(:spec_path) { "spec" } | ||
let(:argv) { [] } | ||
|
||
# outputs | ||
let(:failed) { false } | ||
let(:result) { "result" } | ||
let(:action) { double("action", call: result, failed: failed) } | ||
|
||
before do | ||
allow(::Datadog::CI::TestOptimisation::SkippablePercentage::Calculator).to receive(:new).with( | ||
rspec_cli_options: rspec_options, | ||
verbose: verbose, | ||
spec_path: spec_path | ||
).and_return(action) | ||
|
||
stub_const("ARGV", argv) | ||
end | ||
|
||
context "when no CLI options are given" do | ||
let(:argv) { [] } | ||
|
||
it "executes the action, validates it, and outputs the result" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when file option is given" do | ||
let(:argv) { ["-f", "output.txt"] } | ||
|
||
it "writes the result to the file" do | ||
expect(File).to receive(:write).with("output.txt", "result") | ||
|
||
exec | ||
end | ||
end | ||
|
||
context "when verbose option is given" do | ||
let(:argv) { ["--verbose"] } | ||
let(:verbose) { true } | ||
|
||
it "passes the verbose option to the action" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when rspec-opts option is given" do | ||
let(:argv) { ["--rspec-opts=--color --format progress"] } | ||
let(:rspec_options) { ["--color", "--format", "progress"] } | ||
|
||
it "passes the rspec-opts option to the action" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when spec-path option is given" do | ||
let(:argv) { ["--spec-path=spec/models"] } | ||
let(:spec_path) { "spec/models" } | ||
|
||
it "passes the spec-path option to the action" do | ||
expect { exec }.to output("result").to_stdout | ||
end | ||
end | ||
|
||
context "when the action fails" do | ||
let(:failed) { true } | ||
|
||
it "exits with status 1" do | ||
expect { exec }.to raise_error(SystemExit) | ||
end | ||
end | ||
end | ||
end |