automan 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,15 @@
1
1
  require 'automan'
2
2
 
3
3
  describe Automan::Cloudformation::Terminator do
4
- it { should respond_to :name }
5
- it { should respond_to :terminate }
6
- it { should respond_to :stack_exists? }
7
- it { should respond_to :stack_deleted? }
8
- it { should respond_to :delete_stack }
9
- it { should respond_to :wait_for_completion }
4
+ it { is_expected.to respond_to :name }
5
+ it { is_expected.to respond_to :terminate }
6
+ it { is_expected.to respond_to :stack_exists? }
7
+ it { is_expected.to respond_to :stack_deleted? }
8
+ it { is_expected.to respond_to :delete_stack }
9
+ it { is_expected.to respond_to :wait_for_completion }
10
10
 
11
11
  describe '#terminate' do
12
- subject(:t) do
12
+ subject() do
13
13
  AWS.stub!
14
14
  t = Automan::Cloudformation::Terminator.new
15
15
  t.logger = Logger.new('/dev/null')
@@ -17,20 +17,20 @@ describe Automan::Cloudformation::Terminator do
17
17
  end
18
18
 
19
19
  it 'should call #delete_stack if the stack exists' do
20
- t.stub(:stack_exists?).and_return(true)
21
- t.should_receive :delete_stack
22
- t.terminate
20
+ allow(subject).to receive(:stack_exists?).and_return(true)
21
+ expect(subject).to receive :delete_stack
22
+ subject.terminate
23
23
  end
24
24
 
25
25
  it 'should not call #delete_stack if the stack does not exist' do
26
- t.stub(:stack_exists?).and_return(false)
27
- t.should_not_receive :delete_stack
28
- t.terminate
26
+ allow(subject).to receive(:stack_exists?).and_return(false)
27
+ expect(subject).to_not receive :delete_stack
28
+ subject.terminate
29
29
  end
30
30
  end
31
31
 
32
32
  describe '#stack_deleted?' do
33
- subject(:t) do
33
+ subject() do
34
34
  AWS.stub!
35
35
  t = Automan::Cloudformation::Terminator.new
36
36
  t.logger = Logger.new('/dev/null')
@@ -38,26 +38,26 @@ describe Automan::Cloudformation::Terminator do
38
38
  end
39
39
 
40
40
  it 'returns true if the stack does not exist' do
41
- t.stub(:stack_exists?).and_return(false)
42
- t.stub(:stack_status).and_raise StandardError
43
- t.stack_deleted?('foo').should be_true
41
+ allow(subject).to receive(:stack_exists?).and_return(false)
42
+ allow(subject).to receive(:stack_status).and_raise StandardError
43
+ expect(subject.stack_deleted?('foo')).to be_truthy
44
44
  end
45
45
 
46
46
  it 'returns true when status is DELETE_COMPLETE' do
47
- t.stub(:stack_status).and_return('DELETE_COMPLETE')
48
- t.stack_deleted?('foo').should be_true
47
+ allow(subject).to receive(:stack_status).and_return('DELETE_COMPLETE')
48
+ expect(subject.stack_deleted?('foo')).to be_truthy
49
49
  end
50
50
 
51
51
  it 'raises an error when the delete fails' do
52
- t.stub(:stack_status).and_return('DELETE_FAILED')
52
+ allow(subject).to receive(:stack_status).and_return('DELETE_FAILED')
53
53
  expect {
54
- t.stack_deleted?('foo')
54
+ subject.stack_deleted?('foo')
55
55
  }.to raise_error Automan::Cloudformation::StackDeletionError
56
56
  end
57
57
 
58
58
  it 'returns false for any other status' do
59
- t.stub(:stack_status).and_return('foo')
60
- t.stack_deleted?('foo').should be_false
59
+ allow(subject).to receive(:stack_status).and_return('foo')
60
+ expect(subject.stack_deleted?('foo')).to be_falsey
61
61
  end
62
62
  end
63
63
  end
@@ -1,11 +1,11 @@
1
1
  require 'automan'
2
2
 
3
3
  describe Automan::Cloudformation::Uploader do
4
- subject(:u) do
4
+ subject() do
5
5
  AWS.stub!
6
6
  u = Automan::Cloudformation::Uploader.new
7
7
  u.logger = Logger.new('/dev/null')
8
- u.stub(:templates).and_return(%w[a b c])
8
+ allow(u).to receive(:templates).and_return(%w[a b c])
9
9
  u
10
10
  end
11
11
 
@@ -16,35 +16,35 @@ describe Automan::Cloudformation::Uploader do
16
16
 
17
17
  describe '#all_templates_valid?' do
18
18
  it "raises error if there are no templates" do
19
- u.stub(:templates).and_return([])
19
+ allow(subject).to receive(:templates).and_return([])
20
20
  expect {
21
- u.all_templates_valid?
21
+ subject.all_templates_valid?
22
22
  }.to raise_error Automan::Cloudformation::NoTemplatesError
23
23
  end
24
24
 
25
25
  it 'returns true if templates are valid' do
26
- u.should_receive(:template_valid?).exactly(3).times.and_return(true)
27
- u.all_templates_valid?.should be_true
26
+ expect(subject).to receive(:template_valid?).exactly(3).times.and_return(true)
27
+ expect(subject.all_templates_valid?).to be_truthy
28
28
  end
29
29
 
30
30
  it 'returns false if any templates are invalid' do
31
- u.stub(:template_valid?).and_return(false)
32
- u.all_templates_valid?.should be_false
31
+ allow(subject).to receive(:template_valid?).and_return(false)
32
+ expect(subject.all_templates_valid?).to be_falsey
33
33
  end
34
34
  end
35
35
 
36
36
  describe '#upload_templates' do
37
37
  it 'raises error if any template fails validation' do
38
- u.stub(:all_templates_valid?).and_return(false)
38
+ allow(subject).to receive(:all_templates_valid?).and_return(false)
39
39
  expect {
40
- u.upload_templates
40
+ subject.upload_templates
41
41
  }.to raise_error(Automan::Cloudformation::InvalidTemplateError)
42
42
  end
43
43
 
44
44
  it 'uploads files if all are valid' do
45
- u.stub(:all_templates_valid?).and_return(true)
46
- u.should_receive(:upload_file).exactly(3).times
47
- u.upload_templates
45
+ allow(subject).to receive(:all_templates_valid?).and_return(true)
46
+ expect(subject).to receive(:upload_file).exactly(3).times
47
+ subject.upload_templates
48
48
  end
49
49
  end
50
50
  end
@@ -2,37 +2,37 @@ require 'automan'
2
2
  require 'logger'
3
3
 
4
4
  describe Automan::Ec2::Image do
5
- it { should respond_to :ec2 }
6
- it { should respond_to :create }
7
- it { should respond_to :prune }
8
- it { should respond_to :default_image_name }
9
- it { should respond_to :image_snapshot_exists? }
10
- it { should respond_to :image_snapshot }
11
- it { should respond_to :delete_snapshots }
12
- it { should respond_to :is_more_than_month_old? }
5
+ it { is_expected.to respond_to :ec2 }
6
+ it { is_expected.to respond_to :create }
7
+ it { is_expected.to respond_to :prune }
8
+ it { is_expected.to respond_to :default_image_name }
9
+ it { is_expected.to respond_to :image_snapshot_exists? }
10
+ it { is_expected.to respond_to :image_snapshot }
11
+ it { is_expected.to respond_to :delete_snapshots }
12
+ it { is_expected.to respond_to :is_more_than_month_old? }
13
13
 
14
14
  describe '#default_image_name' do
15
- subject(:s) do
15
+ subject() do
16
16
  AWS.stub!
17
17
  s = Automan::Ec2::Image.new
18
18
  s.logger = Logger.new('/dev/null')
19
- s.stub(:name).and_return('skee-lo')
19
+ allow(s).to receive(:name).and_return('skee-lo')
20
20
  s
21
21
  end
22
22
 
23
23
  it "never returns nil" do
24
- s.default_image_name().should_not be_nil
24
+ expect(subject.default_image_name()).to_not be_nil
25
25
  end
26
26
 
27
27
  it "returns name dash iso8601 string" do
28
- name = s.default_image_name()
29
- name.should match /^skee-lo-(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2})[+-](\d{2})-(\d{2})/
28
+ name = subject.default_image_name()
29
+ expect(name).to match /^skee-lo-(\d{4})-(\d{2})-(\d{2})T(\d{2})(\d{2})(\d{2})Z/
30
30
  end
31
31
 
32
32
  end
33
33
 
34
34
  describe '#image_snapshot' do
35
- subject(:s) do
35
+ subject() do
36
36
  AWS.stub!
37
37
  s = Automan::Ec2::Image.new
38
38
  s.logger = Logger.new('/dev/null')
@@ -41,31 +41,31 @@ describe Automan::Ec2::Image do
41
41
 
42
42
  it "returns id if the snapshot exists" do
43
43
  fake_ami = double("ami")
44
- fake_ami.stub(:block_devices) { [ { ebs: {snapshot_id: 'foo' } } ] }
45
- s.image_snapshot(fake_ami).should eq('foo')
44
+ allow(fake_ami).to receive(:block_devices) { [ { ebs: {snapshot_id: 'foo' } } ] }
45
+ expect(subject.image_snapshot(fake_ami)).to eq('foo')
46
46
  end
47
47
 
48
48
  it "returns nil if the snapshot is nil" do
49
49
  fake_ami = double("ami")
50
- fake_ami.stub(:block_devices) { [ { ebs: {snapshot_id: nil } } ] }
51
- s.image_snapshot(fake_ami).should be_nil
50
+ allow(fake_ami).to receive(:block_devices) { [ { ebs: {snapshot_id: nil } } ] }
51
+ expect(subject.image_snapshot(fake_ami)).to be_nil
52
52
  end
53
53
 
54
54
  it "returns nil if the ebs is nil" do
55
55
  fake_ami = double("ami")
56
- fake_ami.stub(:block_devices) { [ { ebs: nil } ] }
57
- s.image_snapshot(fake_ami).should be_nil
56
+ allow(fake_ami).to receive(:block_devices) { [ { ebs: nil } ] }
57
+ expect(subject.image_snapshot(fake_ami)).to be_nil
58
58
  end
59
59
 
60
60
  it "returns nil if the device is nil" do
61
61
  fake_ami = double("ami")
62
- fake_ami.stub(:block_devices) { [ nil ] }
63
- s.image_snapshot(fake_ami).should be_nil
62
+ allow(fake_ami).to receive(:block_devices) { [ nil ] }
63
+ expect(subject.image_snapshot(fake_ami)).to be_nil
64
64
  end
65
65
  end
66
66
 
67
67
  describe '#delete_snapshots' do
68
- subject(:s) do
68
+ subject() do
69
69
  AWS.stub!
70
70
  s = Automan::Ec2::Image.new
71
71
  s.logger = Logger.new('/dev/null')
@@ -74,67 +74,67 @@ describe Automan::Ec2::Image do
74
74
 
75
75
  it 'does not delete snapshots with status != :completed' do
76
76
  snapshot = double(:snapshot)
77
- snapshot.stub(:status).and_return(:foo)
78
- snapshot.stub(:id)
79
- snapshot.should_not_receive(:delete)
80
- s.delete_snapshots( [ snapshot ])
77
+ allow(snapshot).to receive(:status).and_return(:foo)
78
+ allow(snapshot).to receive(:id)
79
+ expect(snapshot).to_not receive(:delete)
80
+ subject.delete_snapshots( [ snapshot ])
81
81
  end
82
82
 
83
83
  it 'deletes snapshots with status == :completed' do
84
84
  snapshot = double(:snapshot)
85
- snapshot.stub(:status).and_return(:completed)
86
- snapshot.stub(:id)
87
- snapshot.should_receive(:delete)
88
- s.delete_snapshots( [ snapshot ])
85
+ allow(snapshot).to receive(:status).and_return(:completed)
86
+ allow(snapshot).to receive(:id)
87
+ expect(snapshot).to receive(:delete)
88
+ subject.delete_snapshots( [ snapshot ])
89
89
  end
90
90
  end
91
91
 
92
92
  describe '#deregister_images' do
93
- subject(:s) do
93
+ subject() do
94
94
  AWS.stub!
95
95
  s = Automan::Ec2::Image.new
96
96
  s.logger = Logger.new('/dev/null')
97
- s.stub(:image_snapshot).and_return('foo')
97
+ allow(s).to receive(:image_snapshot).and_return('foo')
98
98
  s
99
99
  end
100
100
 
101
101
  before(:each) do
102
102
  @image = double(:image)
103
- @image.stub(:id)
104
- s.stub(:my_images).and_return( [ @image ] )
103
+ allow(@image).to receive(:id)
104
+ allow(subject).to receive(:my_images).and_return( [ @image ] )
105
105
  end
106
106
 
107
107
  it 'does not deregister images with state != :available' do
108
- @image.stub(:state).and_return(:foo)
109
- @image.stub(:tags).and_return( {'CanPrune' => 'yes'} )
110
- @image.should_not_receive(:delete)
111
- s.deregister_images( [ 'foo' ] )
108
+ allow(@image).to receive(:state).and_return(:foo)
109
+ allow(@image).to receive(:tags).and_return( {'CanPrune' => 'yes'} )
110
+ expect(@image).to_not receive(:delete)
111
+ subject.deregister_images( [ 'foo' ] )
112
112
  end
113
113
 
114
114
  it 'does not deregister images w/o prunable tag' do
115
- @image.stub(:state).and_return(:available)
116
- @image.stub(:tags).and_return( Hash.new )
117
- @image.should_not_receive(:delete)
118
- s.deregister_images( [ 'foo' ] )
115
+ allow(@image).to receive(:state).and_return(:available)
116
+ allow(@image).to receive(:tags).and_return( Hash.new )
117
+ expect(@image).to_not receive(:delete)
118
+ subject.deregister_images( [ 'foo' ] )
119
119
  end
120
120
 
121
121
  it 'does not deregister images whose snapshots are not in the list' do
122
- @image.stub(:state).and_return(:available)
123
- @image.stub(:tags).and_return( {'CanPrune' => 'yes'} )
124
- @image.should_not_receive(:delete)
125
- s.deregister_images( [ 'bar' ] )
122
+ allow(@image).to receive(:state).and_return(:available)
123
+ allow(@image).to receive(:tags).and_return( {'CanPrune' => 'yes'} )
124
+ expect(@image).to_not receive(:delete)
125
+ subject.deregister_images( [ 'bar' ] )
126
126
  end
127
127
 
128
128
  it 'deletes available, prunable images on the list' do
129
- @image.stub(:state).and_return(:available)
130
- @image.stub(:tags).and_return( {'CanPrune' => 'yes'} )
131
- @image.should_receive(:delete)
132
- s.deregister_images( [ 'foo' ] )
129
+ allow(@image).to receive(:state).and_return(:available)
130
+ allow(@image).to receive(:tags).and_return( {'CanPrune' => 'yes'} )
131
+ expect(@image).to receive(:delete)
132
+ subject.deregister_images( [ 'foo' ] )
133
133
  end
134
134
  end
135
135
 
136
136
  describe '#is_more_than_month_old?' do
137
- subject(:s) do
137
+ subject() do
138
138
  AWS.stub!
139
139
  s = Automan::Ec2::Image.new
140
140
  s.logger = Logger.new('/dev/null')
@@ -142,17 +142,17 @@ describe Automan::Ec2::Image do
142
142
  end
143
143
 
144
144
  it 'returns false if argument is not a Time object' do
145
- s.is_more_than_month_old?(Object.new).should be_false
145
+ expect(subject.is_more_than_month_old?(Object.new)).to be_falsey
146
146
  end
147
147
 
148
148
  it 'returns true if time is more than 30 days in the past' do
149
149
  days_of_yore = Time.now - (60*60*24*30)
150
- s.is_more_than_month_old?(days_of_yore).should be_true
150
+ expect(subject.is_more_than_month_old?(days_of_yore)).to be_truthy
151
151
  end
152
152
 
153
153
  it 'returns false if time is in the last 30 days' do
154
154
  just_yesterday = Time.now - (60*60*24)
155
- s.is_more_than_month_old?(just_yesterday).should be_false
155
+ expect(subject.is_more_than_month_old?(just_yesterday)).to be_falsey
156
156
  end
157
157
  end
158
158
  end
@@ -2,14 +2,14 @@ require "automan"
2
2
 
3
3
  describe Automan::Ec2::Instance do
4
4
 
5
- it { should respond_to :windows_password }
6
- it { should respond_to :password_data }
7
- it { should respond_to :decrypt_password }
8
- it { should respond_to :windows_name }
9
- it { should respond_to :show_env }
5
+ it { is_expected.to respond_to :windows_password }
6
+ it { is_expected.to respond_to :password_data }
7
+ it { is_expected.to respond_to :decrypt_password }
8
+ it { is_expected.to respond_to :windows_name }
9
+ it { is_expected.to respond_to :show_env }
10
10
 
11
11
  describe '#windows_password' do
12
- subject(:i) do
12
+ subject() do
13
13
  AWS.stub!
14
14
  i = Automan::Ec2::Instance.new
15
15
  i.logger = Logger.new('/dev/null')
@@ -17,24 +17,24 @@ describe Automan::Ec2::Instance do
17
17
  end
18
18
 
19
19
  it "returns nil if password could not be found" do
20
- i.stub(:password_data).and_return nil
21
- i.windows_password('foo','bar').should be_nil
20
+ allow(subject).to receive(:password_data).and_return nil
21
+ expect(subject.windows_password('foo','bar')).to be_nil
22
22
  end
23
23
 
24
24
  it "returns nil if the aws request fails" do
25
- i.stub(:password_data).and_raise Automan::Ec2::RequestFailedError
26
- i.windows_password('foo','bar').should be_nil
25
+ allow(subject).to receive(:password_data).and_raise Automan::Ec2::RequestFailedError
26
+ expect(subject.windows_password('foo','bar')).to be_nil
27
27
  end
28
28
 
29
29
  it "returns nil if the decrypt fails" do
30
- i.stub(:password_data).and_return 'foo'
31
- i.stub(:decrypt_password).and_return nil
32
- i.windows_password('foo','bar').should be_nil
30
+ allow(subject).to receive(:password_data).and_return 'foo'
31
+ allow(subject).to receive(:decrypt_password).and_return nil
32
+ expect(subject.windows_password('foo','bar')).to be_nil
33
33
  end
34
34
  end
35
35
 
36
36
  describe '#windows_name' do
37
- subject(:i) do
37
+ subject() do
38
38
  AWS.stub!
39
39
  i = Automan::Ec2::Instance.new
40
40
  i.logger = Logger.new('/dev/null')
@@ -42,15 +42,15 @@ describe Automan::Ec2::Instance do
42
42
  end
43
43
 
44
44
  it "returns nil if ip_address is nil" do
45
- i.windows_name(nil).should be_nil
45
+ expect(subject.windows_name(nil)).to be_nil
46
46
  end
47
47
 
48
48
  it "returns nil if ip_address is empty" do
49
- i.windows_name("").should be_nil
49
+ expect(subject.windows_name("")).to be_nil
50
50
  end
51
51
 
52
52
  it "converts ip_address to ip-xxxxxxxx" do
53
- i.windows_name('54.56.78.90').should eq 'ip-36384e5a'
53
+ expect(subject.windows_name('54.56.78.90')).to eq 'ip-36384e5a'
54
54
  end
55
55
  end
56
56
 
@@ -1,39 +1,39 @@
1
1
  require 'automan/mixins/aws_caller'
2
2
 
3
3
  describe Automan::Mixins::AwsCaller do
4
- let(:s) { (Class.new { include Automan::Mixins::AwsCaller }).new }
4
+ subject() { (Class.new { include Automan::Mixins::AwsCaller }).new }
5
5
 
6
6
  services = [
7
7
  :s3, :cfn, :as, :eb, :r53, :elb, :rds, :ec2
8
8
  ]
9
9
 
10
10
  services.each do |svc|
11
- it { s.should respond_to svc }
11
+ it { is_expected.to respond_to svc }
12
12
  end
13
13
 
14
- it { s.should respond_to :parse_s3_path }
14
+ it { is_expected.to respond_to :parse_s3_path }
15
15
 
16
16
  describe '#parse_s3_path' do
17
17
  it "parses s3 path into bucket and key" do
18
- bucket, key = s.parse_s3_path('s3://foo/bar/baz')
19
- bucket.should eq('foo')
20
- key.should eq ('bar/baz')
18
+ bucket, key = subject.parse_s3_path('s3://foo/bar/baz')
19
+ expect(bucket).to eq('foo')
20
+ expect(key).to eq ('bar/baz')
21
21
  end
22
22
 
23
23
  it "raises error if it doesn't start with s3://" do
24
24
  expect {
25
- s.parse_s3_path 'foo'
25
+ subject.parse_s3_path 'foo'
26
26
  }.to raise_error ArgumentError
27
27
  end
28
28
  end
29
29
 
30
30
  describe '#looks_like_s3_path?' do
31
31
  it 'returns true if it begins with "s3://"' do
32
- s.looks_like_s3_path?('s3://foo').should be_true
32
+ expect(subject.looks_like_s3_path?('s3://foo')).to be_truthy
33
33
  end
34
34
 
35
35
  it 'returns false if it does not start with "s3://"' do
36
- s.looks_like_s3_path?('foobar').should be_false
36
+ expect(subject.looks_like_s3_path?('foobar')).to be_falsey
37
37
  end
38
38
  end
39
39
  end