|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Mina::DSL, type: :rake do |
| 4 | + before do |
| 5 | + load_default_config |
| 6 | + load_config 'dsl' |
| 7 | + end |
| 8 | + |
| 9 | + describe '#reset!' do |
| 10 | + let(:task_name) { 'reset_task' } |
| 11 | + |
| 12 | + it "clears all commands before it" do |
| 13 | + expect do |
| 14 | + invoke_all |
| 15 | + end.to output(output_file('dsl_reset')).to_stdout |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + describe '#run' do |
| 20 | + context 'when one run block is inside another' do |
| 21 | + let(:task_name) { 'one_run_inside_another' } |
| 22 | + |
| 23 | + it 'exits with an error message' do |
| 24 | + expect do |
| 25 | + invoke_all |
| 26 | + end.to raise_error(SystemExit) |
| 27 | + .and output(/Can't use run block inside another run block./).to_stdout |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'when backend is :local' do |
| 32 | + let(:task_name) { 'local_run' } |
| 33 | + |
| 34 | + it 'executes commands locally' do |
| 35 | + expect do |
| 36 | + invoke_all |
| 37 | + end.to output(output_file('dsl_local_run')).to_stdout |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context 'when backend is :remote' do |
| 42 | + let(:task_name) { 'remote_run' } |
| 43 | + |
| 44 | + it 'executes commands on the server' do |
| 45 | + expect do |
| 46 | + invoke_all |
| 47 | + end.to output(output_file('dsl_remote_run')).to_stdout |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context "when backend doesn't exist" do |
| 52 | + let(:task_name) { 'nonexistent_run' } |
| 53 | + |
| 54 | + # TODO: refactor for more user-friendly error handling |
| 55 | + it 'raises a runtime error' do |
| 56 | + expect do |
| 57 | + invoke_all |
| 58 | + end.to raise_error(RuntimeError, /Don't know how to build task 'nonexistent_environment'/) |
| 59 | + end |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + describe '#on' do |
| 64 | + let(:task_name) { 'on_stage_task' } |
| 65 | + |
| 66 | + it 'executes the command in the given stage' do |
| 67 | + expect do |
| 68 | + invoke_all |
| 69 | + end.to output(output_file('dsl_on')).to_stdout |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + describe '#in_path' do |
| 74 | + let(:task_name) { 'in_path_task' } |
| 75 | + |
| 76 | + it 'executes the command in the given path' do |
| 77 | + expect do |
| 78 | + invoke_all |
| 79 | + end.to output(output_file('dsl_in_path')).to_stdout |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + describe '#deploy' do |
| 84 | + let(:task_name) { 'deploy_block_task' } |
| 85 | + |
| 86 | + it 'executes the deploy script and commands on remote' do |
| 87 | + expect do |
| 88 | + invoke_all |
| 89 | + end.to output(output_file('dsl_deploy')).to_stdout |
| 90 | + end |
| 91 | + end |
| 92 | +end |
0 commit comments