|
34 | 34 | end |
35 | 35 | end |
36 | 36 |
|
| 37 | + context 'with PROGRAM - (stdin)' do |
| 38 | + it 'invokes the Installer using a temp file' do |
| 39 | + allow(subject).to receive(:installer).and_return(mock_installer) |
| 40 | + allow($stdin).to receive_messages(tty?: false, read: 'dummy data') |
| 41 | + |
| 42 | + expect(mock_installer).to receive(:install) |
| 43 | + |
| 44 | + expect { subject.execute %w[install completely-test -] } |
| 45 | + .to output_approval('cli/install/stdin-install') |
| 46 | + |
| 47 | + expect(File.read subject.tempfile.path).to eq 'dummy data' |
| 48 | + end |
| 49 | + end |
| 50 | + |
37 | 51 | context 'with PROGRAM --dry' do |
38 | 52 | it 'shows the command and does not install anything' do |
39 | 53 | expect(mock_installer).not_to receive(:install) |
|
43 | 57 | end |
44 | 58 | end |
45 | 59 |
|
| 60 | + context 'with PROGRAM - --dry (stdin)' do |
| 61 | + it 'shows the command and does not install anything' do |
| 62 | + allow($stdin).to receive_messages(tty?: false, read: 'dummy data') |
| 63 | + |
| 64 | + expect(mock_installer).not_to receive(:install) |
| 65 | + |
| 66 | + expect { subject.execute %w[install completely-test - --dry] } |
| 67 | + .to output_approval('cli/install/stdin-dry') |
| 68 | + .except(/[^\s]*stdin-completely-[^\s]*/, '<tmpfile-path>') |
| 69 | + end |
| 70 | + |
| 71 | + context 'when stdin is empty' do |
| 72 | + it 'raises InstallError' do |
| 73 | + allow($stdin).to receive_messages(tty?: true, read: nil) |
| 74 | + expect(mock_installer).not_to receive(:install) |
| 75 | + |
| 76 | + expect { subject.execute %w[install completely-test - --dry] } |
| 77 | + .to raise_error(InstallError, 'Nothing is piped on stdin') |
| 78 | + end |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + |
46 | 83 | context 'when the installer fails' do |
47 | 84 | it 'raises an error' do |
48 | 85 | allow(subject).to receive(:installer).and_return(mock_installer) |
|
0 commit comments