diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-10-24 12:27:13 +1100 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-10-24 12:27:13 +1100 |
| commit | 08534a8164699017aa847fef62602abf6ec59e8f (patch) | |
| tree | a18b56a9ccb9bebc4e64814391935756e6a03b26 /spec/action_file_executor_spec.rb | |
| parent | 28722066aa4b03a1b981f14e375497940e9f40e4 (diff) | |
Add ActionFileExecutor and execute from CLI
- Updated tests to use tempfile
- Implemented initial ActionFileExecutor tests
Diffstat (limited to 'spec/action_file_executor_spec.rb')
| -rw-r--r-- | spec/action_file_executor_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/action_file_executor_spec.rb b/spec/action_file_executor_spec.rb new file mode 100644 index 0000000..c909bf5 --- /dev/null +++ b/spec/action_file_executor_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'tempfile' +require_relative '../lib/action_file_executor' + +RSpec.describe ActionFileExecutor do + let(:tempfile) { Tempfile.new('actions.txt') } + let(:invalid_file_path) { 'non_existent_file.txt' } + + before do + tempfile.write('ADD_CHILD Mother Child Male') + tempfile.rewind + end + + after do + tempfile.close + tempfile.unlink + end + + describe '#initialize' do + context 'when the file does not exist' do + it 'prints an error message and exits' do + expect do + ActionFileExecutor.new(invalid_file_path) + end.to output("Error: The file 'non_existent_file.txt' does not exist.\n").to_stdout.and raise_error(SystemExit) + end + end + + context 'when the file exists' do + it 'initializes successfully' do + action_file_executor = ActionFileExecutor.new(tempfile.path) + expect(action_file_executor).to be_an_instance_of(ActionFileExecutor) + end + end + end + + describe '#execute_actions' do + it 'prints message indicating action being executed and the parameters which were passed' do + action_file_executor = ActionFileExecutor.new(tempfile.path) + expect do + action_file_executor.execute_actions + end.to output("Executing action: ADD_CHILD with params: Mother, Child, Male\n").to_stdout + end + end +end |
