|
4 | 4 |
|
5 | 5 | describe 'init', type: 'aruba' do
|
6 | 6 | let(:revealing_init) { "#{aruba.root_directory}/exe/revealing init" }
|
| 7 | + let(:cwd) { Pathname(aruba.config.working_directory) } |
| 8 | + let(:project_directory) { cwd / 'shiny-new-presentation' } |
| 9 | + let(:project_files) { %w[src/index.markdown Rakefile Gemfile README.markdown].map { |e| project_directory / e } } |
7 | 10 |
|
8 |
| - context 'with a new project directory' do |
9 |
| - let(:project_directory) { 'shiny-new-presentation' } |
10 |
| - let(:cwd) { Pathname(aruba.config.working_directory) } |
11 |
| - |
12 |
| - before do |
13 |
| - run_command "#{revealing_init} #{project_directory}" |
| 11 | + shared_examples 'a new project directory' do |
| 12 | + it 'creates the required files in the new project directory' do |
| 13 | + run_command "#{revealing_init} #{project_directory.basename}" |
14 | 14 | expect(last_command_started).to be_successfully_executed
|
| 15 | + expect(project_files).to all(exist) |
15 | 16 | end
|
| 17 | + end |
16 | 18 |
|
| 19 | + context 'with a new project directory' do |
17 | 20 | it 'creates the new project directory' do
|
18 |
| - expect(cwd / project_directory).to be_directory |
| 21 | + run_command "#{revealing_init} #{project_directory.basename}" |
| 22 | + expect(last_command_started).to be_successfully_executed |
| 23 | + expect(project_directory).to be_directory |
19 | 24 | end
|
20 | 25 |
|
21 |
| - it 'creates the required files in the new project directory' do |
22 |
| - expect(cwd / project_directory / 'src/index.markdown').to exist |
23 |
| - expect(cwd / project_directory / 'Rakefile').to exist |
24 |
| - expect(cwd / project_directory / 'Gemfile').to exist |
25 |
| - expect(cwd / project_directory / 'README.markdown').to exist |
| 26 | + it_behaves_like('a new project directory') |
| 27 | + end |
| 28 | + |
| 29 | + context 'with an existing (empty) project directory' do |
| 30 | + before do |
| 31 | + project_directory.mkdir |
| 32 | + expect(project_directory).to be_directory |
| 33 | + end |
| 34 | + |
| 35 | + it_behaves_like('a new project directory') |
| 36 | + |
| 37 | + context 'the README already exists' do |
| 38 | + let(:readme) { (project_directory / 'README.markdown') } |
| 39 | + |
| 40 | + before do |
| 41 | + readme.write('fooo') |
| 42 | + end |
| 43 | + |
| 44 | + it 'does not override an existing file' do |
| 45 | + run_command "#{revealing_init} #{project_directory.basename}" |
| 46 | + expect(last_command_started).to be_successfully_executed |
| 47 | + expect(readme.read).to eq('fooo') |
| 48 | + end |
26 | 49 | end
|
27 | 50 | end
|
28 | 51 | end
|
0 commit comments