beaker 4.40.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) 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 +23 -10
  6. data/.rubocop_todo.yml +34 -10
  7. data/CHANGELOG.md +17 -28
  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 +6 -5
  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 -7
  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 -39
  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 +16 -28
  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 +6 -7
  149. data/spec/beaker/cli_spec.rb +121 -142
  150. data/spec/beaker/command_spec.rb +55 -59
  151. data/spec/beaker/dsl/assertions_spec.rb +36 -36
  152. data/spec/beaker/dsl/helpers/host_helpers_spec.rb +110 -131
  153. data/spec/beaker/dsl/helpers/test_helpers_spec.rb +9 -10
  154. data/spec/beaker/dsl/helpers/web_helpers_spec.rb +22 -31
  155. data/spec/beaker/dsl/outcomes_spec.rb +14 -14
  156. data/spec/beaker/dsl/roles_spec.rb +125 -130
  157. data/spec/beaker/dsl/structure_spec.rb +172 -161
  158. data/spec/beaker/dsl/test_tagging_spec.rb +89 -90
  159. data/spec/beaker/dsl/wrappers_spec.rb +32 -33
  160. data/spec/beaker/host/aix_spec.rb +14 -14
  161. data/spec/beaker/host/cisco_spec.rb +84 -94
  162. data/spec/beaker/host/eos_spec.rb +15 -36
  163. data/spec/beaker/host/freebsd/exec_spec.rb +3 -6
  164. data/spec/beaker/host/freebsd/pkg_spec.rb +24 -27
  165. data/spec/beaker/host/mac/exec_spec.rb +2 -3
  166. data/spec/beaker/host/mac/group_spec.rb +48 -57
  167. data/spec/beaker/host/mac/user_spec.rb +54 -63
  168. data/spec/beaker/host/pswindows/exec_spec.rb +30 -32
  169. data/spec/beaker/host/pswindows/file_spec.rb +16 -16
  170. data/spec/beaker/host/pswindows/user_spec.rb +17 -23
  171. data/spec/beaker/host/pswindows_spec.rb +13 -13
  172. data/spec/beaker/host/unix/exec_spec.rb +75 -80
  173. data/spec/beaker/host/unix/file_spec.rb +66 -73
  174. data/spec/beaker/host/unix/pkg_spec.rb +155 -401
  175. data/spec/beaker/host/unix_spec.rb +11 -207
  176. data/spec/beaker/host/windows/exec_spec.rb +30 -32
  177. data/spec/beaker/host/windows/file_spec.rb +18 -19
  178. data/spec/beaker/host/windows/group_spec.rb +10 -12
  179. data/spec/beaker/host/windows/pkg_spec.rb +6 -9
  180. data/spec/beaker/host/windows/user_spec.rb +17 -23
  181. data/spec/beaker/host/windows_spec.rb +39 -39
  182. data/spec/beaker/host_prebuilt_steps_spec.rb +172 -326
  183. data/spec/beaker/host_spec.rb +204 -284
  184. data/spec/beaker/hypervisor/hypervisor_spec.rb +36 -61
  185. data/spec/beaker/localhost_connection_spec.rb +10 -11
  186. data/spec/beaker/logger_junit_spec.rb +19 -30
  187. data/spec/beaker/logger_spec.rb +153 -136
  188. data/spec/beaker/network_manager_spec.rb +23 -23
  189. data/spec/beaker/options/command_line_parser_spec.rb +20 -23
  190. data/spec/beaker/options/hosts_file_parser_spec.rb +30 -32
  191. data/spec/beaker/options/options_file_parser_spec.rb +4 -7
  192. data/spec/beaker/options/options_hash_spec.rb +4 -6
  193. data/spec/beaker/options/parser_spec.rb +167 -167
  194. data/spec/beaker/options/presets_spec.rb +7 -9
  195. data/spec/beaker/options/subcommand_options_parser_spec.rb +13 -14
  196. data/spec/beaker/options/validator_spec.rb +10 -11
  197. data/spec/beaker/perf_spec.rb +18 -21
  198. data/spec/beaker/platform_spec.rb +25 -36
  199. data/spec/beaker/shared/error_handler_spec.rb +7 -16
  200. data/spec/beaker/shared/fog_credentials_spec.rb +29 -29
  201. data/spec/beaker/shared/host_manager_spec.rb +50 -84
  202. data/spec/beaker/shared/options_resolver_spec.rb +9 -12
  203. data/spec/beaker/shared/repetition_spec.rb +17 -24
  204. data/spec/beaker/shared/semvar_spec.rb +21 -26
  205. data/spec/beaker/ssh_connection_spec.rb +76 -83
  206. data/spec/beaker/subcommand/subcommand_util_spec.rb +31 -33
  207. data/spec/beaker/subcommand_spec.rb +75 -77
  208. data/spec/beaker/test_case_spec.rb +25 -50
  209. data/spec/beaker/test_suite_spec.rb +147 -154
  210. data/spec/helpers.rb +48 -53
  211. data/spec/matchers.rb +8 -7
  212. data/spec/mocks.rb +1 -6
  213. data/spec/spec_helper.rb +0 -1
  214. metadata +7 -24
  215. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +0 -142
  216. data/acceptance/tests/base/external_resources_test.rb +0 -31
  217. data/spec/beaker/host/mac_spec.rb +0 -113
@@ -3,21 +3,20 @@ require 'fileutils'
3
3
 
4
4
  module Beaker
5
5
  describe TestSuite do
6
-
7
6
  context 'new' do
8
7
  let(:test_dir) { 'tmp/tests' }
9
8
 
10
- let(:options) { {'name' => create_files(@files)} }
9
+ let(:options) { { 'name' => create_files(@files) } }
11
10
  let(:rb_test) { File.expand_path(test_dir + '/my_ruby_file.rb') }
12
11
  let(:pl_test) { File.expand_path(test_dir + '/my_perl_file.pl') }
13
12
  let(:sh_test) { File.expand_path(test_dir + '/my_shell_file.sh') }
14
13
 
15
14
  it 'fails without test files' do
16
- expect { described_class.new('name', 'hosts', Hash.new, Time.now, :stop_on_error) }.to raise_error
15
+ expect { described_class.new('name', 'hosts', {}, Time.now, :stop_on_error) }.to raise_error
17
16
  end
18
17
 
19
18
  it 'includes specific files as test file when explicitly passed' do
20
- @files = [ rb_test ]
19
+ @files = [rb_test]
21
20
  ts = described_class.new('name', 'hosts', options, Time.now, :stop_on_error)
22
21
 
23
22
  tfs = ts.instance_variable_get(:@test_files)
@@ -25,21 +24,21 @@ module Beaker
25
24
  end
26
25
 
27
26
  it 'defaults to :slow fail_mode if not provided through parameter or options' do
28
- @files = [ rb_test ]
27
+ @files = [rb_test]
29
28
  ts = described_class.new('name', 'hosts', options, Time.now)
30
29
  tfm = ts.instance_variable_get(:@fail_mode)
31
30
  expect(tfm).to be == :slow
32
31
  end
33
32
 
34
33
  it 'uses provided parameter fail_mode' do
35
- @files = [ rb_test ]
34
+ @files = [rb_test]
36
35
  ts = described_class.new('name', 'hosts', options, Time.now, :fast)
37
36
  tfm = ts.instance_variable_get(:@fail_mode)
38
37
  expect(tfm).to be == :fast
39
38
  end
40
39
 
41
40
  it 'uses options fail_mode if fail_mode parameter is not provided' do
42
- @files = [ rb_test ]
41
+ @files = [rb_test]
43
42
  options[:fail_mode] = :fast
44
43
  ts = described_class.new('name', 'hosts', options, Time.now)
45
44
  tfm = ts.instance_variable_get(:@fail_mode)
@@ -48,252 +47,249 @@ module Beaker
48
47
  end
49
48
 
50
49
  context 'run' do
51
-
52
- let( :options ) { make_opts.merge({ :logger => double().as_null_object, 'name' => create_files(@files), :log_dated_dir => '.', :xml_dated_dir => '.'}) }
50
+ let(:options) { make_opts.merge({ :logger => double.as_null_object, 'name' => create_files(@files), :log_dated_dir => '.', :xml_dated_dir => '.' }) }
53
51
  let(:broken_script) { "raise RuntimeError" }
54
52
  let(:fail_script) { "raise Beaker::DSL::Outcomes::FailTest" }
55
53
  let(:okay_script) { "true" }
56
54
  let(:rb_test) { 'my_ruby_file.rb' }
57
55
  let(:pl_test) { '/my_perl_file.pl' }
58
56
  let(:sh_test) { '/my_shell_file.sh' }
59
- let(:hosts) { make_hosts() }
57
+ let(:hosts) { make_hosts }
60
58
 
61
59
  it 'fails fast if fail_mode != :slow and runtime error is raised' do
62
- allow( Logger ).to receive('new')
63
- @files = [ rb_test, pl_test, sh_test]
64
- File.open(rb_test, 'w') { |file| file.write(broken_script) }
65
- File.open(pl_test, 'w') { |file| file.write(okay_script) }
66
- File.open(sh_test, 'w') { |file| file.write(okay_script) }
60
+ allow(Logger).to receive('new')
61
+ @files = [rb_test, pl_test, sh_test]
62
+ File.write(rb_test, broken_script)
63
+ File.write(pl_test, okay_script)
64
+ File.write(sh_test, okay_script)
67
65
 
68
- ts = described_class.new( 'name', hosts, options, Time.now, :stop )
69
- tsr = ts.instance_variable_get( :@test_suite_results )
70
- allow( tsr ).to receive(:write_junit_xml).and_return( true )
71
- allow( tsr ).to receive(:summarize).and_return( true )
66
+ ts = described_class.new('name', hosts, options, Time.now, :stop)
67
+ tsr = ts.instance_variable_get(:@test_suite_results)
68
+ allow(tsr).to receive(:write_junit_xml).and_return(true)
69
+ allow(tsr).to receive(:summarize).and_return(true)
72
70
 
73
71
  ts.run
74
- expect( tsr.errored_tests ).to be === 1
75
- expect( tsr.failed_tests ).to be === 0
76
- expect( tsr.test_count ).to be === 1
77
- expect( tsr.passed_tests).to be === 0
78
-
72
+ expect(tsr.errored_tests).to be === 1
73
+ expect(tsr.failed_tests).to be === 0
74
+ expect(tsr.test_count).to be === 1
75
+ expect(tsr.passed_tests).to be === 0
79
76
  end
80
77
 
81
78
  it 'fails fast if fail_mode != :slow and fail test is raised' do
82
- allow( Logger ).to receive('new')
83
- @files = [ rb_test, pl_test, sh_test]
84
- File.open(rb_test, 'w') { |file| file.write(fail_script) }
85
- File.open(pl_test, 'w') { |file| file.write(okay_script) }
86
- File.open(sh_test, 'w') { |file| file.write(okay_script) }
79
+ allow(Logger).to receive('new')
80
+ @files = [rb_test, pl_test, sh_test]
81
+ File.write(rb_test, fail_script)
82
+ File.write(pl_test, okay_script)
83
+ File.write(sh_test, okay_script)
87
84
 
88
- ts = described_class.new( 'name', hosts, options, Time.now, :stop )
89
- tsr = ts.instance_variable_get( :@test_suite_results )
90
- allow( tsr ).to receive(:write_junit_xml).and_return( true )
91
- allow( tsr ).to receive(:summarize).and_return( true )
85
+ ts = described_class.new('name', hosts, options, Time.now, :stop)
86
+ tsr = ts.instance_variable_get(:@test_suite_results)
87
+ allow(tsr).to receive(:write_junit_xml).and_return(true)
88
+ allow(tsr).to receive(:summarize).and_return(true)
92
89
 
93
90
  ts.run
94
- expect( tsr.errored_tests ).to be === 0
95
- expect( tsr.failed_tests ).to be === 1
96
- expect( tsr.test_count ).to be === 1
97
- expect( tsr.passed_tests).to be === 0
98
-
91
+ expect(tsr.errored_tests).to be === 0
92
+ expect(tsr.failed_tests).to be === 1
93
+ expect(tsr.test_count).to be === 1
94
+ expect(tsr.passed_tests).to be === 0
99
95
  end
100
96
 
101
97
  it 'fails slow if fail_mode = :slow, even if a test fails and there is a runtime error' do
102
- allow( Logger ).to receive('new')
103
- @files = [ rb_test, pl_test, sh_test]
104
- File.open(rb_test, 'w') { |file| file.write(broken_script) }
105
- File.open(pl_test, 'w') { |file| file.write(fail_script) }
106
- File.open(sh_test, 'w') { |file| file.write(okay_script) }
98
+ allow(Logger).to receive('new')
99
+ @files = [rb_test, pl_test, sh_test]
100
+ File.write(rb_test, broken_script)
101
+ File.write(pl_test, fail_script)
102
+ File.write(sh_test, okay_script)
107
103
 
108
- ts = described_class.new( 'name', hosts, options, Time.now, :slow )
109
- tsr = ts.instance_variable_get( :@test_suite_results )
110
- allow( tsr ).to receive(:write_junit_xml).and_return( true )
111
- allow( tsr ).to receive(:summarize).and_return( true )
104
+ ts = described_class.new('name', hosts, options, Time.now, :slow)
105
+ tsr = ts.instance_variable_get(:@test_suite_results)
106
+ allow(tsr).to receive(:write_junit_xml).and_return(true)
107
+ allow(tsr).to receive(:summarize).and_return(true)
112
108
 
113
109
  ts.run
114
- expect( tsr.errored_tests ).to be === 1
115
- expect( tsr.failed_tests ).to be === 1
116
- expect( tsr.test_count ).to be === 3
117
- expect( tsr.passed_tests).to be === 1
118
-
110
+ expect(tsr.errored_tests).to be === 1
111
+ expect(tsr.failed_tests).to be === 1
112
+ expect(tsr.test_count).to be === 3
113
+ expect(tsr.passed_tests).to be === 1
119
114
  end
120
115
  end
121
116
 
122
117
  describe TestSuiteResult do
123
-
124
- let( :options ) { make_opts.merge({ :logger => double().as_null_object }) }
125
- let( :hosts ) { make_hosts() }
126
- let( :testcase1 ) { Beaker::TestCase.new( hosts, options[:logger], options) }
127
- let( :testcase2 ) { Beaker::TestCase.new( hosts, options[:logger], options) }
128
- let( :testcase3 ) { Beaker::TestCase.new( hosts, options[:logger], options) }
129
- let( :test_suite_result ) { described_class.new( options, "my_suite") }
118
+ let(:options) { make_opts.merge({ :logger => double.as_null_object }) }
119
+ let(:hosts) { make_hosts }
120
+ let(:testcase1) { Beaker::TestCase.new(hosts, options[:logger], options) }
121
+ let(:testcase2) { Beaker::TestCase.new(hosts, options[:logger], options) }
122
+ let(:testcase3) { Beaker::TestCase.new(hosts, options[:logger], options) }
123
+ let(:test_suite_result) { described_class.new(options, "my_suite") }
130
124
 
131
125
  it 'supports adding test cases' do
132
- expect( test_suite_result.test_count ).to be === 0
133
- test_suite_result.add_test_case( testcase1 )
134
- expect( test_suite_result.test_count ).to be === 1
126
+ expect(test_suite_result.test_count).to be === 0
127
+ test_suite_result.add_test_case(testcase1)
128
+ expect(test_suite_result.test_count).to be === 1
135
129
  end
136
130
 
137
131
  it 'calculates passed tests' do
138
132
  testcase1.instance_variable_set(:@test_status, :pass)
139
133
  testcase2.instance_variable_set(:@test_status, :pass)
140
134
  testcase3.instance_variable_set(:@test_status, :fail)
141
- test_suite_result.add_test_case( testcase1 )
142
- test_suite_result.add_test_case( testcase2 )
143
- test_suite_result.add_test_case( testcase3 )
144
- expect( test_suite_result.passed_tests ).to be == 2
135
+ test_suite_result.add_test_case(testcase1)
136
+ test_suite_result.add_test_case(testcase2)
137
+ test_suite_result.add_test_case(testcase3)
138
+ expect(test_suite_result.passed_tests).to be == 2
145
139
  end
146
140
 
147
141
  it 'calculates failed tests' do
148
142
  testcase1.instance_variable_set(:@test_status, :pass)
149
143
  testcase2.instance_variable_set(:@test_status, :pass)
150
144
  testcase3.instance_variable_set(:@test_status, :fail)
151
- test_suite_result.add_test_case( testcase1 )
152
- test_suite_result.add_test_case( testcase2 )
153
- test_suite_result.add_test_case( testcase3 )
154
- expect( test_suite_result.failed_tests ).to be == 1
145
+ test_suite_result.add_test_case(testcase1)
146
+ test_suite_result.add_test_case(testcase2)
147
+ test_suite_result.add_test_case(testcase3)
148
+ expect(test_suite_result.failed_tests).to be == 1
155
149
  end
156
150
 
157
151
  it 'calculates errored tests' do
158
152
  testcase1.instance_variable_set(:@test_status, :error)
159
153
  testcase2.instance_variable_set(:@test_status, :pass)
160
154
  testcase3.instance_variable_set(:@test_status, :fail)
161
- test_suite_result.add_test_case( testcase1 )
162
- test_suite_result.add_test_case( testcase2 )
163
- test_suite_result.add_test_case( testcase3 )
164
- expect( test_suite_result.errored_tests ).to be == 1
155
+ test_suite_result.add_test_case(testcase1)
156
+ test_suite_result.add_test_case(testcase2)
157
+ test_suite_result.add_test_case(testcase3)
158
+ expect(test_suite_result.errored_tests).to be == 1
165
159
  end
166
160
 
167
161
  it 'calculates skipped tests' do
168
162
  testcase1.instance_variable_set(:@test_status, :error)
169
163
  testcase2.instance_variable_set(:@test_status, :skip)
170
164
  testcase3.instance_variable_set(:@test_status, :fail)
171
- test_suite_result.add_test_case( testcase1 )
172
- test_suite_result.add_test_case( testcase2 )
173
- test_suite_result.add_test_case( testcase3 )
174
- expect( test_suite_result.skipped_tests ).to be == 1
165
+ test_suite_result.add_test_case(testcase1)
166
+ test_suite_result.add_test_case(testcase2)
167
+ test_suite_result.add_test_case(testcase3)
168
+ expect(test_suite_result.skipped_tests).to be == 1
175
169
  end
176
170
 
177
171
  it 'calculates pending tests' do
178
172
  testcase1.instance_variable_set(:@test_status, :error)
179
173
  testcase2.instance_variable_set(:@test_status, :pending)
180
174
  testcase3.instance_variable_set(:@test_status, :fail)
181
- test_suite_result.add_test_case( testcase1 )
182
- test_suite_result.add_test_case( testcase2 )
183
- test_suite_result.add_test_case( testcase3 )
184
- expect( test_suite_result.pending_tests ).to be == 1
175
+ test_suite_result.add_test_case(testcase1)
176
+ test_suite_result.add_test_case(testcase2)
177
+ test_suite_result.add_test_case(testcase3)
178
+ expect(test_suite_result.pending_tests).to be == 1
185
179
  end
186
180
 
187
181
  it 'calculates sum_failed as a sum of errored and failed TestCases' do
188
182
  testcase1.instance_variable_set(:@test_status, :error)
189
183
  testcase2.instance_variable_set(:@test_status, :pending)
190
184
  testcase3.instance_variable_set(:@test_status, :fail)
191
- test_suite_result.add_test_case( testcase1 )
192
- test_suite_result.add_test_case( testcase2 )
193
- test_suite_result.add_test_case( testcase3 )
194
- expect( test_suite_result.sum_failed ).to be == 2
185
+ test_suite_result.add_test_case(testcase1)
186
+ test_suite_result.add_test_case(testcase2)
187
+ test_suite_result.add_test_case(testcase3)
188
+ expect(test_suite_result.sum_failed).to be == 2
195
189
  end
196
190
 
197
191
  it 'reports success with no errors/failures' do
198
192
  testcase1.instance_variable_set(:@test_status, :pass)
199
193
  testcase2.instance_variable_set(:@test_status, :pending)
200
194
  testcase3.instance_variable_set(:@test_status, :fail)
201
- test_suite_result.add_test_case( testcase1 )
202
- test_suite_result.add_test_case( testcase2 )
203
- test_suite_result.add_test_case( testcase3 )
204
- expect( test_suite_result.success? ).to be == false
195
+ test_suite_result.add_test_case(testcase1)
196
+ test_suite_result.add_test_case(testcase2)
197
+ test_suite_result.add_test_case(testcase3)
198
+ expect(test_suite_result.success?).to be == false
205
199
  end
206
200
 
207
201
  it 'reports failed if any tests error/fail' do
208
202
  testcase1.instance_variable_set(:@test_status, :pass)
209
203
  testcase2.instance_variable_set(:@test_status, :pending)
210
204
  testcase3.instance_variable_set(:@test_status, :fail)
211
- test_suite_result.add_test_case( testcase1 )
212
- test_suite_result.add_test_case( testcase2 )
213
- test_suite_result.add_test_case( testcase3 )
214
- expect( test_suite_result.failed? ).to be == true
205
+ test_suite_result.add_test_case(testcase1)
206
+ test_suite_result.add_test_case(testcase2)
207
+ test_suite_result.add_test_case(testcase3)
208
+ expect(test_suite_result.failed?).to be == true
215
209
  end
216
210
 
217
211
  it 'can calculate the sum of all TestCase runtimes' do
218
212
  testcase1.instance_variable_set(:@runtime, 1)
219
213
  testcase2.instance_variable_set(:@runtime, 10)
220
214
  testcase3.instance_variable_set(:@runtime, 100)
221
- test_suite_result.add_test_case( testcase1 )
222
- test_suite_result.add_test_case( testcase2 )
223
- test_suite_result.add_test_case( testcase3 )
224
- expect( test_suite_result.elapsed_time ).to be == 111
215
+ test_suite_result.add_test_case(testcase1)
216
+ test_suite_result.add_test_case(testcase2)
217
+ test_suite_result.add_test_case(testcase3)
218
+ expect(test_suite_result.elapsed_time).to be == 111
225
219
  end
226
220
 
227
221
  describe '#print_test_result' do
228
222
  it 'prints the test result without the line number if no file path' do
229
- tc = Beaker::TestCase.new( hosts, options[:logger], options)
223
+ tc = Beaker::TestCase.new(hosts, options[:logger], options)
230
224
  ex = StandardError.new('failed')
231
225
  allow(ex).to receive(:backtrace).and_return(['path_to_test_file.rb line 1 - blah'])
232
226
  tc.instance_variable_set(:@exception, ex)
233
- test_suite_result.add_test_case( tc )
227
+ test_suite_result.add_test_case(tc)
234
228
  expect(test_suite_result.print_test_result(tc)).not_to match(/Test line:/)
235
- expect{ test_suite_result.print_test_result(tc) }.not_to raise_error
229
+ expect { test_suite_result.print_test_result(tc) }.not_to raise_error
236
230
  end
237
231
 
238
232
  it 'prints the test result and line number from test case file on failure' do
239
- tc = Beaker::TestCase.new( hosts, options[:logger], options, 'path_to_test_file.rb')
233
+ tc = Beaker::TestCase.new(hosts, options[:logger], options, 'path_to_test_file.rb')
240
234
  ex = StandardError.new('failed')
241
235
  allow(ex).to receive(:backtrace).and_return(['path_to_test_file.rb line 1 - blah'])
242
236
  tc.instance_variable_set(:@exception, ex)
243
- test_suite_result.add_test_case( tc )
237
+ test_suite_result.add_test_case(tc)
244
238
  expect(test_suite_result.print_test_result(tc)).to match(/Test line:/)
245
- expect{ test_suite_result.print_test_result(tc) }.not_to raise_error
239
+ expect { test_suite_result.print_test_result(tc) }.not_to raise_error
246
240
  end
247
241
  end
248
242
 
249
243
  describe '#write_junit_xml' do
250
- let(:options) { make_opts.merge({:logger => double().as_null_object,
251
- 'name' => create_files(@files),
252
- :log_dated_dir => '.',
253
- :xml_dated_dir => '.'}) }
244
+ let(:options) do
245
+ make_opts.merge({ :logger => double.as_null_object,
246
+ 'name' => create_files(@files),
247
+ :log_dated_dir => '.',
248
+ :xml_dated_dir => '.', })
249
+ end
254
250
  let(:rb_test) { 'my_ruby_file.rb' }
255
251
 
256
252
  before do
257
- @files = [ rb_test, rb_test, rb_test]
258
- @ts = Beaker::TestSuite.new( 'name', hosts, options, Time.now, :fast )
259
- @tsr = @ts.instance_variable_get( :@test_suite_results )
260
- allow( @tsr ).to receive( :start_time ).and_return(0)
261
- allow( @tsr ).to receive( :stop_time ).and_return(10)
253
+ @files = [rb_test, rb_test, rb_test]
254
+ @ts = Beaker::TestSuite.new('name', hosts, options, Time.now, :fast)
255
+ @tsr = @ts.instance_variable_get(:@test_suite_results)
256
+ allow(@tsr).to receive(:start_time).and_return(0)
257
+ allow(@tsr).to receive(:stop_time).and_return(10)
262
258
  @test_cases = []
263
259
  @files.each_with_index do |_file, _index|
264
- tc = Beaker::TestCase.new( hosts, options[:logger], options, rb_test)
265
- allow( tc ).to receive( :sublog ).and_return( false )
260
+ tc = Beaker::TestCase.new(hosts, options[:logger], options, rb_test)
261
+ allow(tc).to receive(:sublog).and_return(false)
266
262
  @test_cases << tc
267
263
  end
268
264
  @rexml_mock = REXML::Element.new("testsuites")
269
- allow(REXML::Element).to receive( :add_element ).and_call_original
270
- allow( LoggerJunit ).to receive( :write_xml ).and_yield( Object.new, @rexml_mock )
265
+ allow(REXML::Element).to receive(:add_element).and_call_original
266
+ allow(LoggerJunit).to receive(:write_xml).and_yield(Object.new, @rexml_mock)
271
267
  end
272
268
 
273
269
  it 'doesn\'t re-order test cases themselves on time_sort' do
274
- expect( @tsr.instance_variable_get( :@logger ) ).not_to receive( :error )
270
+ expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
275
271
 
276
- @test_cases.each_with_index do |tc,index|
272
+ @test_cases.each_with_index do |tc, index|
277
273
  tc.instance_variable_set(:@runtime, 3**index)
278
- @tsr.add_test_case( tc )
274
+ @tsr.add_test_case(tc)
279
275
  end
280
276
 
281
- original_testcase_order = test_suite_result.instance_variable_get( :@test_cases ).dup
277
+ original_testcase_order = test_suite_result.instance_variable_get(:@test_cases).dup
282
278
  time_sort = true
283
- @tsr.write_junit_xml( 'fakeFilePath07', 'fakeFileToLink09', time_sort )
284
- after_testcase_order = test_suite_result.instance_variable_get( :@test_cases ).dup
285
- expect( after_testcase_order ).to be === original_testcase_order
279
+ @tsr.write_junit_xml('fakeFilePath07', 'fakeFileToLink09', time_sort)
280
+ after_testcase_order = test_suite_result.instance_variable_get(:@test_cases).dup
281
+ expect(after_testcase_order).to be === original_testcase_order
286
282
  end
287
283
 
288
284
  it 'writes @export nested hashes properly' do
289
- expect( @tsr.instance_variable_get( :@logger ) ).not_to receive( :error )
290
- inner_value = {'second' => '2nd'}
285
+ expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
286
+ inner_value = { 'second' => '2nd' }
291
287
  @test_cases.each do |tc|
292
288
  tc.instance_variable_set(:@runtime, 0)
293
- tc.instance_variable_set(:@exports, [{'oh hey' => 'hai', 'first' => inner_value}])
294
- @tsr.add_test_case( tc )
289
+ tc.instance_variable_set(:@exports, [{ 'oh hey' => 'hai', 'first' => inner_value }])
290
+ @tsr.add_test_case(tc)
295
291
  end
296
- @tsr.write_junit_xml( 'fakeFilePath08')
292
+ @tsr.write_junit_xml('fakeFilePath08')
297
293
  @rexml_mock.elements.each("//testcase") do |e|
298
294
  expect(e.attributes["oh_hey"].to_s).to eq('hai')
299
295
  expect(e.attributes["first"]).to eq(inner_value.to_s)
@@ -301,13 +297,13 @@ module Beaker
301
297
  end
302
298
 
303
299
  it 'writes @export array of hashes properly' do
304
- expect( @tsr.instance_variable_get( :@logger ) ).not_to receive( :error )
300
+ expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
305
301
  @test_cases.each do |tc|
306
302
  tc.instance_variable_set(:@runtime, 0)
307
- tc.instance_variable_set(:@exports, [{:yes => 'hello'}, {:uh => 'sher'}])
308
- @tsr.add_test_case( tc )
303
+ tc.instance_variable_set(:@exports, [{ :yes => 'hello' }, { :uh => 'sher' }])
304
+ @tsr.add_test_case(tc)
309
305
  end
310
- @tsr.write_junit_xml( 'fakeFilePath08' )
306
+ @tsr.write_junit_xml('fakeFilePath08')
311
307
  @rexml_mock.elements.each("//testcase") do |e|
312
308
  expect(e.attributes["yes"].to_s).to eq('hello')
313
309
  expect(e.attributes["uh"].to_s).to eq('sher')
@@ -315,13 +311,13 @@ module Beaker
315
311
  end
316
312
 
317
313
  it 'writes @export hashes per test case properly' do
318
- expect( @tsr.instance_variable_get( :@logger ) ).not_to receive( :error )
319
- @test_cases.each_with_index do |tc,index|
314
+ expect(@tsr.instance_variable_get(:@logger)).not_to receive(:error)
315
+ @test_cases.each_with_index do |tc, index|
320
316
  tc.instance_variable_set(:@runtime, 0)
321
- tc.instance_variable_set(:@exports, [{"yes_#{index}" => "hello#{index}"}])
322
- @tsr.add_test_case( tc )
317
+ tc.instance_variable_set(:@exports, [{ "yes_#{index}" => "hello#{index}" }])
318
+ @tsr.add_test_case(tc)
323
319
  end
324
- @tsr.write_junit_xml( 'fakeFilePath08' )
320
+ @tsr.write_junit_xml('fakeFilePath08')
325
321
  index = 0
326
322
  @rexml_mock.elements.each("//testcase") do |e|
327
323
  expect(e.attributes["yes_#{index}"]).to eq("hello#{index}")
@@ -329,15 +325,14 @@ module Beaker
329
325
  end
330
326
  end
331
327
  end
332
-
333
328
  end
334
329
 
335
330
  describe '#log_path' do
336
- let( :sh_test ) { '/my_shell_file.sh' }
337
- let( :files ) { @files ? @files : [sh_test] }
338
- let( :options ) { make_opts.merge({ :logger => double().as_null_object, 'name' => create_files(files) }) }
339
- let( :hosts ) { make_hosts() }
340
- let( :testsuite ) { described_class.new( 'name', hosts, options, Time.now, :stop ) }
331
+ let(:sh_test) { '/my_shell_file.sh' }
332
+ let(:files) { @files ? @files : [sh_test] }
333
+ let(:options) { make_opts.merge({ :logger => double.as_null_object, 'name' => create_files(files) }) }
334
+ let(:hosts) { make_hosts }
335
+ let(:testsuite) { described_class.new('name', hosts, options, Time.now, :stop) }
341
336
 
342
337
  it 'returns the simple joining of the log dir & file as required' do
343
338
  expect(testsuite.log_path('foo.txt', 'man/date')).to be === 'man/date/foo.txt'
@@ -347,15 +342,15 @@ module Beaker
347
342
  # the base directory is where the latest symlink itself should live
348
343
 
349
344
  it 'in the usual case' do
350
- expect( File ).not_to be_symlink('man/latest')
345
+ expect(File).not_to be_symlink('man/latest')
351
346
  testsuite.log_path('foo.txt', 'man/date')
352
- expect( File ).to be_symlink('man/latest')
347
+ expect(File).to be_symlink('man/latest')
353
348
  end
354
349
 
355
350
  it 'if given a nested directory' do
356
- expect( File ).not_to be_symlink('a/latest')
351
+ expect(File).not_to be_symlink('a/latest')
357
352
  testsuite.log_path('foo.txt', 'a/b/c/d/e/f')
358
- expect( File ).to be_symlink('a/latest')
353
+ expect(File).to be_symlink('a/latest')
359
354
  end
360
355
  end
361
356
 
@@ -363,19 +358,17 @@ module Beaker
363
358
  # the symlink directory is where the symlink points to
364
359
 
365
360
  it 'in the usual case' do
366
- expect( File ).not_to be_symlink('d/latest')
361
+ expect(File).not_to be_symlink('d/latest')
367
362
  testsuite.log_path('foo.txt', 'd/e')
368
- expect( File.readlink('d/latest') ).to be === 'e'
363
+ expect(File.readlink('d/latest')).to be === 'e'
369
364
  end
370
365
 
371
366
  it 'if given a nested directory' do
372
- expect( File ).not_to be_symlink('f/latest')
367
+ expect(File).not_to be_symlink('f/latest')
373
368
  testsuite.log_path('foo.txt', 'f/g/h/i/j/k')
374
- expect( File.readlink('f/latest') ).to be === 'g/h/i/j/k'
369
+ expect(File.readlink('f/latest')).to be === 'g/h/i/j/k'
375
370
  end
376
371
  end
377
-
378
372
  end
379
-
380
373
  end
381
374
  end