beaker 4.38.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) 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 +36 -11
  5. data/.rubocop.yml +75 -0
  6. data/.rubocop_todo.yml +239 -0
  7. data/CHANGELOG.md +88 -33
  8. data/Gemfile +16 -4
  9. data/HISTORY.md +103 -0
  10. data/Rakefile +101 -112
  11. data/acceptance/config/acceptance-options.rb +1 -1
  12. data/acceptance/config/base/acceptance-options.rb +2 -2
  13. data/acceptance/config/hypervisor/acceptance-options.rb +2 -2
  14. data/acceptance/config/subcommands/acceptance-options.rb +2 -2
  15. data/acceptance/fixtures/module/Gemfile +1 -1
  16. data/acceptance/fixtures/module/Rakefile +3 -3
  17. data/acceptance/fixtures/module/spec/acceptance/demo_spec.rb +16 -23
  18. data/acceptance/fixtures/module/spec/classes/init_spec.rb +1 -2
  19. data/acceptance/fixtures/module/spec/spec_helper_acceptance.rb +3 -5
  20. data/acceptance/lib/helpers/test_helper.rb +7 -6
  21. data/acceptance/pre_suite/subcommands/05_install_ruby.rb +2 -3
  22. data/acceptance/pre_suite/subcommands/08_install_beaker.rb +1 -2
  23. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +4 -4
  24. data/acceptance/tests/base/dsl/helpers/hocon_helpers_test.rb +7 -8
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +0 -3
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/archive_file_from_test.rb +9 -7
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +15 -21
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +0 -4
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +23 -30
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +3 -3
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +0 -1
  32. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +21 -16
  33. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +7 -7
  34. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +30 -38
  35. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +14 -18
  36. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +8 -14
  37. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +7 -11
  38. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +5 -5
  39. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +4 -5
  40. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +8 -8
  41. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +4 -6
  42. data/acceptance/tests/base/dsl/platform_tag_confiner_test.rb +14 -17
  43. data/acceptance/tests/base/dsl/structure_test.rb +9 -21
  44. data/acceptance/tests/base/host/file_test.rb +8 -8
  45. data/acceptance/tests/base/host/group_test.rb +2 -3
  46. data/acceptance/tests/base/host/host_test.rb +69 -66
  47. data/acceptance/tests/base/host/packages.rb +27 -30
  48. data/acceptance/tests/base/host/packages_unix.rb +0 -55
  49. data/acceptance/tests/base/host/user_test.rb +2 -3
  50. data/acceptance/tests/base/host_prebuilt_steps/ssh_environment_test.rb +1 -2
  51. data/acceptance/tests/base/test_suite/export.rb +6 -9
  52. data/acceptance/tests/install/from_file.rb +3 -5
  53. data/acceptance/tests/load_path_bootstrap.rb +1 -1
  54. data/acceptance/tests/subcommands/destroy.rb +19 -21
  55. data/acceptance/tests/subcommands/exec.rb +0 -1
  56. data/acceptance/tests/subcommands/init.rb +2 -3
  57. data/acceptance/tests/subcommands/provision.rb +0 -1
  58. data/beaker.gemspec +10 -14
  59. data/docs/concepts/argument_processing_and_precedence.md +1 -10
  60. data/docs/concepts/style_guide.md +1 -1
  61. data/docs/how_to/debug_beaker_tests.md +13 -13
  62. data/docs/how_to/hosts/eos.md +2 -12
  63. data/docs/how_to/install_puppet.md +0 -18
  64. data/docs/how_to/test_arbitrary_beaker_versions.md +2 -2
  65. data/docs/how_to/the_beaker_dsl.md +0 -2
  66. data/lib/beaker/cli.rb +63 -74
  67. data/lib/beaker/command.rb +22 -30
  68. data/lib/beaker/command_factory.rb +4 -3
  69. data/lib/beaker/dsl/assertions.rb +7 -19
  70. data/lib/beaker/dsl/helpers/hocon_helpers.rb +5 -9
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +72 -133
  72. data/lib/beaker/dsl/helpers/test_helpers.rb +3 -5
  73. data/lib/beaker/dsl/helpers/web_helpers.rb +20 -28
  74. data/lib/beaker/dsl/helpers.rb +2 -4
  75. data/lib/beaker/dsl/outcomes.rb +17 -19
  76. data/lib/beaker/dsl/patterns.rb +1 -3
  77. data/lib/beaker/dsl/roles.rb +18 -21
  78. data/lib/beaker/dsl/structure.rb +55 -67
  79. data/lib/beaker/dsl/test_tagging.rb +7 -10
  80. data/lib/beaker/dsl/wrappers.rb +15 -16
  81. data/lib/beaker/dsl.rb +2 -3
  82. data/lib/beaker/host/aix/exec.rb +1 -1
  83. data/lib/beaker/host/aix/file.rb +0 -1
  84. data/lib/beaker/host/aix/group.rb +3 -3
  85. data/lib/beaker/host/aix/user.rb +3 -3
  86. data/lib/beaker/host/aix.rb +3 -4
  87. data/lib/beaker/host/cisco.rb +36 -48
  88. data/lib/beaker/host/eos.rb +4 -30
  89. data/lib/beaker/host/freebsd/exec.rb +1 -1
  90. data/lib/beaker/host/freebsd/pkg.rb +3 -3
  91. data/lib/beaker/host/freebsd.rb +9 -12
  92. data/lib/beaker/host/mac/exec.rb +5 -5
  93. data/lib/beaker/host/mac/group.rb +13 -13
  94. data/lib/beaker/host/mac/pkg.rb +6 -109
  95. data/lib/beaker/host/mac/user.rb +7 -7
  96. data/lib/beaker/host/mac.rb +8 -9
  97. data/lib/beaker/host/pswindows/exec.rb +70 -74
  98. data/lib/beaker/host/pswindows/file.rb +4 -6
  99. data/lib/beaker/host/pswindows/group.rb +5 -5
  100. data/lib/beaker/host/pswindows/pkg.rb +17 -17
  101. data/lib/beaker/host/pswindows/user.rb +4 -4
  102. data/lib/beaker/host/pswindows.rb +4 -3
  103. data/lib/beaker/host/unix/exec.rb +86 -88
  104. data/lib/beaker/host/unix/file.rb +41 -47
  105. data/lib/beaker/host/unix/group.rb +3 -3
  106. data/lib/beaker/host/unix/pkg.rb +158 -421
  107. data/lib/beaker/host/unix/user.rb +4 -4
  108. data/lib/beaker/host/unix.rb +18 -20
  109. data/lib/beaker/host/windows/exec.rb +20 -20
  110. data/lib/beaker/host/windows/file.rb +5 -5
  111. data/lib/beaker/host/windows/group.rb +5 -5
  112. data/lib/beaker/host/windows/pkg.rb +6 -57
  113. data/lib/beaker/host/windows/user.rb +4 -4
  114. data/lib/beaker/host/windows.rb +13 -13
  115. data/lib/beaker/host.rb +82 -139
  116. data/lib/beaker/host_prebuilt_steps.rb +121 -233
  117. data/lib/beaker/hypervisor/noop.rb +2 -4
  118. data/lib/beaker/hypervisor.rb +46 -63
  119. data/lib/beaker/local_connection.rb +4 -6
  120. data/lib/beaker/logger.rb +71 -85
  121. data/lib/beaker/logger_junit.rb +22 -26
  122. data/lib/beaker/network_manager.rb +40 -43
  123. data/lib/beaker/options/command_line_parser.rb +12 -23
  124. data/lib/beaker/options/hosts_file_parser.rb +34 -25
  125. data/lib/beaker/options/options_file_parser.rb +3 -6
  126. data/lib/beaker/options/options_hash.rb +3 -10
  127. data/lib/beaker/options/parser.rb +89 -105
  128. data/lib/beaker/options/presets.rb +114 -123
  129. data/lib/beaker/options/subcommand_options_file_parser.rb +3 -6
  130. data/lib/beaker/options/validator.rb +26 -31
  131. data/lib/beaker/perf.rb +29 -34
  132. data/lib/beaker/platform.rb +38 -46
  133. data/lib/beaker/result.rb +7 -6
  134. data/lib/beaker/shared/error_handler.rb +8 -10
  135. data/lib/beaker/shared/fog_credentials.rb +5 -9
  136. data/lib/beaker/shared/host_manager.rb +40 -46
  137. data/lib/beaker/shared/options_resolver.rb +3 -7
  138. data/lib/beaker/shared/repetition.rb +6 -8
  139. data/lib/beaker/shared/semvar.rb +39 -43
  140. data/lib/beaker/shared/timed.rb +2 -5
  141. data/lib/beaker/shared.rb +1 -1
  142. data/lib/beaker/ssh_connection.rb +46 -55
  143. data/lib/beaker/subcommand.rb +23 -30
  144. data/lib/beaker/subcommands/subcommand_util.rb +4 -4
  145. data/lib/beaker/tasks/quick_start.rb +5 -10
  146. data/lib/beaker/tasks/rake_task.rb +26 -28
  147. data/lib/beaker/tasks/test.rb +4 -4
  148. data/lib/beaker/test_case.rb +15 -27
  149. data/lib/beaker/test_suite.rb +35 -39
  150. data/lib/beaker/test_suite_result.rb +52 -57
  151. data/lib/beaker/version.rb +1 -1
  152. data/lib/beaker.rb +5 -6
  153. data/spec/beaker/cli_spec.rb +135 -153
  154. data/spec/beaker/command_spec.rb +64 -58
  155. data/spec/beaker/dsl/assertions_spec.rb +38 -47
  156. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +114 -135
  157. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  158. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +30 -36
  159. data/spec/beaker/dsl/outcomes_spec.rb +15 -14
  160. data/spec/beaker/dsl/roles_spec.rb +170 -132
  161. data/spec/beaker/dsl/structure_spec.rb +181 -163
  162. data/spec/beaker/dsl/test_tagging_spec.rb +94 -95
  163. data/spec/beaker/dsl/wrappers_spec.rb +39 -40
  164. data/spec/beaker/host/aix_spec.rb +14 -14
  165. data/spec/beaker/host/cisco_spec.rb +92 -102
  166. data/spec/beaker/host/eos_spec.rb +15 -36
  167. data/spec/beaker/host/freebsd/exec_spec.rb +5 -8
  168. data/spec/beaker/host/freebsd/pkg_spec.rb +29 -29
  169. data/spec/beaker/host/mac/exec_spec.rb +4 -5
  170. data/spec/beaker/host/mac/group_spec.rb +47 -56
  171. data/spec/beaker/host/mac/user_spec.rb +53 -62
  172. data/spec/beaker/host/pswindows/exec_spec.rb +36 -35
  173. data/spec/beaker/host/pswindows/file_spec.rb +21 -18
  174. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  175. data/spec/beaker/host/pswindows_spec.rb +14 -14
  176. data/spec/beaker/host/unix/exec_spec.rb +87 -92
  177. data/spec/beaker/host/unix/file_spec.rb +76 -82
  178. data/spec/beaker/host/unix/pkg_spec.rb +165 -407
  179. data/spec/beaker/host/unix_spec.rb +11 -207
  180. data/spec/beaker/host/windows/exec_spec.rb +32 -34
  181. data/spec/beaker/host/windows/file_spec.rb +22 -23
  182. data/spec/beaker/host/windows/group_spec.rb +17 -19
  183. data/spec/beaker/host/windows/pkg_spec.rb +10 -13
  184. data/spec/beaker/host/windows/user_spec.rb +17 -23
  185. data/spec/beaker/host/windows_spec.rb +39 -39
  186. data/spec/beaker/host_prebuilt_steps_spec.rb +193 -341
  187. data/spec/beaker/host_spec.rb +241 -312
  188. data/spec/beaker/hypervisor/hypervisor_spec.rb +38 -63
  189. data/spec/beaker/localhost_connection_spec.rb +14 -13
  190. data/spec/beaker/logger_junit_spec.rb +22 -34
  191. data/spec/beaker/logger_spec.rb +174 -155
  192. data/spec/beaker/network_manager_spec.rb +27 -27
  193. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  194. data/spec/beaker/options/data/hosts_preserved.yml +395 -0
  195. data/spec/beaker/options/hosts_file_parser_spec.rb +36 -31
  196. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  197. data/spec/beaker/options/options_hash_spec.rb +7 -9
  198. data/spec/beaker/options/parser_spec.rb +187 -187
  199. data/spec/beaker/options/presets_spec.rb +8 -10
  200. data/spec/beaker/options/subcommand_options_parser_spec.rb +15 -15
  201. data/spec/beaker/options/validator_spec.rb +27 -28
  202. data/spec/beaker/perf_spec.rb +32 -34
  203. data/spec/beaker/platform_spec.rb +27 -37
  204. data/spec/beaker/shared/error_handler_spec.rb +8 -17
  205. data/spec/beaker/shared/fog_credentials_spec.rb +30 -30
  206. data/spec/beaker/shared/host_manager_spec.rb +55 -89
  207. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  208. data/spec/beaker/shared/repetition_spec.rb +24 -31
  209. data/spec/beaker/shared/semvar_spec.rb +21 -26
  210. data/spec/beaker/ssh_connection_spec.rb +85 -90
  211. data/spec/beaker/subcommand/subcommand_util_spec.rb +40 -37
  212. data/spec/beaker/subcommand_spec.rb +89 -89
  213. data/spec/beaker/test_case_spec.rb +33 -62
  214. data/spec/beaker/test_suite_spec.rb +153 -160
  215. data/spec/helpers.rb +48 -53
  216. data/spec/matchers.rb +9 -8
  217. data/spec/mocks.rb +6 -11
  218. data/spec/spec_helper.rb +0 -4
  219. metadata +60 -85
  220. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  221. data/acceptance/tests/base/external_resources_test.rb +0 -31
  222. data/spec/beaker/host/mac_spec.rb +0 -113
  223. data/spec/mock_fission.rb +0 -60
  224. data/spec/mock_vsphere.rb +0 -314
  225. data/spec/mock_vsphere_helper.rb +0 -183
@@ -9,91 +9,94 @@ end
9
9
  describe ClassMixedWithDSLStructure do
10
10
  include Beaker::DSL::Assertions
11
11
 
12
- let (:logger) { double }
13
- let (:metadata) { @metadata ||= {} }
12
+ let(:logger) { double }
13
+ let(:metadata) { @metadata ||= {} }
14
14
 
15
- before :each do
16
- allow( subject ).to receive(:metadata).and_return(metadata)
15
+ before do
16
+ allow(subject).to receive(:metadata).and_return(metadata)
17
17
  end
18
18
 
19
19
  describe '#step' do
20
20
  it 'requires a name' do
21
- expect { subject.step do; end }.to raise_error ArgumentError
21
+ expect { subject.step { ; } }.to raise_error ArgumentError
22
22
  end
23
23
 
24
24
  it 'notifies the logger' do
25
- allow( subject ).to receive( :set_current_step_name )
26
- expect( subject ).to receive( :logger ).and_return( logger )
27
- expect( logger ).to receive( :notify )
25
+ allow(subject).to receive(:set_current_step_name)
26
+ expect(subject).to receive(:logger).and_return(logger)
27
+ expect(logger).to receive(:notify)
28
28
  subject.step 'blah'
29
29
  end
30
30
 
31
31
  it 'yields if a block is given' do
32
- expect( subject ).to receive( :logger ).and_return( logger ).exactly(2).times
33
- allow( subject ).to receive( :set_current_step_name )
34
- allow( logger ).to receive(:with_indent) { |&block| block.call }
35
- expect( logger ).to receive( :notify )
36
- expect( subject ).to receive( :foo )
32
+ expect(subject).to receive(:logger).and_return(logger).twice
33
+ allow(subject).to receive(:set_current_step_name)
34
+ allow(logger).to receive(:with_indent).and_yield
35
+ expect(logger).to receive(:notify)
36
+ expect(subject).to receive(:foo)
37
37
  subject.step 'blah' do
38
38
  subject.foo
39
39
  end
40
40
  end
41
41
 
42
42
  it 'sets the metadata' do
43
- allow( subject ).to receive( :logger ).and_return( logger )
44
- allow( logger ).to receive( :notify )
43
+ allow(subject).to receive(:logger).and_return(logger)
44
+ allow(logger).to receive(:notify)
45
45
  step_name = 'pierceBrosnanTests'
46
46
  subject.step step_name
47
- expect( metadata[:step][:name] ).to be === step_name
47
+ expect(metadata[:step][:name]).to be === step_name
48
48
  end
49
49
  end
50
50
 
51
51
  describe '#manual_step' do
52
52
  context 'without exec manual test option' do
53
- let( :options ) { {} }
53
+ let(:options) { {} }
54
+
54
55
  it 'throws an error' do
55
- expect( Readline ).not_to receive( :readline )
56
+ expect(Readline).not_to receive(:readline)
56
57
  expect { subject.manual_step 'blah' do; end }.to raise_error StandardError
57
58
  end
58
59
  end
59
60
 
60
61
  context 'with exec manual test option' do
61
- let( :options ) { {exec_manual_tests: nil} }
62
+ let(:options) { { exec_manual_tests: nil } }
63
+
62
64
  it 'requires a name' do
63
- expect { subject.manual_step do; end }.to raise_error ArgumentError
65
+ expect { subject.manual_step { ; } }.to raise_error ArgumentError
64
66
  end
65
67
 
66
68
  it 'notifies the logger' do
67
69
  subject.instance_variable_set(:@options, options)
68
- allow( subject ).to receive( :set_current_step_name )
69
- expect( subject ).to receive( :logger ).and_return( logger )
70
- expect( logger ).to receive( :notify )
71
- allow( Readline ).to receive( :readline ).and_return( 'Y')
70
+ allow(subject).to receive(:set_current_step_name)
71
+ expect(subject).to receive(:logger).and_return(logger)
72
+ expect(logger).to receive(:notify)
73
+ allow(Readline).to receive(:readline).and_return('Y')
72
74
  subject.manual_step 'blah'
73
75
  end
74
76
  end
75
77
 
76
78
  context 'with exec manual test option set to true' do
77
- let( :options ) { {exec_manual_tests: true} }
79
+ let(:options) { { exec_manual_tests: true } }
80
+
78
81
  it 'requires a name' do
79
- expect { subject.manual_step do; end }.to raise_error ArgumentError
82
+ expect { subject.manual_step { ; } }.to raise_error ArgumentError
80
83
  end
81
84
 
82
85
  it 'pass when user enters Y' do
83
86
  subject.instance_variable_set(:@options, options)
84
- allow( subject ).to receive( :set_current_step_name )
85
- allow( subject ).to receive( :logger ).and_return( logger )
86
- allow( logger ).to receive( :notify )
87
- expect( Readline ).to receive( :readline ).and_return( 'Y')
87
+ allow(subject).to receive(:set_current_step_name)
88
+ allow(subject).to receive(:logger).and_return(logger)
89
+ allow(logger).to receive(:notify)
90
+ expect(Readline).to receive(:readline).and_return('Y')
88
91
  subject.manual_step 'blahblah'
89
92
  end
90
93
 
91
94
  it 'fails when user enters n and uses default error when no message is entered' do
92
95
  subject.instance_variable_set(:@options, options)
93
- allow( subject ).to receive( :set_current_step_name )
94
- allow( subject ).to receive( :logger ).and_return( logger )
95
- allow( logger ).to receive( :notify )
96
- expect( Readline ).to receive( :readline ).and_return('n', 'step failed')
96
+ allow(subject).to receive(:set_current_step_name)
97
+ allow(subject).to receive(:logger).and_return(logger)
98
+ allow(logger).to receive(:notify)
99
+ expect(Readline).to receive(:readline).and_return('n', 'step failed')
97
100
  expect { subject.manual_step 'blah two' do; end }.to raise_error(Beaker::DSL::FailTest, 'step failed')
98
101
  end
99
102
  end
@@ -101,39 +104,41 @@ describe ClassMixedWithDSLStructure do
101
104
 
102
105
  describe '#manual_test' do
103
106
  context 'without exec manual test option' do
104
- let( :options ) { {} }
107
+ let(:options) { {} }
108
+
105
109
  it 'requires a name' do
106
- expect { subject.manual_test do; end }.to raise_error ArgumentError
110
+ expect { subject.manual_test { ; } }.to raise_error ArgumentError
107
111
  end
108
112
 
109
113
  it 'raises a skip test' do
110
114
  subject.instance_variable_set(:@options, options)
111
- allow( subject ).to receive( :logger ).and_return( logger )
112
- allow( logger ).to receive( :notify )
115
+ allow(subject).to receive(:logger).and_return(logger)
116
+ allow(logger).to receive(:notify)
113
117
  test_name = 'random test name'
114
118
  expect { subject.manual_test test_name do; end }.to raise_error Beaker::DSL::SkipTest
115
119
  end
116
120
  end
117
121
 
118
122
  context 'with exec manual test option' do
119
- let( :options ) { {exec_manual_tests: true} }
123
+ let(:options) { { exec_manual_tests: true } }
124
+
120
125
  it 'requires a name' do
121
- expect { subject.manual_test do; end }.to raise_error ArgumentError
126
+ expect { subject.manual_test { ; } }.to raise_error ArgumentError
122
127
  end
123
128
 
124
129
  it 'notifies the logger' do
125
130
  subject.instance_variable_set(:@options, options)
126
- expect( subject ).to receive( :logger ).and_return( logger )
127
- expect( logger ).to receive( :notify )
131
+ expect(subject).to receive(:logger).and_return(logger)
132
+ expect(logger).to receive(:notify)
128
133
  subject.manual_test 'blah blah'
129
134
  end
130
135
 
131
136
  it 'yields if a block is given' do
132
137
  subject.instance_variable_set(:@options, options)
133
- expect( subject ).to receive( :logger ).and_return( logger ).exactly(2).times
134
- expect( logger ).to receive( :notify )
135
- allow( logger ).to receive(:with_indent) { |&block| block.call }
136
- expect( subject ).to receive( :foo )
138
+ expect(subject).to receive(:logger).and_return(logger).twice
139
+ expect(logger).to receive(:notify)
140
+ allow(logger).to receive(:with_indent).and_yield
141
+ expect(subject).to receive(:foo)
137
142
  subject.manual_test 'blah' do
138
143
  subject.foo
139
144
  end
@@ -141,43 +146,42 @@ describe ClassMixedWithDSLStructure do
141
146
 
142
147
  it 'sets the metadata' do
143
148
  subject.instance_variable_set(:@options, options)
144
- allow( subject ).to receive( :logger ).and_return( logger )
145
- allow( logger ).to receive( :notify )
149
+ allow(subject).to receive(:logger).and_return(logger)
150
+ allow(logger).to receive(:notify)
146
151
  test_name = 'test is setting metadata yay!'
147
152
  subject.manual_test test_name
148
- expect( metadata[:case][:name] ).to be === test_name
153
+ expect(metadata[:case][:name]).to be === test_name
149
154
  end
150
155
  end
151
156
  end
152
157
 
153
158
  describe '#test_name' do
154
-
155
159
  it 'requires a name' do
156
- expect { subject.test_name do; end }.to raise_error ArgumentError
160
+ expect { subject.test_name { ; } }.to raise_error ArgumentError
157
161
  end
158
162
 
159
163
  it 'notifies the logger' do
160
- expect( subject ).to receive( :logger ).and_return( logger )
161
- expect( logger ).to receive( :notify )
164
+ expect(subject).to receive(:logger).and_return(logger)
165
+ expect(logger).to receive(:notify)
162
166
  subject.test_name 'blah'
163
167
  end
164
168
 
165
169
  it 'yields if a block is given' do
166
- expect( subject ).to receive( :logger ).and_return( logger ).exactly(2).times
167
- expect( logger ).to receive( :notify )
168
- allow( logger ).to receive(:with_indent) { |&block| block.call }
169
- expect( subject ).to receive( :foo )
170
+ expect(subject).to receive(:logger).and_return(logger).twice
171
+ expect(logger).to receive(:notify)
172
+ allow(logger).to receive(:with_indent).and_yield
173
+ expect(subject).to receive(:foo)
170
174
  subject.test_name 'blah' do
171
175
  subject.foo
172
176
  end
173
177
  end
174
178
 
175
179
  it 'sets the metadata' do
176
- allow( subject ).to receive( :logger ).and_return( logger )
177
- allow( logger ).to receive( :notify )
180
+ allow(subject).to receive(:logger).and_return(logger)
181
+ allow(logger).to receive(:notify)
178
182
  test_name = '15-05-08\'s weather is beautiful'
179
183
  subject.test_name test_name
180
- expect( metadata[:case][:name] ).to be === test_name
184
+ expect(metadata[:case][:name]).to be === test_name
181
185
  end
182
186
  end
183
187
 
@@ -185,200 +189,214 @@ describe ClassMixedWithDSLStructure do
185
189
  it 'append a block to the @teardown var' do
186
190
  teardown_array = double
187
191
  subject.instance_variable_set :@teardown_procs, teardown_array
188
- block = lambda { 'blah' }
189
- expect( teardown_array ).to receive( :<< ).with( block )
190
- subject.teardown &block
192
+ block = -> { 'blah' }
193
+ expect(teardown_array).to receive(:<<).with(block)
194
+ subject.teardown(&block)
191
195
  end
192
196
  end
193
197
 
194
198
  describe '#expect_failure' do
195
199
  it 'passes when a MiniTest assertion is raised' do
196
- expect( subject ).to receive( :logger ).and_return( logger )
197
- expect( logger ).to receive( :notify )
200
+ expect(subject).to receive(:logger).and_return(logger)
201
+ expect(logger).to receive(:notify)
198
202
  # We changed this lambda to use the simplest assert possible; using assert_equal
199
203
  # caused an error in minitest 5.9.0 trying to write to the file system.
200
- block = lambda { assert(false, 'this assertion should be caught') }
201
- expect{ subject.expect_failure 'this is an expected failure', &block }.to_not raise_error
204
+ block = -> { assert(false, 'this assertion should be caught') }
205
+ expect { subject.expect_failure 'this is an expected failure', &block }.not_to raise_error
202
206
  end
203
207
 
204
208
  it 'passes when a Beaker assertion is raised' do
205
- expect( subject ).to receive( :logger ).and_return( logger )
206
- expect( logger ).to receive( :notify )
207
- block = lambda { assert_no_match('1', '1', '1 and 1 should not match') }
208
- expect{ subject.expect_failure 'this is an expected failure', &block }.to_not raise_error
209
+ expect(subject).to receive(:logger).and_return(logger)
210
+ expect(logger).to receive(:notify)
211
+ block = -> { refute_match('1', '1', '1 and 1 should not match') }
212
+ expect { subject.expect_failure 'this is an expected failure', &block }.not_to raise_error
209
213
  end
210
214
 
211
215
  it 'fails when a non-Beaker, non-MiniTest assertion is raised' do
212
- block = lambda { raise 'not a Beaker or MiniTest error' }
213
- expect{ subject.expect_failure 'this has a non-Beaker, non-MiniTest exception', &block }.to raise_error(RuntimeError, /not a Beaker or MiniTest error/)
216
+ block = -> { raise 'not a Beaker or MiniTest error' }
217
+ expect { subject.expect_failure 'this has a non-Beaker, non-MiniTest exception', &block }.to raise_error(RuntimeError, /not a Beaker or MiniTest error/)
214
218
  end
215
219
 
216
220
  it 'fails when no assertion is raised' do
217
- block = lambda { assert_equal('1', '1', '1 should equal 1') }
218
- expect{ subject.expect_failure 'this has no failure', &block }.to raise_error(RuntimeError, /An assertion was expected to fail, but passed/)
221
+ block = -> { expect('1').to(eq('1'), '1 should equal 1') }
222
+ expect { subject.expect_failure 'this has no failure', &block }.to raise_error(RuntimeError, /An assertion was expected to fail, but passed/)
219
223
  end
220
224
  end
221
225
 
222
- describe 'confine' do
226
+ describe '#confine' do
223
227
  let(:logger) { double.as_null_object }
228
+
224
229
  before do
225
- allow( subject ).to receive( :logger ).and_return( logger )
230
+ allow(subject).to receive(:logger).and_return(logger)
226
231
  end
227
232
 
228
233
  it ':to - skips the test if there are no applicable hosts' do
229
- allow( subject ).to receive( :hosts ).and_return( [] )
230
- allow( subject ).to receive( :hosts= )
231
- expect( logger ).to receive( :warn )
232
- expect( subject ).to receive( :skip_test ).with( 'No suitable hosts found with {}' )
233
- subject.confine( :to, {} )
234
+ allow(subject).to receive(:hosts).and_return([])
235
+ allow(subject).to receive(:hosts=)
236
+ expect(logger).to receive(:warn)
237
+ expect(subject).to receive(:skip_test).with('No suitable hosts found with {}')
238
+ subject.confine(:to, {})
234
239
  end
235
240
 
236
241
  it ':except - skips the test if there are no applicable hosts' do
237
- allow( subject ).to receive( :hosts ).and_return( [] )
238
- allow( subject ).to receive( :hosts= )
239
- expect( logger ).to receive( :warn )
240
- expect( subject ).to receive( :skip_test ).with( 'No suitable hosts found without {}' )
241
- subject.confine( :except, {} )
242
+ allow(subject).to receive(:hosts).and_return([])
243
+ allow(subject).to receive(:hosts=)
244
+ expect(logger).to receive(:warn)
245
+ expect(subject).to receive(:skip_test).with('No suitable hosts found without {}')
246
+ subject.confine(:except, {})
242
247
  end
243
248
 
244
249
  it ':to - uses a provided host subset when no criteria is provided' do
245
- subset = ['host1', 'host2']
250
+ subset = %w[host1 host2]
246
251
  hosts = subset.dup << 'host3'
247
- allow( subject ).to receive( :hosts ).and_return(hosts).twice
248
- expect( subject ).to receive( :hosts= ).with( subset )
252
+ allow(subject).to receive(:hosts).and_return(hosts).twice
253
+ expect(subject).to receive(:hosts=).with(subset)
249
254
  subject.confine :to, {}, subset
250
255
  end
251
256
 
252
257
  it ':except - excludes provided host subset when no criteria is provided' do
253
- subset = ['host1', 'host2']
258
+ subset = %w[host1 host2]
254
259
  hosts = subset.dup << 'host3'
255
- allow( subject ).to receive( :hosts ).and_return(hosts).twice
256
- expect( subject ).to receive( :hosts= ).with( hosts - subset )
260
+ allow(subject).to receive(:hosts).and_return(hosts).twice
261
+ expect(subject).to receive(:hosts=).with(hosts - subset)
257
262
  subject.confine :except, {}, subset
258
263
  end
259
264
 
260
265
  it 'raises when given mode is not :to or :except' do
261
- hosts = ['host1', 'host2']
262
- allow( subject ).to receive( :hosts ).and_return(hosts)
263
- allow( subject ).to receive( :hosts= )
266
+ hosts = %w[host1 host2]
267
+ allow(subject).to receive(:hosts).and_return(hosts)
268
+ allow(subject).to receive(:hosts=)
264
269
 
265
- expect {
266
- subject.confine( :regardless, {:thing => 'value'} )
267
- }.to raise_error( 'Unknown option regardless' )
270
+ expect do
271
+ subject.confine(:regardless, { :thing => 'value' })
272
+ end.to raise_error('Unknown option regardless')
268
273
  end
269
274
 
270
275
  it 'rejects hosts that do not meet simple hash criteria' do
271
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'} ]
276
+ hosts = [{ 'thing' => 'foo' }, { 'thing' => 'bar' }]
272
277
 
273
- expect( subject ).to receive( :hosts ).and_return( hosts ).twice
274
- expect( subject ).to receive( :hosts= ).
275
- with( [ {'thing' => 'foo'} ] )
278
+ expect(subject).to receive(:hosts).and_return(hosts).twice
279
+ expect(subject).to receive(:hosts=)
280
+ .with([{ 'thing' => 'foo' }])
276
281
 
277
282
  subject.confine :to, :thing => 'foo'
278
283
  end
279
284
 
280
285
  it 'rejects hosts that match a list of criteria' do
281
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'}, {'thing' => 'baz'} ]
286
+ hosts = [{ 'thing' => 'foo' }, { 'thing' => 'bar' }, { 'thing' => 'baz' }]
282
287
 
283
- expect( subject ).to receive( :hosts ).and_return( hosts ).twice
284
- expect( subject ).to receive( :hosts= ).
285
- with( [ {'thing' => 'bar'} ] )
288
+ expect(subject).to receive(:hosts).and_return(hosts).twice
289
+ expect(subject).to receive(:hosts=)
290
+ .with([{ 'thing' => 'bar' }])
286
291
 
287
- subject.confine :except, :thing => ['foo', 'baz']
292
+ subject.confine :except, :thing => %w[foo baz]
288
293
  end
289
294
 
290
295
  it 'rejects hosts when a passed block returns true' do
291
- host1 = {'platform' => 'solaris'}
292
- host2 = {'platform' => 'solaris'}
293
- host3 = {'platform' => 'windows'}
296
+ host1 = { 'platform' => 'solaris' }
297
+ host2 = { 'platform' => 'solaris' }
298
+ host3 = { 'platform' => 'windows' }
294
299
  ret1 = (Struct.new('Result1', :stdout)).new(':global')
295
300
  ret2 = (Struct.new('Result2', :stdout)).new('a_zone')
296
- hosts = [ host1, host2, host3 ]
301
+ hosts = [host1, host2, host3]
297
302
 
298
- expect( subject ).to receive( :hosts ).and_return( hosts ).twice
299
- expect( subject ).to receive( :on ).
300
- with( host1, '/sbin/zonename' ).
301
- and_return( ret1 )
302
- expect( subject ).to receive( :on ).
303
- with( host1, '/sbin/zonename' ).
304
- and_return( ret2 )
303
+ expect(subject).to receive(:hosts).and_return(hosts).twice
304
+ expect(subject).to receive(:on)
305
+ .with(host1, '/sbin/zonename')
306
+ .and_return(ret1)
307
+ expect(subject).to receive(:on)
308
+ .with(host1, '/sbin/zonename')
309
+ .and_return(ret2)
305
310
 
306
- expect( subject ).to receive( :hosts= ).with( [ host1 ] )
311
+ expect(subject).to receive(:hosts=).with([host1])
307
312
 
308
313
  subject.confine :to, :platform => 'solaris' do |host|
309
- subject.on( host, '/sbin/zonename' ).stdout =~ /:global/
314
+ subject.on(host, '/sbin/zonename').stdout.include?(':global')
310
315
  end
311
316
  end
312
317
 
313
318
  it 'doesn\'t corrupt the global hosts hash when confining from a subset of hosts' do
314
- host1 = {'platform' => 'solaris', :roles => ['master']}
315
- host2 = {'platform' => 'solaris', :roles => ['agent']}
316
- host3 = {'platform' => 'windows', :roles => ['agent']}
317
- hosts = [ host1, host2, host3 ]
318
- agents = [ host2, host3 ]
319
+ host1 = { 'platform' => 'solaris', :roles => ['master'] }
320
+ host2 = { 'platform' => 'solaris', :roles => ['agent'] }
321
+ host3 = { 'platform' => 'windows', :roles => ['agent'] }
322
+ hosts = [host1, host2, host3]
323
+ agents = [host2, host3]
319
324
 
320
- expect( subject ).to receive( :hosts ).and_return( hosts )
321
- expect( subject ).to receive( :hosts= ).with( [ host2, host1 ] )
322
- confined_hosts = subject.confine :except, {:platform => 'windows'}, agents
323
- expect( confined_hosts ).to be === [ host2, host1 ]
325
+ expect(subject).to receive(:hosts).and_return(hosts)
326
+ expect(subject).to receive(:hosts=).with([host2, host1])
327
+ confined_hosts = subject.confine :except, { :platform => 'windows' }, agents
328
+ expect(confined_hosts).to be === [host2, host1]
324
329
  end
325
330
 
326
331
  it 'can apply multiple confines correctly' do
327
- host1 = {'platform' => 'solaris', :roles => ['master']}
328
- host2 = {'platform' => 'solaris', :roles => ['agent']}
329
- host3 = {'platform' => 'windows', :roles => ['agent']}
330
- host4 = {'platform' => 'fedora', :roles => ['agent']}
331
- host5 = {'platform' => 'fedora', :roles => ['agent']}
332
- hosts = [ host1, host2, host3, host4, host5 ]
333
- agents = [ host2, host3, host4, host5 ]
334
-
335
- expect( subject ).to receive( :hosts ).and_return( hosts ).exactly(3).times
336
- expect( subject ).to receive( :hosts= ).with( [ host1, host2, host4, host5 ] )
337
- hosts = subject.confine :except, {:platform => 'windows'}
338
- expect( hosts ).to be === [ host1, host2, host4, host5 ]
339
- expect( subject ).to receive( :hosts= ).with( [ host4, host5, host1 ] )
340
- hosts = subject.confine :to, {:platform => 'fedora'}, agents
341
- expect( hosts ).to be === [ host4, host5, host1 ]
332
+ host1 = { 'platform' => 'solaris', :roles => ['master'] }
333
+ host2 = { 'platform' => 'solaris', :roles => ['agent'] }
334
+ host3 = { 'platform' => 'windows', :roles => ['agent'] }
335
+ host4 = { 'platform' => 'fedora', :roles => ['agent'] }
336
+ host5 = { 'platform' => 'fedora', :roles => ['agent'] }
337
+ hosts = [host1, host2, host3, host4, host5]
338
+ agents = [host2, host3, host4, host5]
339
+
340
+ expect(subject).to receive(:hosts).and_return(hosts).exactly(3).times
341
+ expect(subject).to receive(:hosts=).with([host1, host2, host4, host5])
342
+ hosts = subject.confine :except, { :platform => 'windows' }
343
+ expect(hosts).to be === [host1, host2, host4, host5]
344
+ expect(subject).to receive(:hosts=).with([host4, host5, host1])
345
+ hosts = subject.confine :to, { :platform => 'fedora' }, agents
346
+ expect(hosts).to be === [host4, host5, host1]
347
+ end
348
+
349
+ it 'can apply confine with multiple arguments' do
350
+ host1 = { 'platform' => 'solaris', 'hypervisor' => 'vmpooler' }
351
+ host2 = { 'platform' => 'windows', 'hypervisor' => 'vmpooler' }
352
+ host3 = { 'platform' => 'fedora', 'hypervisor' => 'vmpooler' }
353
+ host4 = { 'platform' => 'fedora', 'hypervisor' => 'docker' }
354
+ hosts = [host1, host2, host3, host4]
355
+
356
+ expect(subject).to receive(:hosts).and_return(hosts).twice
357
+ expect(subject).to receive(:hosts=).with([host1, host2, host3])
358
+ result = subject.confine :except, { :platform => 'fedora', :hypervisor => 'docker' }
359
+ expect(result).to eq([host1, host2, host3])
342
360
  end
343
361
  end
344
362
 
345
363
  describe '#select_hosts' do
346
364
  let(:logger) { double.as_null_object }
365
+
347
366
  before do
348
- allow( subject ).to receive( :logger ).and_return( logger )
367
+ allow(subject).to receive(:logger).and_return(logger)
349
368
  end
350
369
 
351
- it 'it returns an empty array if there are no applicable hosts' do
352
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'} ]
370
+ it 'returns an empty array if there are no applicable hosts' do
371
+ hosts = [{ 'thing' => 'foo' }, { 'thing' => 'bar' }]
353
372
 
354
- expect(subject.select_hosts( {'thing' => 'nope'}, hosts )).to be == []
373
+ expect(subject.select_hosts({ 'thing' => 'nope' }, hosts)).to be == []
355
374
  end
356
375
 
357
376
  it 'selects hosts that match a list of criteria' do
358
- hosts = [ {'thing' => 'foo'}, {'thing' => 'bar'}, {'thing' => 'baz'} ]
377
+ hosts = [{ 'thing' => 'foo' }, { 'thing' => 'bar' }, { 'thing' => 'baz' }]
359
378
 
360
- expect(subject.select_hosts( {:thing => ['foo', 'baz']}, hosts )).to be == [ {'thing' => 'foo'}, {'thing' => 'baz'} ]
379
+ expect(subject.select_hosts({ :thing => %w[foo baz] }, hosts)).to be == [{ 'thing' => 'foo' }, { 'thing' => 'baz' }]
361
380
  end
362
381
 
363
382
  it 'selects hosts when a passed block returns true' do
364
- host1 = {'platform' => 'solaris1'}
365
- host2 = {'platform' => 'solaris2'}
366
- host3 = {'platform' => 'windows'}
383
+ host1 = { 'platform' => 'solaris1' }
384
+ host2 = { 'platform' => 'solaris2' }
385
+ host3 = { 'platform' => 'windows' }
367
386
  ret1 = double('result1')
368
- allow( ret1 ).to receive( :stdout ).and_return(':global')
387
+ allow(ret1).to receive(:stdout).and_return(':global')
369
388
  ret2 = double('result2')
370
- allow( ret2 ).to receive( :stdout ).and_return('a_zone')
371
- hosts = [ host1, host2, host3 ]
372
- expect( subject ).to receive( :hosts ).and_return( hosts )
389
+ allow(ret2).to receive(:stdout).and_return('a_zone')
390
+ hosts = [host1, host2, host3]
391
+ expect(subject).to receive(:hosts).and_return(hosts)
373
392
 
374
- expect( subject ).to receive( :on ).with( host1, '/sbin/zonename' ).once.and_return( ret1 )
375
- expect( subject ).to receive( :on ).with( host2, '/sbin/zonename' ).once.and_return( ret2 )
393
+ expect(subject).to receive(:on).with(host1, '/sbin/zonename').once.and_return(ret1)
394
+ expect(subject).to receive(:on).with(host2, '/sbin/zonename').once.and_return(ret2)
376
395
 
377
396
  selected_hosts = subject.select_hosts 'platform' => 'solaris' do |host|
378
- subject.on(host, '/sbin/zonename').stdout =~ /:global/
397
+ subject.on(host, '/sbin/zonename').stdout.include?(':global')
379
398
  end
380
- expect( selected_hosts ).to be == [ host1 ]
399
+ expect(selected_hosts).to be == [host1]
381
400
  end
382
401
  end
383
-
384
402
  end