blob: 9d448d08ab666e11bede231458d57070a0dc077b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# 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
describe '#run' do
it 'prints a message that it is running actions from the actions file' do
expect do
cli = CLI.new([valid_file_path])
cli.run
end.to output(/Running actions from file: test_actions.txt against the family tree./).to_stdout
end
end
describe '#validate_arguments' 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 'does not print any message' do
expect do
CLI.new([valid_file_path])
end.not_to output.to_stdout
end
it 'does not raise any errors' do
expect do
CLI.new([valid_file_path])
end.not_to raise_error
end
end
end
end
|