gorgon 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -2
  3. data/.rspec +2 -0
  4. data/.travis.yml +10 -0
  5. data/Dockerfile +25 -0
  6. data/Gemfile.lock +20 -15
  7. data/README.md +33 -6
  8. data/Rakefile +5 -0
  9. data/architecture.md +2 -2
  10. data/bin/gorgon +2 -114
  11. data/daemon_with_upstart_and_rvm.md +1 -1
  12. data/docker-compose.yml +28 -0
  13. data/file_server/Dockerfile +8 -0
  14. data/file_server/test_gorgon.pem.pub +1 -0
  15. data/gorgon.gemspec +2 -2
  16. data/gorgon_secret.json.sample +5 -0
  17. data/lib/gorgon/amqp_service.rb +28 -26
  18. data/lib/gorgon/callback_handler.rb +28 -26
  19. data/lib/gorgon/colors.rb +6 -4
  20. data/lib/gorgon/command.rb +145 -0
  21. data/lib/gorgon/configuration.rb +45 -5
  22. data/lib/gorgon/core_ext/hash/deep_merge.rb +21 -0
  23. data/lib/gorgon/crash_reporter.rb +15 -13
  24. data/lib/gorgon/failures_printer.rb +27 -26
  25. data/lib/gorgon/g_logger.rb +19 -17
  26. data/lib/gorgon/gem_command_handler.rb +41 -39
  27. data/lib/gorgon/gem_service.rb +60 -57
  28. data/lib/gorgon/host_state.rb +23 -21
  29. data/lib/gorgon/job.rb +19 -17
  30. data/lib/gorgon/job_definition.rb +23 -21
  31. data/lib/gorgon/job_state.rb +93 -90
  32. data/lib/gorgon/listener.rb +137 -146
  33. data/lib/gorgon/listener_installer.rb +98 -96
  34. data/lib/gorgon/originator.rb +170 -167
  35. data/lib/gorgon/originator_logger.rb +30 -28
  36. data/lib/gorgon/originator_protocol.rb +85 -83
  37. data/lib/gorgon/ping_service.rb +44 -42
  38. data/lib/gorgon/pipe_forker.rb +17 -15
  39. data/lib/gorgon/progress_bar_view.rb +109 -107
  40. data/lib/gorgon/rsync_daemon.rb +56 -54
  41. data/lib/gorgon/runtime_file_reader.rb +28 -27
  42. data/lib/gorgon/runtime_recorder.rb +27 -26
  43. data/lib/gorgon/settings/files_content.rb +27 -25
  44. data/lib/gorgon/settings/initial_files_creator.rb +58 -56
  45. data/lib/gorgon/settings/rails_project_files_content.rb +33 -31
  46. data/lib/gorgon/settings/simple_project_files_content.rb +11 -9
  47. data/lib/gorgon/shutdown_manager.rb +20 -18
  48. data/lib/gorgon/source_tree_syncer.rb +108 -69
  49. data/lib/gorgon/version.rb +1 -1
  50. data/lib/gorgon/worker.rb +130 -128
  51. data/lib/gorgon/worker_manager.rb +139 -137
  52. data/lib/gorgon_amq-protocol/.rspec +3 -0
  53. data/run_dev_environment.sh +3 -0
  54. data/run_gorgon.sh +3 -0
  55. data/run_listener.sh +3 -0
  56. data/run_test.sh +3 -0
  57. data/spec/callback_handler_spec.rb +10 -10
  58. data/spec/command_spec.rb +172 -0
  59. data/spec/configuration_spec.rb +62 -0
  60. data/spec/core_ext/hash/deep_merge_spec.rb +11 -0
  61. data/spec/crash_reporter_spec.rb +10 -10
  62. data/spec/dummy/.gitignore +3 -0
  63. data/spec/dummy/Gemfile +11 -0
  64. data/spec/dummy/Gemfile.lock +76 -0
  65. data/spec/dummy/README.md +23 -0
  66. data/spec/dummy/gorgon.json +30 -0
  67. data/spec/dummy/gorgon_callbacks.rb +68 -0
  68. data/spec/dummy/gorgon_listener.json +8 -0
  69. data/spec/dummy/integration_spec.rb +51 -0
  70. data/spec/{support/mock_app/app/mailers → dummy/log}/.gitkeep +0 -0
  71. data/spec/dummy/rspec_runner.rb +8 -0
  72. data/spec/dummy/spec/1_syntax_error_spec.rb +1 -0
  73. data/spec/dummy/spec/exception_spec.rb +5 -0
  74. data/spec/dummy/spec/failing_spec.rb +11 -0
  75. data/spec/dummy/spec/keeping_rspec_config_spec.rb +5 -0
  76. data/spec/dummy/spec/spec_helper.rb +13 -0
  77. data/spec/dummy/spec/successful_spec.rb +9 -0
  78. data/spec/dummy/spec/using_shared_example_spec.rb +3 -0
  79. data/spec/dummy/test/.rb +15 -0
  80. data/spec/dummy/test/minitest/mini1_test.rb +11 -0
  81. data/spec/dummy/test/minitest/mini2_test.rb +25 -0
  82. data/spec/dummy/test/unit/1_syntax_error_test.rb +9 -0
  83. data/spec/dummy/test/unit/exception_test.rb +14 -0
  84. data/spec/dummy/test/unit/failing_test.rb +17 -0
  85. data/spec/dummy/test/unit/successful_test.rb +9 -0
  86. data/spec/dummy/test_gorgon.pem +27 -0
  87. data/spec/end_to_end_spec.rb +142 -0
  88. data/spec/failures_printer_spec.rb +20 -20
  89. data/spec/gem_command_handler_spec.rb +24 -24
  90. data/spec/gem_service_spec.rb +18 -18
  91. data/spec/gorgon_rspec_formatter_spec.rb +12 -12
  92. data/spec/host_state_spec.rb +8 -8
  93. data/spec/job_definition_spec.rb +3 -3
  94. data/spec/job_state_spec.rb +46 -46
  95. data/spec/listener_spec.rb +67 -73
  96. data/spec/mini_test_runner_spec.rb +7 -7
  97. data/spec/originator_logger_spec.rb +6 -6
  98. data/spec/originator_protocol_spec.rb +38 -38
  99. data/spec/originator_spec.rb +78 -69
  100. data/spec/ping_service_spec.rb +14 -14
  101. data/spec/pipe_forker_spec.rb +13 -13
  102. data/spec/progress_bar_view_spec.rb +32 -32
  103. data/spec/rspec_runner_spec.rb +12 -12
  104. data/spec/rsync_daemon_spec.rb +18 -16
  105. data/spec/runtime_file_reader_spec.rb +12 -12
  106. data/spec/runtime_recorder_spec.rb +19 -19
  107. data/spec/shutdown_manager_spec.rb +9 -9
  108. data/spec/source_tree_syncer_spec.rb +148 -61
  109. data/spec/spec_helper.rb +3 -0
  110. data/spec/support/end_to_end_helpers.rb +16 -0
  111. data/spec/support/stream_helpers.rb +23 -0
  112. data/spec/unknown_runner_spec.rb +1 -1
  113. data/spec/worker_manager_spec.rb +23 -23
  114. data/spec/worker_spec.rb +70 -70
  115. metadata +84 -113
  116. data/spec/acceptance_spec_helper.rb +0 -7
  117. data/spec/support/mock_app/.gitignore +0 -15
  118. data/spec/support/mock_app/Gemfile +0 -39
  119. data/spec/support/mock_app/Gemfile.lock +0 -135
  120. data/spec/support/mock_app/README.rdoc +0 -261
  121. data/spec/support/mock_app/Rakefile +0 -7
  122. data/spec/support/mock_app/app/assets/images/rails.png +0 -0
  123. data/spec/support/mock_app/app/assets/javascripts/application.js +0 -15
  124. data/spec/support/mock_app/app/assets/stylesheets/application.css +0 -13
  125. data/spec/support/mock_app/app/controllers/application_controller.rb +0 -3
  126. data/spec/support/mock_app/app/helpers/application_helper.rb +0 -2
  127. data/spec/support/mock_app/app/models/.gitkeep +0 -0
  128. data/spec/support/mock_app/app/views/layouts/application.html.erb +0 -14
  129. data/spec/support/mock_app/config.ru +0 -4
  130. data/spec/support/mock_app/config/application.rb +0 -62
  131. data/spec/support/mock_app/config/boot.rb +0 -6
  132. data/spec/support/mock_app/config/database.yml +0 -25
  133. data/spec/support/mock_app/config/environment.rb +0 -5
  134. data/spec/support/mock_app/config/environments/development.rb +0 -37
  135. data/spec/support/mock_app/config/environments/production.rb +0 -67
  136. data/spec/support/mock_app/config/environments/test.rb +0 -37
  137. data/spec/support/mock_app/config/initializers/backtrace_silencers.rb +0 -7
  138. data/spec/support/mock_app/config/initializers/inflections.rb +0 -15
  139. data/spec/support/mock_app/config/initializers/mime_types.rb +0 -5
  140. data/spec/support/mock_app/config/initializers/secret_token.rb +0 -7
  141. data/spec/support/mock_app/config/initializers/session_store.rb +0 -8
  142. data/spec/support/mock_app/config/initializers/wrap_parameters.rb +0 -14
  143. data/spec/support/mock_app/config/locales/en.yml +0 -5
  144. data/spec/support/mock_app/config/routes.rb +0 -58
  145. data/spec/support/mock_app/db/seeds.rb +0 -7
  146. data/spec/support/mock_app/doc/README_FOR_APP +0 -2
  147. data/spec/support/mock_app/lib/assets/.gitkeep +0 -0
  148. data/spec/support/mock_app/lib/tasks/.gitkeep +0 -0
  149. data/spec/support/mock_app/log/.gitkeep +0 -0
  150. data/spec/support/mock_app/public/404.html +0 -26
  151. data/spec/support/mock_app/public/422.html +0 -26
  152. data/spec/support/mock_app/public/500.html +0 -25
  153. data/spec/support/mock_app/public/favicon.ico +0 -0
  154. data/spec/support/mock_app/public/index.html +0 -241
  155. data/spec/support/mock_app/public/robots.txt +0 -5
  156. data/spec/support/mock_app/script/rails +0 -6
  157. data/spec/support/mock_app/test/fixtures/.gitkeep +0 -0
  158. data/spec/support/mock_app/test/functional/.gitkeep +0 -0
  159. data/spec/support/mock_app/test/integration/.gitkeep +0 -0
  160. data/spec/support/mock_app/test/performance/browsing_test.rb +0 -12
  161. data/spec/support/mock_app/test/test_helper.rb +0 -13
  162. data/spec/support/mock_app/test/unit/.gitkeep +0 -0
  163. data/spec/support/mock_app/test/unit/passing_test.rb +0 -7
  164. data/spec/support/mock_app/vendor/assets/javascripts/.gitkeep +0 -0
  165. data/spec/support/mock_app/vendor/assets/stylesheets/.gitkeep +0 -0
  166. data/spec/support/mock_app/vendor/plugins/.gitkeep +0 -0
  167. data/spec/support/originator_handler.rb +0 -8
@@ -0,0 +1,5 @@
1
+ RSpec.describe "Keeping rspec configuration" do
2
+ it "keeps rspec configuration" do
3
+ expect(RSpec.configuration.custom_setting).to eq(:set)
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ RSpec.shared_examples "a shared example" do
5
+ it "passes" do
6
+ expect(true).to eq(true)
7
+ end
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ config.add_setting :custom_setting
12
+ config.custom_setting = :set
13
+ end
@@ -0,0 +1,9 @@
1
+ describe "Successful spec" do
2
+ it "passes" do
3
+ expect(true).to eq(true)
4
+ end
5
+
6
+ it "passes again" do
7
+ expect(false).to eq(false)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.describe "Using shared example spec" do
2
+ it_behaves_like "a shared example"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+
3
+ module Stuff
4
+ class Haha < Test::Unit::TestCase
5
+ def test_blahblah
6
+ assert true
7
+ end
8
+
9
+ def test_going_to_blow_up
10
+ sleep 1
11
+ raise "oh mah gawd"
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,11 @@
1
+ require 'minitest/unit'
2
+
3
+ class GorgonMini1Test < MiniTest::Unit::TestCase
4
+ def test_pass
5
+ assert true
6
+ end
7
+
8
+ def test_that_will_be_skipped
9
+ skip "test this later"
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest/unit'
2
+
3
+ class GorgonMini2Test < MiniTest::Unit::TestCase
4
+ def test_pass
5
+ assert true
6
+ end
7
+
8
+ def test_fails
9
+ assert false
10
+ end
11
+ end
12
+
13
+ class OtherCaseTest < MiniTest::Unit::TestCase
14
+ def test_pass
15
+ assert true
16
+ end
17
+
18
+ def test_fails
19
+ assert false
20
+ end
21
+
22
+ def test_that_will_be_skipped
23
+ skip "test this later"
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ module Stuff
4
+ class Haha1 < Test::Unit::TestCase
5
+ def test_no_end
6
+ assert true
7
+ end
8
+ end
9
+
@@ -0,0 +1,14 @@
1
+ require 'test/unit'
2
+
3
+ module Stuff
4
+ class Haha1 < Test::Unit::TestCase
5
+ def test_blahblah
6
+ assert true
7
+ end
8
+
9
+ def test_going_to_blow_up
10
+ raise "oh mah gawd"
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+
3
+ module Stuff
4
+ class Over9000 < Test::Unit::TestCase
5
+ def test_blahblah
6
+ assert true
7
+ end
8
+
9
+ def test_will_fail
10
+ assert false
11
+ end
12
+
13
+ def test_2_will_fail
14
+ assert false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ module Stuff
4
+ class SuccessfulTest < Test::Unit::TestCase
5
+ def assert_true
6
+ assert true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEAtXfCXWX3qlOLErhwX9OVEFK2nYFnbNVulBZE5vPWbDwBUyTS
3
+ zuNAOtN7cmF/5GFnWJm2UHr+BMc5yKWQwoXak6I44z9apxREr/TXAVBER6NyO/Zq
4
+ dj2p0HxZy9FZHCcPV2wwGSE3O5U8mcphmWS9xYhjVhoopN5vjobgXm6ie7IYVJvY
5
+ vtZOCxCBKmDxETDl9HYphySwsNhc4fvPaYmDP8jk2SGN7Z3g2kD8FOme8rUUdYNQ
6
+ fni2l7Aq4oRNUnl48v6aMGKqW89RAd+Lg/mjPVcIsm/67XH5E0FgOvVAPTYqne06
7
+ bBpZckHru42xUPNlkHthiL9PbpBuYVYNKQ9gWwIDAQABAoIBAQCG0RdcbjHmn7SV
8
+ zuLlvnpjKyAyuf3NlG9Xo4fDEWq+9IGDdLsNKzX/vjhbTOZIFLlD0Mbq2cU4ZY6f
9
+ a6m1at5tijq7UckWke9JzhuiBTEFDAAFXlfPypYLpybLTpfmW3qBV4YQVWYEZSYl
10
+ l36VCIwYYfBy+nIxsnOsrrWoUodyXyhetYGUrbn6dspgC5K7dPhDDEtK2YQEWVrH
11
+ d8XFyl3/RTB55BPo/PUlqYfeRCdOWMtqOzW/nVvNgRVVNubr+TP8Y9nhs2XovsHD
12
+ IGmjItrMl1pbTC7O2mHAd5gGkFlq3jEr8EXK87KN/BKDUBCVDMaZYwUliFgnpQbT
13
+ Ik/7RG45AoGBAN4lRvdkZlB4ADKM2ocGjBIDDszf/7NDD6Y+/iJSlo/LPCDoxGjf
14
+ ZhCHzvqeZl7SbWr2XUhn6vVGZS4WJYb3ys/QNLKtK/XI5JYtoTFOysQY3RYttyYG
15
+ twuSI7M+lgVXvpAPoX2/dlSd7whalRDWZSLPUXrBdX6YvrmRYpOfvdklAoGBANEf
16
+ fYLyiQZmwx4F5i1EC6WYR7PakUABLPrr5L35lUiHhO1gLgu+bOgseDEBbjdOV/ES
17
+ YZO0zeTC8ou+An+nBT9S1fxIkOfxRAbSUXn5DTYOztNEfpA/zB9/NJug+P21oMMW
18
+ h6rixz/G5ayvOz6ZCJzvwBWPXPdu6U5uLjBNRtt/AoGAJ42xnhkFUqybNGT5//K9
19
+ e/OJbhcwOyXkonAy5b+YyU+hjCaF2jp0vNrBksQjbBzBmLr3Dw5ZuoRnPZZ55hc2
20
+ yFvFFk9ZNXEoqkjDm7jwx4u5ydon8yBc9TV3H9Iz+g2Og64UzgQKOLTKO82NHytd
21
+ ZJ5PXrEVj43436ewSqK1tfUCgYEAtd6RJWUQzkRoxJ+UwyE+j9GT6lLXp7ZeDAtD
22
+ cASzU9SoQlk3Mnd196VVEimQVQEJclruCatgtObmUan6OlJjOeMsvq/NdipZYyVe
23
+ PpneZ3kRXqNe/sy9FVdnxUGFygA/w+rAKln3tvufm0L6X0JwPywy/Y0k6PvIY7Fm
24
+ 8hMC4LkCgYAO82O4xrdo7Cjh1S4itM5nDuiQS4/tYcnxIHirHh6roolBoz2oIu5M
25
+ PoMZZbAAvP0mbPESndwL2f/JL8aU9EgTT9qZYtAa802yMLsFIASUWdmpA5pdnjcr
26
+ bKQ+SBYgH+c4L+kdLr0qk79FpU/SyahIlrEcTMOfKzj+PHVn64b5XQ==
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,142 @@
1
+ require "open4"
2
+ require "socket"
3
+ require File.expand_path("../support/end_to_end_helpers", __FILE__)
4
+
5
+ describe "EndToEnd" do
6
+ include Gorgon::EndToEndHelpers
7
+
8
+ HOSTNAME = "listener"
9
+
10
+ before(:all) do
11
+ Dir.chdir(File.join(__dir__, "dummy")) do
12
+ pid, stdin, stdout, stderr = Open4::popen4("bundle exec gorgon")
13
+ @outputs = stdout.read.split("*" * 80)
14
+ end
15
+ end
16
+
17
+ context "number of output hunks" do
18
+ it "is same as errors raised plus meta information" do
19
+ expect(@outputs.count).to eq(7), "expected 7 output hunks, got:\n#{@outputs.inspect}"
20
+ end
21
+ end
22
+
23
+ context "meta suite run information" do
24
+ it "has version and legend information" do
25
+ expected_meta = <<-META
26
+ Welcome to Gorgon #{Gorgon::VERSION}
27
+ before job starts was called
28
+ Loading environment and workers...\r \rLegend:
29
+ F - failure files count
30
+ H - number of hosts that have run files
31
+ W - number of workers running files
32
+
33
+
34
+ Progress: ||
35
+
36
+ META
37
+ expect(@outputs[0]).to eq(expected_meta)
38
+ end
39
+ end
40
+
41
+ context "last hunk" do
42
+ it "has information for running after_job_finishes callback" do
43
+ expect(@outputs.last).to match(Gorgon::EndToEndHelpers::AFTER_RUNNING_REGEX)
44
+ end
45
+ end
46
+
47
+ context "exception test" do
48
+ it "has proper error output" do
49
+ actual_output = extract_hunk(@outputs, /Stuff::Haha1/)
50
+ expected_output = <<-EXPECTED
51
+
52
+ File 'test/unit/exception_test.rb' failed/crashed at '#{HOSTNAME}:1'
53
+ Error:
54
+ test_going_to_blow_up(Stuff::Haha1):
55
+ RuntimeError: oh mah gawd
56
+ test/unit/exception_test.rb:10:in `test_going_to_blow_up'
57
+
58
+ EXPECTED
59
+
60
+ expect(actual_output).to eq(expected_output)
61
+ end
62
+ end
63
+
64
+ context "exception spec" do
65
+ it "has proper error output" do
66
+ actual_output = extract_hunk(@outputs, /exception_spec/)
67
+ expected_output = <<-EXPECTED
68
+
69
+ File 'spec/exception_spec.rb' failed/crashed at '#{HOSTNAME}:1'
70
+ Test name: Exception spec raises: line 2
71
+ RuntimeError
72
+ Message:
73
+ BOOOOM from spec!
74
+
75
+
76
+ EXPECTED
77
+
78
+ expect(actual_output).to eq(expected_output)
79
+ end
80
+ end
81
+
82
+ context "syntax error test" do
83
+ it "has proper error output" do
84
+ actual_output = extract_hunk(@outputs, /1_syntax_error_test/, strip_backtrace: true)
85
+ expected_output = <<-EXPECTED
86
+
87
+ File 'test/unit/1_syntax_error_test.rb' failed/crashed at '#{HOSTNAME}:1'
88
+ Exception: test/unit/1_syntax_error_test.rb:9: syntax error, unexpected end-of-input, expecting keyword_end
89
+
90
+ EXPECTED
91
+ expect(actual_output).to eq(expected_output)
92
+ end
93
+ end
94
+
95
+ context "syntax error spec" do
96
+ it "has proper error output" do
97
+ actual_output = extract_hunk(@outputs, /1_syntax_error_spec/, strip_backtrace: true)
98
+ expected_output = <<-EXPECTED
99
+
100
+ File 'spec/1_syntax_error_spec.rb' failed/crashed at '#{HOSTNAME}:1'
101
+ Exception: undefined local variable or method `ruby' for main:Object
102
+
103
+ EXPECTED
104
+ expect(actual_output).to eq(expected_output)
105
+ end
106
+ end
107
+
108
+ context "failing test" do
109
+ it "has proper error output" do
110
+ actual_output = extract_hunk(@outputs, /failing_test\.rb/)
111
+ expected_output = <<-EXPECTED
112
+
113
+ File 'test/unit/failing_test.rb' failed/crashed at '#{HOSTNAME}:1'
114
+ Failure:
115
+ test_2_will_fail(Stuff::Over9000) [test/unit/failing_test.rb:14]:
116
+ <false> is not true.
117
+ Failure:
118
+ test_will_fail(Stuff::Over9000) [test/unit/failing_test.rb:10]:
119
+ <false> is not true.
120
+
121
+ EXPECTED
122
+ expect(actual_output).to eq(expected_output)
123
+ end
124
+ end
125
+
126
+ context "failing spec" do
127
+ it "has proper error output" do
128
+ actual_output = extract_hunk(@outputs, /failing_spec\.rb/)
129
+ expected_output = <<-EXPECTED
130
+
131
+ File 'spec/failing_spec.rb' failed/crashed at '#{HOSTNAME}:1'
132
+ Test name: Failing spec fails: line 6
133
+ RSpec::Expectations::ExpectationNotMetError
134
+ Message:
135
+ failed
136
+
137
+
138
+ EXPECTED
139
+ expect(actual_output).to eq(expected_output)
140
+ end
141
+ end
142
+ end
@@ -1,6 +1,6 @@
1
1
  require 'gorgon/failures_printer'
2
2
 
3
- describe FailuresPrinter do
3
+ describe Gorgon::FailuresPrinter do
4
4
  let(:job_state) { double("Job State", :add_observer => nil,
5
5
  :is_job_complete? => true, :is_job_cancelled? => false,
6
6
  :each_failed_test => nil,
@@ -8,63 +8,63 @@ describe FailuresPrinter do
8
8
  let(:fd) {double("File descriptor", :write => nil)}
9
9
 
10
10
  subject do
11
- FailuresPrinter.new({}, job_state)
11
+ Gorgon::FailuresPrinter.new({}, job_state)
12
12
  end
13
13
 
14
14
  it { should respond_to :update }
15
15
 
16
16
  describe "#initialize" do
17
17
  it "add its self to observers of job_state" do
18
- job_state.should_receive(:add_observer)
19
- FailuresPrinter.new({}, job_state)
18
+ expect(job_state).to receive(:add_observer)
19
+ Gorgon::FailuresPrinter.new({}, job_state)
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#update" do
24
24
  before do
25
- @printer = FailuresPrinter.new({}, job_state)
25
+ @printer = Gorgon::FailuresPrinter.new({}, job_state)
26
26
  end
27
27
 
28
28
  context "job is not completed nor cancelled" do
29
29
  it "doesn't output anything" do
30
- job_state.stub(:is_job_complete? => false)
31
- File.should_not_receive(:open)
30
+ allow(job_state).to receive(:is_job_complete?).and_return(false)
31
+ expect(File).not_to receive(:open)
32
32
  @printer.update({})
33
33
  end
34
34
  end
35
35
 
36
36
  context "job is completed" do
37
37
  it "outputs failed tests return by job_state#each_failed_test" do
38
- job_state.stub(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
39
- File.should_receive(:open).with(FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
40
- fd.should_receive(:write).with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
38
+ allow(job_state).to receive(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
39
+ expect(File).to receive(:open).with(Gorgon::FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
40
+ expect(fd).to receive(:write).with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
41
41
  @printer.update({})
42
42
  end
43
43
 
44
44
  it "outputs failed tests to 'failed_files' in configuration" do
45
- printer = FailuresPrinter.new({failed_files: 'a-file-somewhere.json'}, job_state)
46
- File.should_receive(:open).with('a-file-somewhere.json', 'w+')
45
+ printer = Gorgon::FailuresPrinter.new({failed_files: 'a-file-somewhere.json'}, job_state)
46
+ expect(File).to receive(:open).with('a-file-somewhere.json', 'w+')
47
47
  printer.update({})
48
48
  end
49
49
  end
50
50
 
51
51
  context "job is cancelled" do
52
52
  before do
53
- job_state.stub(:is_job_complete?).and_return(false)
54
- job_state.stub(:is_job_cancelled?).and_return(true)
53
+ allow(job_state).to receive(:is_job_complete?).and_return(false)
54
+ allow(job_state).to receive(:is_job_cancelled?).and_return(true)
55
55
  end
56
56
 
57
57
  it "outputs failed tests return by job_state#each_failed_test" do
58
- job_state.stub(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
59
- File.should_receive(:open).with(FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
60
- fd.should_receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
58
+ allow(job_state).to receive(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
59
+ expect(File).to receive(:open).with(Gorgon::FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
60
+ expect(fd).to receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
61
61
  @printer.update({})
62
62
  end
63
63
 
64
64
  it "outputs still-running files returns by job_state#each_running_file" do
65
- job_state.stub(:each_running_file).and_yield("host1", "file1.rb").and_yield("host2", "file2.rb")
66
- File.stub(:open).and_yield fd
67
- fd.should_receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
65
+ allow(job_state).to receive(:each_running_file).and_yield("host1", "file1.rb").and_yield("host2", "file2.rb")
66
+ allow(File).to receive(:open).and_yield fd
67
+ expect(fd).to receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
68
68
  @printer.update({})
69
69
  end
70
70
  end
@@ -1,6 +1,6 @@
1
1
  require 'gorgon/gem_command_handler'
2
2
 
3
- describe GemCommandHandler do
3
+ describe Gorgon::GemCommandHandler do
4
4
  let(:exchange) { double("GorgonBunny Exchange", :publish => nil) }
5
5
  let(:bunny) { double("GorgonBunny", :exchange => exchange, :stop => nil) }
6
6
 
@@ -15,70 +15,70 @@ describe GemCommandHandler do
15
15
 
16
16
  describe "#handle" do
17
17
  before do
18
- @handler = GemCommandHandler.new bunny
18
+ @handler = Gorgon::GemCommandHandler.new bunny
19
19
  @running_response = {:type => :running_command, :hostname => Socket.gethostname}
20
20
  stub_methods
21
21
  end
22
22
 
23
23
  it "publishes 'running_command' message" do
24
- bunny.should_receive(:exchange).with("name", anything).and_return(exchange)
25
- Yajl::Encoder.should_receive(:encode).with(@running_response).and_return :json_msg
26
- exchange.should_receive(:publish).with(:json_msg)
24
+ expect(bunny).to receive(:exchange).with("name", anything).and_return(exchange)
25
+ expect(Yajl::Encoder).to receive(:encode).with(@running_response).and_return :json_msg
26
+ expect(exchange).to receive(:publish).with(:json_msg)
27
27
  @handler.handle payload, {}
28
28
  end
29
29
 
30
30
  it "runs 'gem <command> gorgon' using popen4" do
31
- Open4.should_receive(:popen4).with("gem cmd gorgon").and_return([1, stdin, stdout, stderr])
31
+ expect(Open4).to receive(:popen4).with("gem cmd gorgon").and_return([1, stdin, stdout, stderr])
32
32
  @handler.handle payload, {}
33
33
  end
34
34
 
35
35
  it "uses binary gem from configuration if this was specified" do
36
- Open4.should_receive(:popen4).with("path/to/gem cmd gorgon").and_return([1, stdin, stdout, stderr])
36
+ expect(Open4).to receive(:popen4).with("path/to/gem cmd gorgon").and_return([1, stdin, stdout, stderr])
37
37
  @handler.handle payload, {:bin_gem_path => "path/to/gem"}
38
38
  end
39
39
 
40
40
  it "waits for the command to finish" do
41
- Open4.should_receive(:popen4).ordered
42
- Process.should_receive(:waitpid2).with(1).ordered.and_return([nil, status])
41
+ expect(Open4).to receive(:popen4).ordered
42
+ expect(Process).to receive(:waitpid2).with(1).ordered.and_return([nil, status])
43
43
  @handler.handle payload, {}
44
44
  end
45
45
 
46
46
  it "closes stding and reads stdout and stderr from process" do
47
- stdin.should_receive(:close)
48
- stdout.should_receive(:read)
49
- stderr.should_receive(:read)
47
+ expect(stdin).to receive(:close)
48
+ expect(stdout).to receive(:read)
49
+ expect(stderr).to receive(:read)
50
50
  @handler.handle payload, {}
51
51
  end
52
52
 
53
53
  it "sends 'command_completed' message when exitstatus is 0" do
54
54
  response = {:type => :command_completed, :hostname => Socket.gethostname,
55
55
  :command => "gem cmd gorgon", :stdout => "output", :stderr => "errors" }
56
- Yajl::Encoder.should_receive(:encode).once.ordered.with(@running_response)
57
- Yajl::Encoder.should_receive(:encode).once.ordered.with(response).and_return :json_msg
58
- exchange.should_receive(:publish).with(:json_msg)
56
+ expect(Yajl::Encoder).to receive(:encode).once.ordered.with(@running_response)
57
+ expect(Yajl::Encoder).to receive(:encode).once.ordered.with(response).and_return :json_msg
58
+ expect(exchange).to receive(:publish).with(:json_msg)
59
59
  @handler.handle payload, {}
60
60
  end
61
61
 
62
62
  it "stops bunny and exit if exitstatus is 0" do
63
- bunny.should_receive(:stop).once.ordered
64
- @handler.should_receive(:exit).once.ordered
63
+ expect(bunny).to receive(:stop).once.ordered
64
+ expect(@handler).to receive(:exit).once.ordered
65
65
  @handler.handle payload, {}
66
66
  end
67
67
 
68
68
  it "sends 'command_failed' message when exitstatus is not 0" do
69
- status.should_receive(:exitstatus).and_return(99)
69
+ expect(status).to receive(:exitstatus).and_return(99)
70
70
  response = {:type => :command_failed, :hostname => Socket.gethostname,
71
71
  :command => "gem cmd gorgon", :stdout => "output", :stderr => "errors" }
72
- Yajl::Encoder.should_receive(:encode).with(response).and_return :json_msg
73
- exchange.should_receive(:publish).with(:json_msg)
72
+ expect(Yajl::Encoder).to receive(:encode).with(response).and_return :json_msg
73
+ expect(exchange).to receive(:publish).with(:json_msg)
74
74
  @handler.handle payload, {}
75
75
  end
76
76
  end
77
77
 
78
78
  def stub_methods
79
- Open4.stub(:popen4).and_return([1, stdin, stdout, stderr])
80
- Process.stub(:waitpid2).and_return([nil, status])
81
- Yajl::Encoder.stub(:encode).and_return :json_msg
82
- @handler.stub(:exit)
79
+ allow(Open4).to receive(:popen4).and_return([1, stdin, stdout, stderr])
80
+ allow(Process).to receive(:waitpid2).and_return([nil, status])
81
+ allow(Yajl::Encoder).to receive(:encode).and_return :json_msg
82
+ allow(@handler).to receive(:exit)
83
83
  end
84
84
  end