Module: Ace::TestSupport::Fixtures::GitMocks
- Defined in:
- lib/ace/test_support/fixtures/git_mocks.rb
Overview
Shared mock fixtures for Git command testing Extracted from ace-git-worktree/test/test_helper.rb to promote reusability
Defined Under Namespace
Classes: MockGitRepo
Constant Summary collapse
- MOCK_WORKTREE_LIST =
Common git worktree list output
<<~OUTPUT /Users/test/project abc123 [main] /Users/test/project-task-081 def456 [task-081] /Users/test/project-task-082 ghi789 [task-082] OUTPUT
- MOCK_BRANCH_LIST =
Common git branch list output
<<~OUTPUT * main task-081 task-082 feature/new-feature OUTPUT
- MOCK_STATUS_CLEAN =
Common git status output (clean)
<<~OUTPUT On branch main nothing to commit, working tree clean OUTPUT
- MOCK_STATUS_DIRTY =
Common git status output (dirty)
<<~OUTPUT On branch task-081 Changes not staged for commit: modified: lib/example.rb Untracked files: new_file.rb OUTPUT
Class Method Summary collapse
-
.mock_command_result(output: "", error: "", exit_status: 0) ⇒ Hash
Creates a mock git command result.
-
.mock_create_task_result(task_id:, task_title:, worktree_path:, branch:, dry_run: false) ⇒ Hash
Creates a mock WorktreeManager.create_task result.
-
.mock_error_result(error_message) ⇒ Hash
Creates a mock WorktreeManager error result.
-
.stub_ace_core_config(config_data = {}) { ... } ⇒ Object
Stub ace-core configuration.
-
.stub_ace_taskflow_output(task_id, output) { ... } ⇒ Object
Stub ace-task CLI output.
-
.stub_git_command(output: "", error: "", exit_status: 0) { ... } ⇒ Object
Stub git command execution via ace-git CommandExecutor.
Class Method Details
.mock_command_result(output: "", error: "", exit_status: 0) ⇒ Hash
Creates a mock git command result
101 102 103 104 105 106 107 108 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 101 def self.mock_command_result(output: "", error: "", exit_status: 0) { success: exit_status == 0, output: output, error: error, exit_code: exit_status } end |
.mock_create_task_result(task_id:, task_title:, worktree_path:, branch:, dry_run: false) ⇒ Hash
Creates a mock WorktreeManager.create_task result
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 189 def self.mock_create_task_result(task_id:, task_title:, worktree_path:, branch:, dry_run: false) if dry_run { success: true, task_id: task_id, task_title: task_title, would_create: { worktree_path: worktree_path, branch: branch }, steps_planned: [ "Would fetch task details for #{task_id}", "Would create worktree at #{worktree_path}", "Would create and checkout branch #{branch}", "Would copy untracked files", "Would stash and apply changes" ] } else { success: true, task_id: task_id, task_title: task_title, worktree_path: worktree_path, branch: branch, steps_completed: [ "Fetched task details for #{task_id}", "Created worktree at #{worktree_path}", "Created and checked out branch #{branch}", "Copied untracked files", "Stashed and applied changes" ] } end end |
.mock_error_result(error_message) ⇒ Hash
Creates a mock WorktreeManager error result
228 229 230 231 232 233 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 228 def self.mock_error_result() { success: false, error: } end |
.stub_ace_core_config(config_data = {}) { ... } ⇒ Object
Stub ace-core configuration
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 128 def self.stub_ace_core_config(config_data = {}) return yield unless defined?(Ace::Core) return yield unless Ace::Core.respond_to?(:get) original = Ace::Core.method(:get) Ace::Core.define_singleton_method(:get) { |*| config_data } yield ensure Ace::Core.define_singleton_method(:get, original) if original end |
.stub_ace_taskflow_output(task_id, output) { ... } ⇒ Object
Stub ace-task CLI output
143 144 145 146 147 148 149 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 143 def self.stub_ace_taskflow_output(task_id, output) require "open3" Open3.stub(:capture3, [output.to_s, "", 0]) do yield end end |
.stub_git_command(output: "", error: "", exit_status: 0) { ... } ⇒ Object
Stub git command execution via ace-git CommandExecutor
115 116 117 118 119 120 121 122 123 |
# File 'lib/ace/test_support/fixtures/git_mocks.rb', line 115 def self.stub_git_command(output: "", error: "", exit_status: 0) return unless defined?(Ace::Git::Atoms::CommandExecutor) mock_result = mock_command_result(output: output, error: error, exit_status: exit_status) Ace::Git::Atoms::CommandExecutor.stub(:execute, mock_result) do yield end end |