Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make --spec-path option available to skipped-tests-estimate cli command #250

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/datadog/ci/cli/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def options

opts.on("-f", "--file FILENAME", "Output result to file FILENAME")
opts.on("--verbose", "Verbose output to stdout")
opts.on("--spec-path=[SPEC_PATH]", "Relative path to the spec directory, example: spec")

command_options(opts)
end.parse!(into: ddcirb_options)
Expand Down
1 change: 0 additions & 1 deletion lib/datadog/ci/cli/command/skippable_tests_percentage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def build_action

def command_options(opts)
opts.on("--rspec-opts=[OPTIONS]", "Command line options to pass to RSpec")
opts.on("--spec-path=[SPEC_PATH]", "Relative path to the spec directory, example: spec")
end
end
end
Expand Down
43 changes: 43 additions & 0 deletions spec/datadog/ci/cli/cli_spec.rb
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
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 spec/datadog/ci/cli/command/skippable_tests_percentage_spec.rb
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
Loading