diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-10-24 11:37:38 +1100 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-10-24 11:37:38 +1100 |
| commit | 4b6c5ce0cd6b29e0b0842f38b7f9e0f3d5a9d60d (patch) | |
| tree | 14735d78eda0328d58553a509f63a981d54562cd | |
| parent | 1d1b3511e4c523458d78653cb8781a5328600387 (diff) | |
Add CLI::initize tests
| -rw-r--r-- | spec/cli_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb new file mode 100644 index 0000000..4799ff0 --- /dev/null +++ b/spec/cli_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require_relative '../lib/cli' + +RSpec.describe CLI do + let(:valid_file_path) { 'test_actions.txt' } + let(:invalid_file_path) { 'non_existent_file.txt' } + + before do + File.write(valid_file_path, 'some actions') + end + + after do + File.delete(valid_file_path) if File.exist?(valid_file_path) + end + + describe '#initialize' do + context 'when no arguments are provided' do + it 'prints usage message and exits' do + expect do + CLI.new([]) + end.to output(%r{Usage: family_tree <path/to/actions.txt>}).to_stdout.and raise_error(SystemExit) + end + end + + context 'when an invalid file path is provided' do + it 'prints error message and exits' do + expect do + CLI.new([invalid_file_path]) + end.to output(/Error: The file 'non_existent_file.txt' does not exist./).to_stdout.and raise_error(SystemExit) + end + end + + context 'when a valid file path is provided' do + it 'initializes successfully' do + cli = CLI.new([valid_file_path]) + expect(cli).to be_an_instance_of(CLI) + end + end + end +end |
