2024-01-02 13:35:22 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
require "../src/config"
|
|
|
|
|
|
|
|
CONFIG_FILE_SIMPLE = "spec/config_data/simple_config.yml"
|
|
|
|
CONFIG_FILE_COMPLEX = "spec/config_data/complex_config.yml"
|
|
|
|
|
2024-01-04 15:35:39 +00:00
|
|
|
alias Config = CodePreloader::Config
|
2024-01-02 13:35:22 +00:00
|
|
|
describe CodePreloader::Config do
|
|
|
|
|
|
|
|
context "Initialization" do
|
|
|
|
it "initializes with default values" do
|
2024-01-04 15:35:39 +00:00
|
|
|
config = Config.new
|
|
|
|
config.pack_options.should be_nil
|
|
|
|
config.init_options.should be_nil
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-04 15:35:39 +00:00
|
|
|
context "Handles global arguments" do
|
|
|
|
it "parses version option correctly" do
|
|
|
|
args = ["--version"]
|
|
|
|
config = Config.new
|
|
|
|
config.parse_arguments(args)
|
|
|
|
config.subcommand == Config::Subcommand::Version
|
|
|
|
config.pack_options.should be_nil
|
|
|
|
config.init_options.should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "parses help options correctly" do
|
|
|
|
args = ["-h"]
|
|
|
|
config = Config.new
|
|
|
|
config.parse_arguments(args)
|
|
|
|
config.subcommand.should eq(Config::Subcommand::Help)
|
|
|
|
config.pack_options.should be_nil
|
|
|
|
config.init_options.should be_nil
|
|
|
|
|
|
|
|
args = ["--help"]
|
|
|
|
config = Config.new
|
|
|
|
config.parse_arguments(args)
|
|
|
|
config.subcommand.should eq(Config::Subcommand::Help)
|
|
|
|
config.pack_options.should be_nil
|
|
|
|
config.init_options.should be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "Handles pack arguments" do
|
2024-01-02 13:35:22 +00:00
|
|
|
it "parses repository paths correctly" do
|
2024-01-04 15:35:39 +00:00
|
|
|
args = ["pack", "path/to/repo1", "path/to/repo2"]
|
|
|
|
config = Config.new
|
2024-01-02 13:35:22 +00:00
|
|
|
config.parse_arguments(args)
|
2024-01-04 15:35:39 +00:00
|
|
|
config.subcommand.should eq(Config::Subcommand::Pack)
|
|
|
|
config.pack_options.should be_truthy
|
|
|
|
config.pack_options.try do |opts|
|
|
|
|
opts.repository_path_list.should eq ["path/to/repo1", "path/to/repo2"]
|
|
|
|
end
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "parses ignore paths correctly" do
|
2024-01-04 15:35:39 +00:00
|
|
|
args = ["pack", "-i", "path/to/ignore", "path/to/repo"]
|
|
|
|
config = Config.new
|
2024-01-02 13:35:22 +00:00
|
|
|
config.parse_arguments(args)
|
2024-01-04 15:35:39 +00:00
|
|
|
config.subcommand.should eq(Config::Subcommand::Pack)
|
|
|
|
config.pack_options.should be_truthy
|
|
|
|
config.pack_options.try do |opts|
|
|
|
|
opts.ignore_list.should eq ["path/to/ignore"]
|
|
|
|
end
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "parses output file path correctly" do
|
2024-01-04 15:35:39 +00:00
|
|
|
args = ["pack", "-o", "output.txt", "path/to/repo"]
|
|
|
|
config = Config.new
|
2024-01-02 13:35:22 +00:00
|
|
|
config.parse_arguments(args)
|
2024-01-04 15:35:39 +00:00
|
|
|
config.subcommand.should eq(Config::Subcommand::Pack)
|
|
|
|
config.pack_options.should be_truthy
|
|
|
|
config.pack_options.try do |opts|
|
|
|
|
opts.output_file_path.should eq "output.txt"
|
|
|
|
end
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-01-04 15:35:39 +00:00
|
|
|
context "loads config file" do
|
2024-01-02 13:35:22 +00:00
|
|
|
it "loads settings from a simple config file" do
|
2024-01-04 15:35:39 +00:00
|
|
|
config = Config.new
|
|
|
|
args = ["pack", "-c", CONFIG_FILE_SIMPLE, "path/to/repo"]
|
2024-01-02 13:35:22 +00:00
|
|
|
config.parse_arguments(args)
|
|
|
|
|
|
|
|
# Assuming the simple_config.yml has specific settings
|
2024-01-04 15:35:39 +00:00
|
|
|
config.pack_options.should be_truthy
|
|
|
|
config.pack_options.try do |opts|
|
|
|
|
opts.repository_path_list.should eq ["path/to/repo"]
|
|
|
|
opts.ignore_list.should eq ["simple/ignore"]
|
|
|
|
opts.output_file_path.should eq "simple_output.txt"
|
|
|
|
end
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "loads settings from a complex config file" do
|
|
|
|
repo_path ="path/to/repo"
|
2024-01-04 15:35:39 +00:00
|
|
|
config = Config.new
|
|
|
|
args = ["pack", "-c", CONFIG_FILE_COMPLEX, repo_path]
|
2024-01-02 13:35:22 +00:00
|
|
|
config.parse_arguments(args)
|
|
|
|
|
|
|
|
# Assuming the complex_config.yml has specific settings
|
2024-01-04 15:35:39 +00:00
|
|
|
config.pack_options.should be_truthy
|
|
|
|
config.pack_options.try do |opts|
|
|
|
|
opts.repository_path_list.should eq [repo_path]
|
|
|
|
opts.ignore_list.should eq ["complex/ignore1", "complex/ignore2"]
|
|
|
|
opts.output_file_path.should eq "complex_output.txt"
|
|
|
|
end
|
2024-01-02 13:35:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|