spec/integration/dsl_spec.rb in capistrano-3.2.1 vs spec/integration/dsl_spec.rb in capistrano-3.3.3

- old
+ new

@@ -34,14 +34,14 @@ it 'returns all release servers' do expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com} end end - context 'with filter options' do + context 'with property filter options' do subject { dsl.release_roles(:all, filter: :active) } - it 'returns all release servers that match the filter' do + it 'returns all release servers that match the property filter' do expect(subject.map(&:hostname)).to eq %w{example1.com example3.com} end end end @@ -90,18 +90,50 @@ it 'returns the servers' do expect(subject.hostname).to eq 'example1.com' end end - context 'when the attribute `primary` is explicity set' do + context 'when the attribute `primary` is explicitly set' do subject { dsl.primary(:app) } it 'returns the servers' do expect(subject.hostname).to eq 'example4.com' end end end + describe 'setting an internal host filter' do + subject { dsl.roles(:app) } + it 'is ignored' do + dsl.set :filter, { host: 'example3.com' } + expect(subject.map(&:hostname)).to eq(['example3.com', 'example4.com']) + end + end + + describe 'setting an internal role filter' do + subject { dsl.roles(:app) } + it 'ignores it' do + dsl.set :filter, { role: :web } + expect(subject.map(&:hostname)).to eq(['example3.com','example4.com']) + end + end + + describe 'setting an internal host and role filter' do + subject { dsl.roles(:app) } + it 'ignores it' do + dsl.set :filter, { role: :web, host: 'example1.com' } + expect(subject.map(&:hostname)).to eq(['example3.com','example4.com']) + end + end + + describe 'setting an internal regexp host filter' do + subject { dsl.roles(:all) } + it 'is ignored' do + dsl.set :filter, { host: /1/ } + expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com}) + end + end + end describe 'when defining role with reserved name' do it 'fails with ArgumentError' do expect { @@ -216,15 +248,15 @@ end end describe 'fetching servers for a role' do it 'roles defined using the `server` syntax are included' do - expect(dsl.roles(:web)).to have(2).items + expect(dsl.roles(:web).size).to eq(2) end it 'roles defined using the `role` syntax are included' do - expect(dsl.roles(:app)).to have(2).items + expect(dsl.roles(:app).size).to eq(2) end end end @@ -315,26 +347,26 @@ end context 'variable is an non-empty array' do let(:linked_files) { %w{1} } - it { should be_true } + it { expect(subject).to be_truthy } end context 'variable is an empty array' do let(:linked_files) { [] } - it { should be_false } + it { expect(subject).to be_falsey } end context 'variable exists, is not an array' do let(:linked_files) { stub } - it { should be_true } + it { expect(subject).to be_truthy } end context 'variable is nil' do let(:linked_files) { nil } - it { should be_false } + it { expect(subject).to be_falsey } end end describe 'configuration SSHKit' do let(:config) { SSHKit.config } @@ -366,11 +398,11 @@ it 'sets the default env' do expect(config.default_env).to eq default_env end it 'sets the backend pty' do - expect(backend.pty).to be_true + expect(backend.pty).to be_truthy end it 'sets the backend connection timeout' do expect(backend.connection_timeout).to eq 10 end @@ -486,6 +518,93 @@ expect(subject).to eq 'my/custom/path' end end end end + + describe 'local_user' do + before do + dsl.set :local_user, -> { Etc.getlogin } + end + + describe 'fetching local_user' do + subject { dsl.local_user } + + context 'where a local_user is not set' do + before do + Etc.expects(:getlogin).returns('login') + end + + it 'returns the login name' do + expect(subject.to_s).to eq 'login' + end + end + + context 'where a local_user is set' do + before do + dsl.set(:local_user, -> { 'custom login' }) + end + + it 'returns the custom name' do + expect(subject.to_s).to eq 'custom login' + end + end + end + end + + describe 'on()' do + + before do + dsl.server 'example1.com', roles: %w{web}, active: true + dsl.server 'example2.com', roles: %w{web} + dsl.server 'example3.com', roles: %w{app web}, active: true + dsl.server 'example4.com', roles: %w{app}, primary: true + dsl.server 'example5.com', roles: %w{db}, no_release: true + @coordinator = mock('coordinator') + @coordinator.expects(:each).returns(nil) + ENV.delete 'ROLES' + ENV.delete 'HOSTS' + + end + + it 'filters by role from the :filter variable' do + hosts = dsl.roles(:web) + all = dsl.roles(:all) + SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator) + dsl.set :filter, { role: 'web' } + dsl.on(all) + end + + it 'filters by host and role from the :filter variable' do + all = dsl.roles(:all) + SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator) + dsl.set :filter, { role: 'db', host: 'example3.com' } + dsl.on(all) + end + + it 'filters from ENV[ROLES]' do + hosts = dsl.roles(:db) + all = dsl.roles(:all) + SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator) + ENV['ROLES'] = 'db' + dsl.on(all) + end + + it 'filters from ENV[HOSTS]' do + hosts = dsl.roles(:db) + all = dsl.roles(:all) + SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator) + ENV['HOSTS'] = 'example5.com' + dsl.on(all) + end + + it 'filters by ENV[HOSTS] && ENV[ROLES]' do + all = dsl.roles(:all) + SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator) + ENV['HOSTS'] = 'example5.com' + ENV['ROLES'] = 'web' + dsl.on(all) + end + + end + end