tugboat 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/CODE_OF_CONDUCT.md +46 -0
  4. data/lib/tugboat/cli.rb +7 -1
  5. data/lib/tugboat/config.rb +11 -1
  6. data/lib/tugboat/middleware.rb +2 -0
  7. data/lib/tugboat/middleware/ask_for_credentials.rb +2 -1
  8. data/lib/tugboat/middleware/base.rb +31 -13
  9. data/lib/tugboat/middleware/check_snapshot_parameters.rb +16 -0
  10. data/lib/tugboat/middleware/info_droplet.rb +2 -2
  11. data/lib/tugboat/middleware/inject_client.rb +10 -1
  12. data/lib/tugboat/middleware/list_droplets.rb +5 -3
  13. data/lib/tugboat/version.rb +1 -1
  14. data/spec/cli/add_key_spec.rb +7 -9
  15. data/spec/cli/authorize_cli_spec.rb +4 -34
  16. data/spec/cli/config_cli_spec.rb +10 -5
  17. data/spec/cli/create_cli_spec.rb +20 -17
  18. data/spec/cli/debug_cli_spec.rb +11 -12
  19. data/spec/cli/destroy_cli_spec.rb +35 -12
  20. data/spec/cli/destroy_image_cli_spec.rb +12 -10
  21. data/spec/cli/droplets_cli_spec.rb +74 -48
  22. data/spec/cli/env_variable_spec.rb +4 -4
  23. data/spec/cli/halt_cli_spec.rb +16 -13
  24. data/spec/cli/help_cli_spec.rb +4 -4
  25. data/spec/cli/images_cli_spec.rb +9 -7
  26. data/spec/cli/info_cli_spec.rb +120 -50
  27. data/spec/cli/info_image_cli_spec.rb +24 -23
  28. data/spec/cli/keys_cli_spec.rb +3 -3
  29. data/spec/cli/password_reset_cli_spec.rb +12 -12
  30. data/spec/cli/rebuild_cli_spec.rb +31 -24
  31. data/spec/cli/regions_cli_spec.rb +3 -3
  32. data/spec/cli/resize_cli_spec.rb +16 -16
  33. data/spec/cli/restart_cli_spec.rb +32 -11
  34. data/spec/cli/sizes_cli_spec.rb +3 -3
  35. data/spec/cli/snapshot_cli_spec.rb +25 -9
  36. data/spec/cli/ssh_cli_spec.rb +10 -10
  37. data/spec/cli/start_cli_spec.rb +15 -15
  38. data/spec/cli/verify_cli_spec.rb +4 -7
  39. data/spec/cli/version_cli_spec.rb +1 -2
  40. data/spec/cli/wait_cli_spec.rb +16 -16
  41. data/spec/config_spec.rb +7 -1
  42. data/spec/fixtures/show_droplets.json +7 -4
  43. data/spec/fixtures/show_droplets_paginated_first.json +10 -7
  44. data/spec/fixtures/show_droplets_paginated_last.json +11 -5
  45. data/spec/fixtures/show_droplets_private_ip.json +7 -4
  46. data/spec/middleware/base_spec.rb +1 -2
  47. data/spec/middleware/check_configuration_spec.rb +1 -1
  48. data/spec/middleware/check_credentials_spec.rb +1 -1
  49. data/spec/middleware/check_droplet_active_spec.rb +1 -1
  50. data/spec/middleware/check_droplet_inactive_spec.rb +1 -1
  51. data/spec/middleware/find_droplet_spec.rb +3 -5
  52. data/spec/middleware/find_image_spec.rb +3 -5
  53. data/spec/middleware/ssh_droplet_spec.rb +5 -10
  54. data/spec/shared/environment.rb +2 -18
  55. data/tugboat.gemspec +1 -2
  56. metadata +8 -6
@@ -13,9 +13,7 @@ describe Tugboat::CLI do
13
13
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
14
14
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_coreos_image'))
15
15
 
16
- cli.info_image('745.1.0 (alpha)')
17
-
18
- expect($stdout.string).to eq <<-eos
16
+ expected_string = <<-eos
19
17
  Image fuzzy name provided. Finding image ID...done\e[0m, 12789325 (745.1.0 (alpha))
20
18
 
21
19
  Name: 745.1.0 (alpha)
@@ -24,6 +22,8 @@ Distribution: CoreOS
24
22
  Min Disk Size: 20GB
25
23
  Regions: nyc1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
26
24
  eos
25
+
26
+ expect { cli.info_image('745.1.0 (alpha)') }.to output(expected_string).to_stdout
27
27
  end
28
28
 
29
29
  it 'shows an image with an id' do
@@ -35,10 +35,7 @@ Regions: nyc1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
35
35
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
36
36
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_redmine_image'))
37
37
 
38
- cli.options = cli.options.merge(id: 12_438_838)
39
- cli.info_image
40
-
41
- expect($stdout.string).to eq <<-eos
38
+ expected_string = <<-eos
42
39
  Image id provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
43
40
 
44
41
  Name: Redmine on 14.04
@@ -47,6 +44,9 @@ Distribution: Ubuntu
47
44
  Min Disk Size: 20GB
48
45
  Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
49
46
  eos
47
+
48
+ cli.options = cli.options.merge(id: 12_438_838)
49
+ expect { cli.info_image }.to output(expected_string).to_stdout
50
50
  end
51
51
 
52
52
  it 'shows an image with a name' do
@@ -58,10 +58,7 @@ Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
58
58
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
59
59
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_redmine_image'))
60
60
 
61
- cli.options = cli.options.merge(name: 'Redmine on 14.04')
62
- cli.info_image
63
-
64
- expect($stdout.string).to eq <<-eos
61
+ expected_string = <<-eos
65
62
  Image name provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
66
63
 
67
64
  Name: Redmine on 14.04
@@ -70,6 +67,9 @@ Distribution: Ubuntu
70
67
  Min Disk Size: 20GB
71
68
  Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
72
69
  eos
70
+
71
+ cli.options = cli.options.merge(name: 'Redmine on 14.04')
72
+ expect { cli.info_image }.to output(expected_string).to_stdout
73
73
  end
74
74
 
75
75
  it 'errors if no image with matching id is found' do
@@ -81,12 +81,12 @@ Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
81
81
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
82
82
  to_return(status: 404, body: fixture('not_found'), headers: {})
83
83
 
84
- cli.options = cli.options.merge(id: '123')
85
- expect { cli.info_image }.to raise_error(SystemExit)
86
-
87
- expect($stdout.string).to eq <<-eos
84
+ expected_string = <<-eos
88
85
  Image id provided. Finding Image...Failed to find Image: The resource you were accessing could not be found.
89
86
  eos
87
+
88
+ cli.options = cli.options.merge(id: '123')
89
+ expect { cli.info_image }.to raise_error(SystemExit).and output(expected_string).to_stdout
90
90
  end
91
91
 
92
92
  it 'errors if no image with matching name is found' do
@@ -95,12 +95,13 @@ Image id provided. Finding Image...Failed to find Image: The resource you were a
95
95
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
96
96
 
97
97
  cli.options = cli.options.merge(name: 'foobarbaz')
98
- expect { cli.info_image }.to raise_error(SystemExit)
99
98
 
100
- expect($stdout.string).to eq <<-eos
99
+ expected_string = <<-eos
101
100
  Image name provided. Finding Image...error
102
101
  Unable to find an image named 'foobarbaz'.
103
102
  eos
103
+
104
+ expect { cli.info_image }.to raise_error(SystemExit).and output(expected_string).to_stdout
104
105
  end
105
106
 
106
107
  it 'errors if no image with matching fuzzy name is found' do
@@ -108,12 +109,12 @@ Unable to find an image named 'foobarbaz'.
108
109
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
109
110
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
110
111
 
111
- expect { cli.info_image('foobarbaz') }.to raise_error(SystemExit)
112
-
113
- expect($stdout.string).to eq <<-eos
112
+ expected_string = <<-eos
114
113
  Image fuzzy name provided. Finding image ID...error
115
114
  Unable to find an image named 'foobarbaz'.
116
115
  eos
116
+
117
+ expect { cli.info_image('foobarbaz') }.to raise_error(SystemExit).and output(expected_string).to_stdout
117
118
  end
118
119
 
119
120
  it 'allows choice of multiple images' do
@@ -127,9 +128,7 @@ Unable to find an image named 'foobarbaz'.
127
128
 
128
129
  expect($stdin).to receive(:gets).and_return('0')
129
130
 
130
- cli.info_image('ubun')
131
-
132
- expect($stdout.string).to eq <<-eos
131
+ expected_string = <<-eos
133
132
  Image fuzzy name provided. Finding image ID...Multiple images found.
134
133
 
135
134
  0) 14.10 x32 (9801951)
@@ -148,6 +147,8 @@ Distribution: Ubuntu
148
147
  Min Disk Size: 20GB
149
148
  Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
150
149
  eos
150
+
151
+ expect { cli.info_image('ubun') }.to output(expected_string).to_stdout
151
152
  end
152
153
  end
153
154
  end
@@ -9,14 +9,14 @@ describe Tugboat::CLI do
9
9
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
10
10
  to_return(status: 200, body: fixture('show_keys'), headers: {})
11
11
 
12
- cli.keys
13
-
14
- expect($stdout.string).to eq <<-eos
12
+ expected_string = <<-eos
15
13
  SSH Keys:
16
14
  Name: My SSH Public Key, (id: 512189), fingerprint: 3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa
17
15
  Name: My Other SSH Public Key, (id: 512110), fingerprint: 3b:16:bf:d4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa
18
16
  eos
19
17
 
18
+ expect { cli.keys }.to output(expected_string).to_stdout
19
+
20
20
  expect(a_request(:get, 'https://api.digitalocean.com/v2/account/keys?per_page=200')).to have_been_made
21
21
  end
22
22
  end
@@ -18,13 +18,13 @@ describe Tugboat::CLI do
18
18
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
19
19
  to_return(status: 200, body: fixture('password_reset_response'), headers: {})
20
20
 
21
- cli.password_reset('example.com')
22
-
23
- expect($stdout.string).to eq <<-eos
21
+ expected_string = <<-eos
24
22
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
25
23
  Queuing password reset for 6918990 (example.com)...Password reset successful!
26
24
  Your new root password will be emailed to you
27
25
  eos
26
+
27
+ expect { cli.password_reset('example.com') }.to output(expected_string).to_stdout
28
28
  end
29
29
 
30
30
  it 'resets the root password given an id' do
@@ -45,14 +45,14 @@ Your new root password will be emailed to you
45
45
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
46
46
  to_return(status: 200, body: fixture('password_reset_response'), headers: {})
47
47
 
48
- cli.options = cli.options.merge(id: 6_918_990)
49
- cli.password_reset
50
-
51
- expect($stdout.string).to eq <<-eos
48
+ expected_string = <<-eos
52
49
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
53
50
  Queuing password reset for 6918990 (example.com)...Password reset successful!
54
51
  Your new root password will be emailed to you
55
52
  eos
53
+
54
+ cli.options = cli.options.merge(id: 6_918_990)
55
+ expect { cli.password_reset }.to output(expected_string).to_stdout
56
56
  end
57
57
 
58
58
  it 'resets the root password given a name' do
@@ -69,14 +69,14 @@ Your new root password will be emailed to you
69
69
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
70
70
  to_return(status: 200, body: fixture('password_reset_response'), headers: {})
71
71
 
72
- cli.options = cli.options.merge(name: 'example.com')
73
- cli.password_reset
74
-
75
- expect($stdout.string).to eq <<-eos
72
+ expected_string = <<-eos
76
73
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
77
74
  Queuing password reset for 6918990 (example.com)...Password reset successful!
78
75
  Your new root password will be emailed to you
79
76
  eos
77
+
78
+ cli.options = cli.options.merge(name: 'example.com')
79
+ expect { cli.password_reset }.to output(expected_string).to_stdout
80
80
  end
81
81
 
82
82
  it 'raises SystemExit when a request fails' do
@@ -95,7 +95,7 @@ Your new root password will be emailed to you
95
95
 
96
96
  cli.options = cli.options.merge(name: 'example.com')
97
97
 
98
- expect { cli.password_reset('example.com') }.to raise_error(SystemExit)
98
+ expect { cli.password_reset('example.com') }.to raise_error(SystemExit).and output(%r{Failed to reset password on Droplet: Some error}).to_stdout
99
99
  end
100
100
  end
101
101
  end
@@ -24,13 +24,13 @@ describe Tugboat::CLI do
24
24
 
25
25
  expect($stdin).to receive(:gets).and_return('y')
26
26
 
27
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
28
-
29
- expect($stdout.string).to eq <<-eos
27
+ expected_string = <<-eos
30
28
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
31
29
  Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
32
30
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
33
31
  eos
32
+
33
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
34
34
  end
35
35
 
36
36
  it 'rebuilds a droplet with an id based on an image with a fuzzy name' do
@@ -54,13 +54,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
54
54
  expect($stdin).to receive(:gets).and_return('y')
55
55
 
56
56
  cli.options = cli.options.merge(id: '12790328')
57
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
58
57
 
59
- expect($stdout.string).to eq <<-eos
58
+ expected_string = <<-eos
60
59
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
61
60
  Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
62
61
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
63
62
  eos
63
+
64
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
64
65
  end
65
66
 
66
67
  it 'rebuilds a droplet with a name based on an image with a fuzzy name' do
@@ -88,13 +89,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
88
89
  expect($stdin).to receive(:gets).and_return('y')
89
90
 
90
91
  cli.options = cli.options.merge(name: 'example.com')
91
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
92
92
 
93
- expect($stdout.string).to eq <<-eos
93
+ expected_string = <<-eos
94
94
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
95
95
  Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
96
96
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
97
97
  eos
98
+
99
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
98
100
  end
99
101
 
100
102
  it 'rebuilds a droplet with a fuzzy name based on an image with an id' do
@@ -125,14 +127,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
125
127
 
126
128
  expect($stdin).to receive(:gets).and_return('y')
127
129
 
128
- cli.options = cli.options.merge(image_id: 12_790_328)
129
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
130
-
131
- expect($stdout.string).to eq <<-eos
130
+ expected_string = <<-eos
132
131
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
133
132
  Image id provided. Finding Image...done\e[0m, 6376601 (My application image)
134
133
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 6376601 (My application image)...Rebuild complete
135
134
  eos
135
+
136
+ cli.options = cli.options.merge(image_id: 12_790_328)
137
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
136
138
  end
137
139
 
138
140
  it 'rebuilds a droplet with an id based on an image with an id' do
@@ -164,13 +166,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
164
166
  expect($stdin).to receive(:gets).and_return('y')
165
167
 
166
168
  cli.options = cli.options.merge(id: '12790328', image_id: 12_790_328)
167
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
168
169
 
169
- expect($stdout.string).to eq <<-eos
170
+ expected_string = <<-eos
170
171
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
171
172
  Image id provided. Finding Image...done\e[0m, 6376601 (My application image)
172
173
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 6376601 (My application image)...Rebuild complete
173
174
  eos
175
+
176
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
174
177
  end
175
178
 
176
179
  it 'rebuilds a droplet with a name based on an image with an id' do
@@ -202,13 +205,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
202
205
  expect($stdin).to receive(:gets).and_return('y')
203
206
 
204
207
  cli.options = cli.options.merge(name: 'example.com', image_id: 12_790_328)
205
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
206
208
 
207
- expect($stdout.string).to eq <<-eos
209
+ expected_string = <<-eos
208
210
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
209
211
  Image id provided. Finding Image...done\e[0m, 6376601 (My application image)
210
212
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 6376601 (My application image)...Rebuild complete
211
213
  eos
214
+
215
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
212
216
  end
213
217
 
214
218
  it 'rebuilds a droplet with a fuzzy name based on an image with a name' do
@@ -233,13 +237,13 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
233
237
 
234
238
  cli.options = cli.options.merge(image_name: '14.04 x64')
235
239
 
236
- cli.rebuild('example.com', 'ubuntu-14-04-x64')
237
-
238
- expect($stdout.string).to eq <<-eos
240
+ expected_string = <<-eos
239
241
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
240
242
  Image name provided. Finding Image...done\e[0m, 12790328 (14.04 x64)
241
243
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
242
244
  eos
245
+
246
+ expect { cli.rebuild('example.com', 'ubuntu-14-04-x64') }.to output(expected_string).to_stdout
243
247
  end
244
248
 
245
249
  it 'rebuilds a droplet with an id based on an image with a name' do
@@ -267,13 +271,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
267
271
  expect($stdin).to receive(:gets).and_return('y')
268
272
 
269
273
  cli.options = cli.options.merge(id: '12790328', image_name: '14.04 x64')
270
- cli.rebuild('example.com', '14.04 x64')
271
274
 
272
- expect($stdout.string).to eq <<-eos
275
+ expected_string = <<-eos
273
276
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
274
277
  Image name provided. Finding Image...done\e[0m, 12790328 (14.04 x64)
275
278
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
276
279
  eos
280
+
281
+ expect { cli.rebuild('example.com', '14.04 x64') }.to output(expected_string).to_stdout
277
282
  end
278
283
 
279
284
  it 'rebuilds a droplet with a name based on an image with a name' do
@@ -297,13 +302,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
297
302
  expect($stdin).to receive(:gets).and_return('y')
298
303
 
299
304
  cli.options = cli.options.merge(name: 'example.com', image_name: '14.04 x64')
300
- cli.rebuild('example.com', '14.04 x64')
301
305
 
302
- expect($stdout.string).to eq <<-eos
306
+ expected_string = <<-eos
303
307
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
304
308
  Image name provided. Finding Image...done\e[0m, 12790328 (14.04 x64)
305
309
  Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
306
310
  eos
311
+
312
+ expect { cli.rebuild('example.com', '14.04 x64') }.to output(expected_string).to_stdout
307
313
  end
308
314
 
309
315
  it 'rebuilds a droplet with confirm flag set' do
@@ -325,13 +331,14 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
325
331
  to_return(status: 200, body: '', headers: {})
326
332
 
327
333
  cli.options = cli.options.merge(confirm: 'no')
328
- cli.rebuild('example.com', '14.04 x64')
329
334
 
330
- expect($stdout.string).to eq <<-eos
335
+ expected_string = <<-eos
331
336
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
332
337
  Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
333
338
  Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
334
339
  eos
340
+
341
+ expect { cli.rebuild('example.com', '14.04 x64') }.to output(expected_string).to_stdout
335
342
  end
336
343
  end
337
344
  end
@@ -9,9 +9,7 @@ describe Tugboat::CLI do
9
9
  with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
10
10
  to_return(status: 200, body: fixture('show_regions'), headers: { 'Content-Type' => 'application/json' })
11
11
 
12
- cli.regions
13
-
14
- expect($stdout.string).to eq <<-eos
12
+ expected_string = <<-eos
15
13
  Regions:
16
14
  Amsterdam 1 (slug: ams1)
17
15
  Amsterdam 2 (slug: ams2)
@@ -24,6 +22,8 @@ San Francisco 1 (slug: sfo1)
24
22
  Singapore 1 (slug: sgp1)
25
23
  eos
26
24
 
25
+ expect { cli.regions }.to output(expected_string).to_stdout
26
+
27
27
  expect(a_request(:get, 'https://api.digitalocean.com/v2/regions?page=1&per_page=20')).
28
28
  to have_been_made
29
29
  end
@@ -18,13 +18,13 @@ describe Tugboat::CLI do
18
18
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
19
19
  to_return(status: 200, body: fixture('resize_droplet'), headers: {})
20
20
 
21
- cli.options = cli.options.merge(size: '1gb')
22
- cli.resize('example.com')
23
-
24
- expect($stdout.string).to eq <<-eos
21
+ expected_string = <<-eos
25
22
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
26
23
  Queuing resize for 6918990 (example.com)...Resize complete!
27
24
  eos
25
+
26
+ cli.options = cli.options.merge(size: '1gb')
27
+ expect { cli.resize('example.com') }.to output(expected_string).to_stdout
28
28
  end
29
29
 
30
30
  it 'resizes a droplet with an id' do
@@ -41,13 +41,13 @@ Queuing resize for 6918990 (example.com)...Resize complete!
41
41
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
42
42
  to_return(status: 200, body: fixture('resize_droplet'), headers: {})
43
43
 
44
- cli.options = cli.options.merge(size: '1gb', id: 6_918_990)
45
- cli.resize
46
-
47
- expect($stdout.string).to eq <<-eos
44
+ expected_string = <<-eos
48
45
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
49
46
  Queuing resize for 6918990 (example.com)...Resize complete!
50
47
  eos
48
+
49
+ cli.options = cli.options.merge(size: '1gb', id: 6_918_990)
50
+ expect { cli.resize }.to output(expected_string).to_stdout
51
51
  end
52
52
 
53
53
  it 'resizes a droplet with a name' do
@@ -64,13 +64,13 @@ Queuing resize for 6918990 (example.com)...Resize complete!
64
64
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
65
65
  to_return(status: 200, body: fixture('resize_droplet'), headers: {})
66
66
 
67
- cli.options = cli.options.merge(size: '1gb', name: 'example.com')
68
- cli.resize
69
-
70
- expect($stdout.string).to eq <<-eos
67
+ expected_string = <<-eos
71
68
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
72
69
  Queuing resize for 6918990 (example.com)...Resize complete!
73
70
  eos
71
+
72
+ cli.options = cli.options.merge(size: '1gb', name: 'example.com')
73
+ expect { cli.resize }.to output(expected_string).to_stdout
74
74
  end
75
75
 
76
76
  it 'raises SystemExit when a request fails' do
@@ -87,13 +87,13 @@ Queuing resize for 6918990 (example.com)...Resize complete!
87
87
  headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.9.2' }).
88
88
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 500, body: '{"status":"ERROR","message":"Some error"}')
89
89
 
90
- cli.options = cli.options.merge(size: '1gb')
91
- expect { cli.resize('example.com') }.to raise_error(SystemExit)
92
-
93
- expect($stdout.string).to eq <<-eos
90
+ expected_string = <<-eos
94
91
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
95
92
  Queuing resize for 6918990 (example.com)...Failed to resize Droplet: Some error
96
93
  eos
94
+
95
+ cli.options = cli.options.merge(size: '1gb')
96
+ expect { cli.resize('example.com') }.to raise_error(SystemExit).and output(expected_string).to_stdout
97
97
  end
98
98
  end
99
99
  end