beaker 4.39.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/release.yml +2 -2
  4. data/.github/workflows/test.yml +26 -13
  5. data/.rubocop.yml +6 -21
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +22 -0
  8. data/Gemfile +12 -7
  9. data/Rakefile +99 -111
  10. data/acceptance/config/acceptance-options.rb +1 -1
  11. data/acceptance/config/base/acceptance-options.rb +2 -2
  12. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  13. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  14. data/acceptance/fixtures/module/Rakefile +1 -1
  15. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +8 -12
  16. data/acceptance/fixtures/module/spec/classes/init_spec.rb +0 -1
  17. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  18. data/acceptance/lib/helpers/test_helper.rb +4 -3
  19. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  20. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  21. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  22. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +3 -1
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +9 -9
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +19 -26
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +2 -2
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +18 -13
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +3 -3
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +22 -27
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +12 -16
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +3 -4
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +3 -3
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +4 -4
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +3 -4
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +3 -5
  40. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  41. data/acceptance/tests/base/dsl/structure_test.rb +5 -11
  42. data/acceptance/tests/base/host/file_test.rb +2 -2
  43. data/acceptance/tests/base/host/group_test.rb +0 -1
  44. data/acceptance/tests/base/host/host_test.rb +66 -63
  45. data/acceptance/tests/base/host/packages.rb +1 -2
  46. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  47. data/acceptance/tests/base/host/user_test.rb +0 -1
  48. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  49. data/acceptance/tests/base/test_suite/export.rb +6 -9
  50. data/acceptance/tests/install/from_file.rb +2 -4
  51. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  52. data/acceptance/tests/subcommands/destroy.rb +19 -21
  53. data/acceptance/tests/subcommands/exec.rb +0 -1
  54. data/acceptance/tests/subcommands/init.rb +2 -3
  55. data/acceptance/tests/subcommands/provision.rb +0 -1
  56. data/beaker.gemspec +4 -8
  57. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  58. data/docs/how_to/debug_beaker_tests.md +12 -12
  59. data/docs/how_to/hosts/eos.md +2 -12
  60. data/docs/how_to/install_puppet.md +0 -18
  61. data/docs/how_to/the_beaker_dsl.md +0 -2
  62. data/lib/beaker/cli.rb +59 -68
  63. data/lib/beaker/command.rb +20 -28
  64. data/lib/beaker/command_factory.rb +3 -2
  65. data/lib/beaker/dsl/assertions.rb +6 -18
  66. data/lib/beaker/dsl/helpers/hocon_helpers.rb +3 -7
  67. data/lib/beaker/dsl/helpers/host_helpers.rb +62 -123
  68. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  69. data/lib/beaker/dsl/helpers/web_helpers.rb +19 -27
  70. data/lib/beaker/dsl/helpers.rb +2 -4
  71. data/lib/beaker/dsl/outcomes.rb +13 -15
  72. data/lib/beaker/dsl/patterns.rb +1 -3
  73. data/lib/beaker/dsl/roles.rb +17 -20
  74. data/lib/beaker/dsl/structure.rb +53 -65
  75. data/lib/beaker/dsl/test_tagging.rb +7 -10
  76. data/lib/beaker/dsl/wrappers.rb +15 -16
  77. data/lib/beaker/dsl.rb +2 -3
  78. data/lib/beaker/host/aix/exec.rb +1 -1
  79. data/lib/beaker/host/aix/file.rb +0 -1
  80. data/lib/beaker/host/aix/group.rb +1 -1
  81. data/lib/beaker/host/aix/user.rb +1 -1
  82. data/lib/beaker/host/aix.rb +3 -4
  83. data/lib/beaker/host/cisco.rb +27 -39
  84. data/lib/beaker/host/eos.rb +4 -30
  85. data/lib/beaker/host/freebsd/exec.rb +1 -1
  86. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  87. data/lib/beaker/host/freebsd.rb +9 -12
  88. data/lib/beaker/host/mac/exec.rb +4 -4
  89. data/lib/beaker/host/mac/group.rb +7 -7
  90. data/lib/beaker/host/mac/pkg.rb +3 -106
  91. data/lib/beaker/host/mac/user.rb +2 -2
  92. data/lib/beaker/host/mac.rb +8 -9
  93. data/lib/beaker/host/pswindows/exec.rb +66 -70
  94. data/lib/beaker/host/pswindows/file.rb +3 -5
  95. data/lib/beaker/host/pswindows/group.rb +3 -3
  96. data/lib/beaker/host/pswindows/pkg.rb +12 -12
  97. data/lib/beaker/host/pswindows/user.rb +3 -3
  98. data/lib/beaker/host/pswindows.rb +4 -3
  99. data/lib/beaker/host/unix/exec.rb +80 -82
  100. data/lib/beaker/host/unix/file.rb +38 -43
  101. data/lib/beaker/host/unix/group.rb +1 -1
  102. data/lib/beaker/host/unix/pkg.rb +154 -417
  103. data/lib/beaker/host/unix/user.rb +2 -2
  104. data/lib/beaker/host/unix.rb +8 -11
  105. data/lib/beaker/host/windows/exec.rb +17 -17
  106. data/lib/beaker/host/windows/file.rb +3 -3
  107. data/lib/beaker/host/windows/group.rb +3 -3
  108. data/lib/beaker/host/windows/pkg.rb +3 -54
  109. data/lib/beaker/host/windows/user.rb +3 -3
  110. data/lib/beaker/host/windows.rb +12 -12
  111. data/lib/beaker/host.rb +76 -133
  112. data/lib/beaker/host_prebuilt_steps.rb +93 -198
  113. data/lib/beaker/hypervisor/noop.rb +2 -4
  114. data/lib/beaker/hypervisor.rb +44 -61
  115. data/lib/beaker/local_connection.rb +2 -4
  116. data/lib/beaker/logger.rb +68 -76
  117. data/lib/beaker/logger_junit.rb +21 -25
  118. data/lib/beaker/network_manager.rb +39 -42
  119. data/lib/beaker/options/command_line_parser.rb +12 -23
  120. data/lib/beaker/options/hosts_file_parser.rb +16 -24
  121. data/lib/beaker/options/options_file_parser.rb +3 -6
  122. data/lib/beaker/options/options_hash.rb +2 -7
  123. data/lib/beaker/options/parser.rb +86 -102
  124. data/lib/beaker/options/presets.rb +114 -123
  125. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  126. data/lib/beaker/options/validator.rb +26 -31
  127. data/lib/beaker/perf.rb +22 -27
  128. data/lib/beaker/platform.rb +38 -46
  129. data/lib/beaker/result.rb +7 -6
  130. data/lib/beaker/shared/error_handler.rb +8 -10
  131. data/lib/beaker/shared/fog_credentials.rb +5 -9
  132. data/lib/beaker/shared/host_manager.rb +36 -41
  133. data/lib/beaker/shared/options_resolver.rb +3 -7
  134. data/lib/beaker/shared/repetition.rb +2 -4
  135. data/lib/beaker/shared/semvar.rb +37 -41
  136. data/lib/beaker/shared/timed.rb +0 -3
  137. data/lib/beaker/shared.rb +1 -1
  138. data/lib/beaker/ssh_connection.rb +38 -47
  139. data/lib/beaker/subcommand.rb +17 -24
  140. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  141. data/lib/beaker/tasks/quick_start.rb +4 -9
  142. data/lib/beaker/tasks/rake_task.rb +25 -27
  143. data/lib/beaker/tasks/test.rb +4 -4
  144. data/lib/beaker/test_case.rb +15 -27
  145. data/lib/beaker/test_suite.rb +35 -39
  146. data/lib/beaker/test_suite_result.rb +45 -47
  147. data/lib/beaker/version.rb +1 -1
  148. data/lib/beaker.rb +5 -6
  149. data/rubocop.yml +39 -0
  150. data/spec/beaker/cli_spec.rb +121 -142
  151. data/spec/beaker/command_spec.rb +55 -59
  152. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  153. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  154. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  155. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +28 -34
  156. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  157. data/spec/beaker/dsl/roles_spec.rb +125 -130
  158. data/spec/beaker/dsl/structure_spec.rb +169 -158
  159. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  160. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  161. data/spec/beaker/host/aix_spec.rb +14 -14
  162. data/spec/beaker/host/cisco_spec.rb +84 -94
  163. data/spec/beaker/host/eos_spec.rb +15 -36
  164. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  165. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  166. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  167. data/spec/beaker/host/mac/group_spec.rb +47 -56
  168. data/spec/beaker/host/mac/user_spec.rb +53 -62
  169. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  170. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  171. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  172. data/spec/beaker/host/pswindows_spec.rb +13 -13
  173. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  174. data/spec/beaker/host/unix/file_spec.rb +66 -73
  175. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  176. data/spec/beaker/host/unix_spec.rb +11 -207
  177. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  178. data/spec/beaker/host/windows/file_spec.rb +18 -19
  179. data/spec/beaker/host/windows/group_spec.rb +10 -12
  180. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  181. data/spec/beaker/host/windows/user_spec.rb +17 -23
  182. data/spec/beaker/host/windows_spec.rb +39 -39
  183. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  184. data/spec/beaker/host_spec.rb +204 -284
  185. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  186. data/spec/beaker/localhost_connection_spec.rb +10 -11
  187. data/spec/beaker/logger_junit_spec.rb +19 -30
  188. data/spec/beaker/logger_spec.rb +153 -136
  189. data/spec/beaker/network_manager_spec.rb +23 -23
  190. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  191. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  192. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  193. data/spec/beaker/options/options_hash_spec.rb +4 -6
  194. data/spec/beaker/options/parser_spec.rb +167 -167
  195. data/spec/beaker/options/presets_spec.rb +7 -9
  196. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  197. data/spec/beaker/options/validator_spec.rb +10 -11
  198. data/spec/beaker/perf_spec.rb +18 -21
  199. data/spec/beaker/platform_spec.rb +25 -36
  200. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  201. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  202. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  203. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  204. data/spec/beaker/shared/repetition_spec.rb +17 -24
  205. data/spec/beaker/shared/semvar_spec.rb +21 -26
  206. data/spec/beaker/ssh_connection_spec.rb +76 -83
  207. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  208. data/spec/beaker/subcommand_spec.rb +75 -77
  209. data/spec/beaker/test_case_spec.rb +25 -50
  210. data/spec/beaker/test_suite_spec.rb +147 -154
  211. data/spec/helpers.rb +48 -53
  212. data/spec/matchers.rb +8 -7
  213. data/spec/mocks.rb +1 -6
  214. data/spec/spec_helper.rb +0 -1
  215. metadata +13 -37
  216. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  217. data/acceptance/tests/base/external_resources_test.rb +0 -31
  218. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -12,17 +12,16 @@ end
12
12
 
13
13
  module Beaker
14
14
  describe CLI do
15
-
16
- let(:cli) {
15
+ let(:cli) do
17
16
  allow(File).to receive(:exist?).and_call_original
18
17
  allow(File).to receive(:exist?).with('.beaker.yml').and_return(false)
19
18
  described_class.new.parse_options
20
- }
19
+ end
21
20
 
22
21
  context 'initializing and parsing' do
23
- let( :cli ) {
22
+ let(:cli) do
24
23
  described_class.new
25
- }
24
+ end
26
25
 
27
26
  describe 'instance variable initialization' do
28
27
  it 'creates a logger for use before parse is called' do
@@ -60,18 +59,18 @@ module Beaker
60
59
 
61
60
  it 'prints the version and exits cleanly' do
62
61
  expect(cli.logger).to receive(:notify).once
63
- expect{ cli.parse_options(['--version']) }.to raise_exception(SystemExit) { |e| expect(e.success?).to eq(true) }
62
+ expect { cli.parse_options(['--version']) }.to raise_exception(SystemExit) { |e| expect(e.success?).to eq(true) }
64
63
  end
65
64
 
66
65
  it 'prints the help and exits cleanly' do
67
66
  expect(cli.logger).to receive(:notify).once
68
- expect{ cli.parse_options(['--help']) }.to raise_exception(SystemExit) { |e| expect(e.success?).to eq(true) }
67
+ expect { cli.parse_options(['--help']) }.to raise_exception(SystemExit) { |e| expect(e.success?).to eq(true) }
69
68
  end
70
69
  end
71
70
 
72
71
  describe '#print_version_and_options' do
73
72
  before do
74
- options = Beaker::Options::OptionsHash.new
73
+ options = Beaker::Options::OptionsHash.new
75
74
  options[:beaker_version] = 'version_number'
76
75
  cli.instance_variable_set(:@options, options)
77
76
  end
@@ -83,23 +82,20 @@ module Beaker
83
82
  end
84
83
  end
85
84
 
86
-
87
85
  describe '#configured_options' do
88
86
  it 'returns a list of options that were not presets' do
89
87
  attribution = cli.instance_variable_get(:@attribution)
90
88
  attribution.each do |attribute, setter|
91
- if setter == 'preset'
92
- expect(cli.configured_options[attribute]).to be_nil
93
- end
89
+ expect(cli.configured_options[attribute]).to be_nil if setter == 'preset'
94
90
  end
95
91
  end
96
92
  end
97
93
 
98
94
  describe '#combined_instance_and_options_hosts' do
99
- let(:options_host) { {'HOSTS' => {'ubuntu' => {:options_attribute => 'options'}} }}
100
- let(:instance_host ) {
101
- [Beaker::Host.create('ubuntu', {:platform => 'host'}, {} )]
102
- }
95
+ let(:options_host) { { 'HOSTS' => { 'ubuntu' => { :options_attribute => 'options' } } } }
96
+ let(:instance_host) do
97
+ [Beaker::Host.create('ubuntu', { :platform => 'host' }, {})]
98
+ end
103
99
 
104
100
  before do
105
101
  cli.instance_variable_set(:@options, options_host)
@@ -117,14 +113,14 @@ module Beaker
117
113
 
118
114
  context 'when hosts share IP addresses' do
119
115
  let(:options_host) do
120
- {'HOSTS' => {'host1' => {:options_attribute => 'options'},
121
- 'host2' => {:options_attribute => 'options'}}}
116
+ { 'HOSTS' => { 'host1' => { :options_attribute => 'options' },
117
+ 'host2' => { :options_attribute => 'options' }, } }
122
118
  end
123
- let(:instance_host ) do
119
+ let(:instance_host) do
124
120
  [Beaker::Host.create('host1',
125
- {:platform => 'host', :ip => '127.0.0.1'}, {} ),
121
+ { :platform => 'host', :ip => '127.0.0.1' }, {}),
126
122
  Beaker::Host.create('host2',
127
- {:platform => 'host', :ip => '127.0.0.1'}, {} )]
123
+ { :platform => 'host', :ip => '127.0.0.1' }, {}),]
128
124
  end
129
125
 
130
126
  it 'creates separate entries for each host' do
@@ -138,7 +134,7 @@ module Beaker
138
134
 
139
135
  context 'execute!' do
140
136
  before do
141
- stub_const("Beaker::Logger", double().as_null_object )
137
+ stub_const("Beaker::Logger", double.as_null_object)
142
138
  File.open("sample.cfg", "w+") do |file|
143
139
  file.write("HOSTS:\n")
144
140
  file.write(" myhost:\n")
@@ -147,9 +143,9 @@ module Beaker
147
143
  file.write(" platform: ubuntu-x-x\n")
148
144
  file.write("CONFIG:\n")
149
145
  end
150
- allow( cli ).to receive(:setup).and_return(true)
151
- allow( cli ).to receive(:validate).and_return(true)
152
- allow( cli ).to receive(:provision).and_return(true)
146
+ allow(cli).to receive(:setup).and_return(true)
147
+ allow(cli).to receive(:validate).and_return(true)
148
+ allow(cli).to receive(:provision).and_return(true)
153
149
  end
154
150
 
155
151
  describe "test fail mode" do
@@ -157,44 +153,41 @@ module Beaker
157
153
  options = cli.instance_variable_get(:@options)
158
154
  options[:fail_mode] = 'slow'
159
155
  cli.instance_variable_set(:@options, options)
160
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_throw("bad test")
161
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode])
162
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
163
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
156
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_throw("bad test")
157
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode])
158
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
159
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
164
160
 
165
- expect( cli ).to receive(:run_suite).twice
166
- expect{ cli.execute! }.to raise_error
161
+ expect(cli).to receive(:run_suite).twice
162
+ expect { cli.execute! }.to raise_error
167
163
  expect(cli.instance_variable_get(:@attribution)[:logger]).to be == 'runtime'
168
164
  expect(cli.instance_variable_get(:@attribution)[:timestamp]).to be == 'runtime'
169
165
  expect(cli.instance_variable_get(:@attribution)[:beaker_version]).to be == 'runtime'
170
-
171
166
  end
172
167
 
173
168
  it 'continues testing after failed test if using slow fail_mode' do
174
169
  options = cli.instance_variable_get(:@options)
175
170
  options[:fail_mode] = 'slow'
176
171
  cli.instance_variable_set(:@options, options)
177
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
178
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
179
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
180
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
181
-
182
- expect( cli ).to receive(:run_suite).exactly( 4 ).times
183
- expect{ cli.execute! }.to raise_error
172
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
173
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
174
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
175
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
184
176
 
177
+ expect(cli).to receive(:run_suite).exactly(4).times
178
+ expect { cli.execute! }.to raise_error
185
179
  end
186
180
 
187
181
  it 'stops testing after failed test if using fast fail_mode' do
188
182
  options = cli.instance_variable_get(:@options)
189
183
  options[:fail_mode] = 'fast'
190
184
  cli.instance_variable_set(:@options, options)
191
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
192
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
193
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
194
-
195
- expect( cli ).to receive(:run_suite).exactly( 3 ).times
196
- expect{ cli.execute! }.to raise_error
185
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
186
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
187
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
197
188
 
189
+ expect(cli).to receive(:run_suite).exactly(3).times
190
+ expect { cli.execute! }.to raise_error
198
191
  end
199
192
  end
200
193
 
@@ -204,16 +197,15 @@ module Beaker
204
197
  options[:fail_mode] = 'fast'
205
198
  options[:preserve_hosts] = 'never'
206
199
  cli.instance_variable_set(:@options, options)
207
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
208
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
209
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
200
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
201
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
202
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
210
203
 
211
204
  netmanager = double(:netmanager)
212
205
  cli.instance_variable_set(:@network_manager, netmanager)
213
- expect( netmanager ).to receive(:cleanup).once
214
-
215
- expect{ cli.execute! }.to raise_error
206
+ expect(netmanager).to receive(:cleanup).once
216
207
 
208
+ expect { cli.execute! }.to raise_error
217
209
  end
218
210
 
219
211
  it 'cleans up SUTs post testing if no tests fail and preserve_hosts = never' do
@@ -221,20 +213,18 @@ module Beaker
221
213
  options[:fail_mode] = 'fast'
222
214
  options[:preserve_hosts] = 'never'
223
215
  cli.instance_variable_set(:@options, options)
224
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
225
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
226
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
227
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
216
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
217
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
218
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
219
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
228
220
 
229
221
  netmanager = double(:netmanager)
230
222
  cli.instance_variable_set(:@network_manager, netmanager)
231
- expect( netmanager ).to receive(:cleanup).once
232
-
233
- expect{ cli.execute! }.not_to raise_error
223
+ expect(netmanager).to receive(:cleanup).once
234
224
 
225
+ expect { cli.execute! }.not_to raise_error
235
226
  end
236
227
 
237
-
238
228
  it 'preserves SUTs post testing if no tests fail and preserve_hosts = always' do
239
229
  options = cli.instance_variable_get(:@options)
240
230
  options[:fail_mode] = 'fast'
@@ -242,18 +232,17 @@ module Beaker
242
232
  options[:log_dated_dir] = '.'
243
233
  options[:hosts_file] = 'sample.cfg'
244
234
  cli.instance_variable_set(:@options, options)
245
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
246
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
247
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
248
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
235
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
236
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
237
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
238
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
249
239
  cli.instance_variable_set(:@hosts, {})
250
240
 
251
241
  netmanager = double(:netmanager)
252
242
  cli.instance_variable_set(:@network_manager, netmanager)
253
- expect( netmanager ).not_to receive(:cleanup)
254
-
255
- expect{ cli.execute! }.not_to raise_error
243
+ expect(netmanager).not_to receive(:cleanup)
256
244
 
245
+ expect { cli.execute! }.not_to raise_error
257
246
  end
258
247
 
259
248
  it 'preserves SUTs post testing if no tests fail and preserve_hosts = always' do
@@ -261,16 +250,16 @@ module Beaker
261
250
  options[:fail_mode] = 'fast'
262
251
  options[:preserve_hosts] = 'always'
263
252
  cli.instance_variable_set(:@options, options)
264
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
265
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
266
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
267
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
253
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
254
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
255
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
256
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
268
257
 
269
258
  netmanager = double(:netmanager)
270
259
  cli.instance_variable_set(:@network_manager, netmanager)
271
- expect( netmanager ).not_to receive(:cleanup)
260
+ expect(netmanager).not_to receive(:cleanup)
272
261
 
273
- expect{ cli.execute! }.to raise_error
262
+ expect { cli.execute! }.to raise_error
274
263
  end
275
264
 
276
265
  it 'cleans up SUTs post testing if no tests fail and preserve_hosts = onfail' do
@@ -278,17 +267,16 @@ module Beaker
278
267
  options[:fail_mode] = 'fast'
279
268
  options[:preserve_hosts] = 'onfail'
280
269
  cli.instance_variable_set(:@options, options)
281
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
282
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
283
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
284
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
270
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
271
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
272
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
273
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
285
274
 
286
275
  netmanager = double(:netmanager)
287
276
  cli.instance_variable_set(:@network_manager, netmanager)
288
- expect( netmanager ).to receive(:cleanup).once
289
-
290
- expect{ cli.execute! }.not_to raise_error
277
+ expect(netmanager).to receive(:cleanup).once
291
278
 
279
+ expect { cli.execute! }.not_to raise_error
292
280
  end
293
281
 
294
282
  it 'preserves SUTs post testing if tests fail and preserve_hosts = onfail' do
@@ -296,17 +284,16 @@ module Beaker
296
284
  options[:fail_mode] = 'fast'
297
285
  options[:preserve_hosts] = 'onfail'
298
286
  cli.instance_variable_set(:@options, options)
299
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
300
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
301
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
302
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
287
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
288
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
289
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
290
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
303
291
 
304
292
  netmanager = double(:netmanager)
305
293
  cli.instance_variable_set(:@network_manager, netmanager)
306
- expect( netmanager ).not_to receive(:cleanup)
307
-
308
- expect{ cli.execute! }.to raise_error
294
+ expect(netmanager).not_to receive(:cleanup)
309
295
 
296
+ expect { cli.execute! }.to raise_error
310
297
  end
311
298
 
312
299
  it 'cleans up SUTs post testing if tests fail and preserve_hosts = onpass' do
@@ -314,17 +301,16 @@ module Beaker
314
301
  options[:fail_mode] = 'fast'
315
302
  options[:preserve_hosts] = 'onpass'
316
303
  cli.instance_variable_set(:@options, options)
317
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
318
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
319
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
320
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
304
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
305
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_throw("bad test")
306
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
307
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
321
308
 
322
309
  netmanager = double(:netmanager)
323
310
  cli.instance_variable_set(:@network_manager, netmanager)
324
- expect( netmanager ).to receive(:cleanup).once
325
-
326
- expect{ cli.execute! }.to raise_error
311
+ expect(netmanager).to receive(:cleanup).once
327
312
 
313
+ expect { cli.execute! }.to raise_error
328
314
  end
329
315
 
330
316
  it 'preserves SUTs post testing if no tests fail and preserve_hosts = onpass' do
@@ -335,22 +321,22 @@ module Beaker
335
321
  options[:hosts_file] = 'sample.cfg'
336
322
  cli.instance_variable_set(:@hosts, {})
337
323
  cli.instance_variable_set(:@options, options)
338
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
339
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
340
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
341
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
324
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
325
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
326
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
327
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
342
328
 
343
329
  netmanager = double(:netmanager)
344
330
  cli.instance_variable_set(:@network_manager, netmanager)
345
- expect( netmanager ).not_to receive(:cleanup)
331
+ expect(netmanager).not_to receive(:cleanup)
346
332
 
347
- expect{ cli.execute! }.not_to raise_error
333
+ expect { cli.execute! }.not_to raise_error
348
334
  end
349
335
  end
350
336
 
351
337
  describe "#preserve_hosts_file" do
352
338
  it 'removes the pre-suite/post-suite/tests and sets to []' do
353
- hosts = make_hosts
339
+ hosts = make_hosts
354
340
  options = cli.instance_variable_get(:@options)
355
341
  options[:log_dated_dir] = Dir.mktmpdir
356
342
  File.open("sample.cfg", "w+") do |file|
@@ -366,10 +352,10 @@ module Beaker
366
352
  file.write("CONFIG:\n")
367
353
  end
368
354
  options[:hosts_file] = 'sample.cfg'
369
- options[:pre_suite] = ['pre1', 'pre2', 'pre3']
355
+ options[:pre_suite] = %w[pre1 pre2 pre3]
370
356
  options[:post_suite] = ['post1']
371
357
  options[:pre_cleanup] = ['preclean1']
372
- options[:tests] = ['test1', 'test2']
358
+ options[:tests] = %w[test1 test2]
373
359
 
374
360
  cli.instance_variable_set(:@options, options)
375
361
  cli.instance_variable_set(:@hosts, hosts)
@@ -384,17 +370,16 @@ module Beaker
384
370
  end
385
371
 
386
372
  describe 'hosts file saving when preserve_hosts should happen' do
387
-
388
373
  before do
389
374
  options = cli.instance_variable_get(:@options)
390
375
  options[:fail_mode] = 'fast'
391
376
  options[:preserve_hosts] = 'onpass'
392
377
  options[:hosts_file] = 'sample.cfg'
393
378
  cli.instance_variable_set(:@options, options)
394
- allow( cli ).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
395
- allow( cli ).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
396
- allow( cli ).to receive(:run_suite).with(:post_suite).and_return(true)
397
- allow( cli ).to receive(:run_suite).with(:pre_cleanup).and_return(true)
379
+ allow(cli).to receive(:run_suite).with(:pre_suite, :fast).and_return(true)
380
+ allow(cli).to receive(:run_suite).with(:tests, options[:fail_mode]).and_return(true)
381
+ allow(cli).to receive(:run_suite).with(:post_suite).and_return(true)
382
+ allow(cli).to receive(:run_suite).with(:pre_cleanup).and_return(true)
398
383
 
399
384
  hosts = [
400
385
  make_host('petey', { :hypervisor => 'peterPan' }),
@@ -404,13 +389,12 @@ module Beaker
404
389
 
405
390
  netmanager = double(:netmanager)
406
391
  cli.instance_variable_set(:@network_manager, netmanager)
407
- expect( netmanager ).not_to receive(:cleanup)
408
-
392
+ expect(netmanager).not_to receive(:cleanup)
409
393
 
410
- allow( cli ).to receive( :print_env_vars_affecting_beaker )
394
+ allow(cli).to receive(:print_env_vars_affecting_beaker)
411
395
  logger = cli.instance_variable_get(:@logger)
412
- expect( logger ).to receive( :send ).with( anything, anything ).ordered
413
- expect( logger ).to receive( :send ).with( anything, anything ).ordered
396
+ expect(logger).to receive(:send).with(anything, anything).ordered
397
+ expect(logger).to receive(:send).with(anything, anything).ordered
414
398
  end
415
399
 
416
400
  it 'executes without error' do
@@ -418,7 +402,7 @@ module Beaker
418
402
  Dir.mktmpdir do |dir|
419
403
  options[:log_dated_dir] = File.absolute_path(dir)
420
404
 
421
- expect{ cli.execute! }.not_to raise_error
405
+ expect { cli.execute! }.not_to raise_error
422
406
  end
423
407
  end
424
408
 
@@ -430,7 +414,7 @@ module Beaker
430
414
  cli.execute!
431
415
 
432
416
  copied_hosts_file = File.join(File.absolute_path(dir), 'hosts_preserved.yml')
433
- expect( File ).to exist(copied_hosts_file)
417
+ expect(File).to exist(copied_hosts_file)
434
418
  end
435
419
  end
436
420
 
@@ -442,7 +426,7 @@ module Beaker
442
426
  cli.execute!
443
427
 
444
428
  copied_hosts_file = File.join(File.absolute_path(dir), 'hosts_preserved.yml')
445
- expect{ load_yaml_file(copied_hosts_file) }.not_to raise_error
429
+ expect { load_yaml_file(copied_hosts_file) }.not_to raise_error
446
430
  end
447
431
  end
448
432
 
@@ -455,7 +439,7 @@ module Beaker
455
439
 
456
440
  copied_hosts_file = File.join(File.absolute_path(dir), 'hosts_preserved.yml')
457
441
  yaml_content = load_yaml_file(copied_hosts_file)
458
- expect( yaml_content['CONFIG']['provision'] ).to be_falsy
442
+ expect(yaml_content['CONFIG']['provision']).to be_falsy
459
443
  end
460
444
  end
461
445
 
@@ -464,17 +448,16 @@ module Beaker
464
448
  Dir.mktmpdir do |dir|
465
449
  options[:log_dated_dir] = File.absolute_path(dir)
466
450
 
467
- expect( options ).not_to have_key(:hosts_preserved_yaml_file)
451
+ expect(options).not_to have_key(:hosts_preserved_yaml_file)
468
452
  cli.execute!
469
- expect( options ).to have_key(:hosts_preserved_yaml_file)
453
+ expect(options).to have_key(:hosts_preserved_yaml_file)
470
454
 
471
455
  copied_hosts_file = File.join(File.absolute_path(dir), 'hosts_preserved.yml')
472
- expect( options[:hosts_preserved_yaml_file] ).to be === copied_hosts_file
456
+ expect(options[:hosts_preserved_yaml_file]).to be === copied_hosts_file
473
457
  end
474
458
  end
475
459
 
476
460
  describe 'output text informing the user that re-use is possible' do
477
-
478
461
  it 'if unsupported, does not output extra text' do
479
462
  options = cli.instance_variable_get(:@options)
480
463
  Dir.mktmpdir do |dir|
@@ -482,9 +465,9 @@ module Beaker
482
465
  copied_hosts_file = File.join(File.absolute_path(dir), options[:hosts_file])
483
466
 
484
467
  logger = cli.instance_variable_get(:@logger)
485
- expect( logger ).not_to receive( :send ).with( anything, "\nYou can re-run commands against the already provisioned SUT(s) by following these steps:\n")
486
- expect( logger ).not_to receive( :send ).with( anything, "- change the hosts file to #{copied_hosts_file}")
487
- expect( logger ).not_to receive( :send ).with( anything, '- use the --no-provision flag')
468
+ expect(logger).not_to receive(:send).with(anything, "\nYou can re-run commands against the already provisioned SUT(s) by following these steps:\n")
469
+ expect(logger).not_to receive(:send).with(anything, "- change the hosts file to #{copied_hosts_file}")
470
+ expect(logger).not_to receive(:send).with(anything, '- use the --no-provision flag')
488
471
 
489
472
  cli.execute!
490
473
  end
@@ -499,11 +482,11 @@ module Beaker
499
482
  hosts << make_host('fusion', { :hypervisor => 'fusion' })
500
483
 
501
484
  reproducing_cmd = "the faith of the people"
502
- allow( cli ).to receive( :build_hosts_preserved_reproducing_command ).and_return( reproducing_cmd )
485
+ allow(cli).to receive(:build_hosts_preserved_reproducing_command).and_return(reproducing_cmd)
503
486
 
504
487
  logger = cli.instance_variable_get(:@logger)
505
- expect( logger ).to receive( :send ).with( anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n").ordered
506
- expect( logger ).to receive( :send ).with( anything, reproducing_cmd).ordered
488
+ expect(logger).to receive(:send).with(anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n").ordered
489
+ expect(logger).to receive(:send).with(anything, reproducing_cmd).ordered
507
490
 
508
491
  cli.execute!
509
492
  end
@@ -519,12 +502,12 @@ module Beaker
519
502
  hosts << make_host('docker', { :hypervisor => 'docker' })
520
503
 
521
504
  reproducing_cmd = "the crow flies true says the shoe to you"
522
- allow( cli ).to receive( :build_hosts_preserved_reproducing_command ).and_return( reproducing_cmd )
505
+ allow(cli).to receive(:build_hosts_preserved_reproducing_command).and_return(reproducing_cmd)
523
506
 
524
507
  logger = cli.instance_variable_get(:@logger)
525
- expect( logger ).to receive( :send ).with( anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n").ordered
526
- expect( logger ).to receive( :send ).with( anything, '(docker support is untested for this feature. please reference the docs for more info)').ordered
527
- expect( logger ).to receive( :send ).with( anything, reproducing_cmd).ordered
508
+ expect(logger).to receive(:send).with(anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n").ordered
509
+ expect(logger).to receive(:send).with(anything, '(docker support is untested for this feature. please reference the docs for more info)').ordered
510
+ expect(logger).to receive(:send).with(anything, reproducing_cmd).ordered
528
511
 
529
512
  cli.execute!
530
513
  end
@@ -540,28 +523,25 @@ module Beaker
540
523
  hosts << make_host('docker', { :hypervisor => 'docker' })
541
524
 
542
525
  logger = cli.instance_variable_get(:@logger)
543
- expect( logger ).not_to receive( :send ).with( anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n")
544
- expect( logger ).not_to receive( :send ).with( anything, '(docker support is untested for this feature. please reference the docs for more info)')
545
- expect( logger ).not_to receive( :send ).with( anything, "- change the hosts file to #{copied_hosts_file}")
546
- expect( logger ).not_to receive( :send ).with( anything, '- use the --no-provision flag')
526
+ expect(logger).not_to receive(:send).with(anything, "\nYou can re-run commands against the already provisioned SUT(s) with:\n")
527
+ expect(logger).not_to receive(:send).with(anything, '(docker support is untested for this feature. please reference the docs for more info)')
528
+ expect(logger).not_to receive(:send).with(anything, "- change the hosts file to #{copied_hosts_file}")
529
+ expect(logger).not_to receive(:send).with(anything, '- use the --no-provision flag')
547
530
 
548
531
  cli.execute!
549
532
  end
550
533
  end
551
-
552
-
553
534
  end
554
535
  end
555
536
 
556
537
  describe '#build_hosts_preserved_reproducing_command' do
557
-
558
538
  it 'replaces the hosts file' do
559
539
  new_hosts_file = 'john/deer/was/here.txt'
560
540
  command_to_sub = 'p --log-level debug --hosts pants/of/plan.poo jam --jankies --flag-business'
561
541
  command_correct = "p --log-level debug --hosts #{new_hosts_file} jam --jankies --flag-business"
562
542
 
563
543
  answer = cli.build_hosts_preserved_reproducing_command(command_to_sub, new_hosts_file)
564
- expect( answer ).to be_start_with(command_correct)
544
+ expect(answer).to be_start_with(command_correct)
565
545
  end
566
546
 
567
547
  it 'doesn\'t replace an entry if no --hosts key is found' do
@@ -569,7 +549,7 @@ module Beaker
569
549
  command_correct = 'p --log-level debug johnnypantaloons7 --jankies --flag-business'
570
550
 
571
551
  answer = cli.build_hosts_preserved_reproducing_command(command_to_sub, 'john/deer/plans.txt')
572
- expect( answer ).to be_start_with(command_correct)
552
+ expect(answer).to be_start_with(command_correct)
573
553
  end
574
554
 
575
555
  it 'removes any old --provision flags' do
@@ -577,7 +557,7 @@ module Beaker
577
557
  command_correct = 'jam --jankies --flag-business'
578
558
 
579
559
  answer = cli.build_hosts_preserved_reproducing_command(command_to_sub, 'can/talk/to/pigs.yml')
580
- expect( answer ).to be_start_with(command_correct)
560
+ expect(answer).to be_start_with(command_correct)
581
561
  end
582
562
 
583
563
  it 'removes any old --no-provision flags' do
@@ -585,10 +565,9 @@ module Beaker
585
565
  command_correct = 'jam --jankoos --flag-businesses'
586
566
 
587
567
  answer = cli.build_hosts_preserved_reproducing_command(command_to_sub, 'can/talk/to/bears.yml')
588
- expect( answer ).to be_start_with(command_correct)
568
+ expect(answer).to be_start_with(command_correct)
589
569
  end
590
570
  end
591
-
592
571
  end
593
572
  end
594
573
  end