|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | +require "mocha/minitest" |
| 5 | +require "roast" |
| 6 | + |
| 7 | +class RoastCLITest < ActiveSupport::TestCase |
| 8 | + def test_execute_with_workflow_yml_path |
| 9 | + workflow_path = "path/to/workflow.yml" |
| 10 | + expanded_path = File.expand_path(workflow_path) |
| 11 | + |
| 12 | + # Mock the ConfigurationParser to prevent actual execution |
| 13 | + mock_parser = mock("ConfigurationParser") |
| 14 | + mock_parser.expects(:begin!).once |
| 15 | + Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], {}).returns(mock_parser) |
| 16 | + |
| 17 | + # Make sure File.directory? returns false to avoid the directory error |
| 18 | + File.expects(:directory?).with(expanded_path).returns(false) |
| 19 | + |
| 20 | + # Execute the CLI command |
| 21 | + cli = Roast::CLI.new |
| 22 | + cli.execute(workflow_path) |
| 23 | + end |
| 24 | + |
| 25 | + def test_execute_with_conventional_path |
| 26 | + workflow_name = "my_workflow" |
| 27 | + conventional_path = "roast/#{workflow_name}/workflow.yml" |
| 28 | + expanded_path = File.expand_path(conventional_path) |
| 29 | + |
| 30 | + # Mock the ConfigurationParser to prevent actual execution |
| 31 | + mock_parser = mock("ConfigurationParser") |
| 32 | + mock_parser.expects(:begin!).once |
| 33 | + Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], {}).returns(mock_parser) |
| 34 | + |
| 35 | + # Make sure File.directory? returns false to avoid the directory error |
| 36 | + File.expects(:directory?).with(expanded_path).returns(false) |
| 37 | + |
| 38 | + # Execute the CLI command |
| 39 | + cli = Roast::CLI.new |
| 40 | + cli.execute(workflow_name) |
| 41 | + end |
| 42 | + |
| 43 | + def test_execute_with_directory_path_raises_error |
| 44 | + workflow_path = "path/to/directory" |
| 45 | + expanded_path = File.expand_path("roast/#{workflow_path}/workflow.yml") |
| 46 | + |
| 47 | + # Make the directory check return true to trigger the error |
| 48 | + File.expects(:directory?).with(expanded_path).returns(true) |
| 49 | + |
| 50 | + # Execute the CLI command and expect an error |
| 51 | + cli = Roast::CLI.new |
| 52 | + assert_raises(Thor::Error) do |
| 53 | + cli.execute(workflow_path) |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + def test_execute_with_files_passes_files_to_parser |
| 58 | + workflow_path = "path/to/workflow.yml" |
| 59 | + expanded_path = File.expand_path(workflow_path) |
| 60 | + files = ["file1.rb", "file2.rb"] |
| 61 | + |
| 62 | + # Mock the ConfigurationParser to prevent actual execution |
| 63 | + mock_parser = mock("ConfigurationParser") |
| 64 | + mock_parser.expects(:begin!).once |
| 65 | + Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, files, {}).returns(mock_parser) |
| 66 | + |
| 67 | + # Make sure File.directory? returns false to avoid the directory error |
| 68 | + File.expects(:directory?).with(expanded_path).returns(false) |
| 69 | + |
| 70 | + # Execute the CLI command |
| 71 | + cli = Roast::CLI.new |
| 72 | + cli.execute(workflow_path, *files) |
| 73 | + end |
| 74 | + |
| 75 | + def test_execute_with_options_passes_options_to_parser |
| 76 | + workflow_path = "path/to/workflow.yml" |
| 77 | + expanded_path = File.expand_path(workflow_path) |
| 78 | + options = { "verbose" => true, "concise" => false } |
| 79 | + |
| 80 | + # Mock the ConfigurationParser to prevent actual execution |
| 81 | + mock_parser = mock("ConfigurationParser") |
| 82 | + mock_parser.expects(:begin!).once |
| 83 | + Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], options.transform_keys(&:to_sym)).returns(mock_parser) |
| 84 | + |
| 85 | + # Make sure File.directory? returns false to avoid the directory error |
| 86 | + File.expects(:directory?).with(expanded_path).returns(false) |
| 87 | + |
| 88 | + # Create CLI with options |
| 89 | + cli = Roast::CLI.new([], options) |
| 90 | + cli.execute(workflow_path) |
| 91 | + end |
| 92 | +end |
0 commit comments