deep_test_pre 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. data/CHANGELOG +47 -0
  2. data/README.rdoc +199 -0
  3. data/Rakefile +137 -0
  4. data/lib/deep_test.rb +78 -0
  5. data/lib/deep_test/agent.rb +108 -0
  6. data/lib/deep_test/central_command.rb +165 -0
  7. data/lib/deep_test/cpu_info.rb +22 -0
  8. data/lib/deep_test/database/mysql_setup_listener.rb +112 -0
  9. data/lib/deep_test/database/setup_listener.rb +116 -0
  10. data/lib/deep_test/deadlock_detector.rb +7 -0
  11. data/lib/deep_test/demon.rb +25 -0
  12. data/lib/deep_test/distributed/beachhead.rb +104 -0
  13. data/lib/deep_test/distributed/dispatch_controller.rb +60 -0
  14. data/lib/deep_test/distributed/establish_beachhead.rb +19 -0
  15. data/lib/deep_test/distributed/filename_resolver.rb +40 -0
  16. data/lib/deep_test/distributed/landing_fleet.rb +30 -0
  17. data/lib/deep_test/distributed/landing_ship.rb +60 -0
  18. data/lib/deep_test/distributed/remote_deployment.rb +56 -0
  19. data/lib/deep_test/distributed/rsync.rb +50 -0
  20. data/lib/deep_test/distributed/shell_environment.rb +50 -0
  21. data/lib/deep_test/distributed/ssh_client_connection_info.rb +14 -0
  22. data/lib/deep_test/extensions/object_extension.rb +40 -0
  23. data/lib/deep_test/failure_message.rb +19 -0
  24. data/lib/deep_test/lib_root.rb +4 -0
  25. data/lib/deep_test/listener_list.rb +17 -0
  26. data/lib/deep_test/local_deployment.rb +46 -0
  27. data/lib/deep_test/logger.rb +32 -0
  28. data/lib/deep_test/main.rb +41 -0
  29. data/lib/deep_test/marshallable_exception_wrapper.rb +44 -0
  30. data/lib/deep_test/metrics/data.rb +34 -0
  31. data/lib/deep_test/metrics/measurement.rb +39 -0
  32. data/lib/deep_test/null_listener.rb +62 -0
  33. data/lib/deep_test/options.rb +113 -0
  34. data/lib/deep_test/proxy_io.rb +77 -0
  35. data/lib/deep_test/rake_tasks.rb +13 -0
  36. data/lib/deep_test/result_reader.rb +40 -0
  37. data/lib/deep_test/rspec_detector.rb +21 -0
  38. data/lib/deep_test/spec.rb +17 -0
  39. data/lib/deep_test/spec/extensions/example_group_methods.rb +64 -0
  40. data/lib/deep_test/spec/extensions/example_methods.rb +52 -0
  41. data/lib/deep_test/spec/extensions/options.rb +43 -0
  42. data/lib/deep_test/spec/extensions/spec_task.rb +21 -0
  43. data/lib/deep_test/spec/runner.rb +72 -0
  44. data/lib/deep_test/spec/work_result.rb +35 -0
  45. data/lib/deep_test/spec/work_unit.rb +59 -0
  46. data/lib/deep_test/test.rb +10 -0
  47. data/lib/deep_test/test/extensions/error.rb +14 -0
  48. data/lib/deep_test/test/run_test_suite.rb +5 -0
  49. data/lib/deep_test/test/runner.rb +24 -0
  50. data/lib/deep_test/test/supervised_test_suite.rb +48 -0
  51. data/lib/deep_test/test/work_result.rb +35 -0
  52. data/lib/deep_test/test/work_unit.rb +40 -0
  53. data/lib/deep_test/test_task.rb +47 -0
  54. data/lib/deep_test/ui/console.rb +74 -0
  55. data/lib/deep_test/ui/null.rb +17 -0
  56. data/lib/deep_test/warlock.rb +146 -0
  57. data/lib/telegraph.rb +29 -0
  58. data/lib/telegraph/ack_sequence.rb +14 -0
  59. data/lib/telegraph/logging.rb +20 -0
  60. data/lib/telegraph/message.rb +39 -0
  61. data/lib/telegraph/operator.rb +47 -0
  62. data/lib/telegraph/switchboard.rb +57 -0
  63. data/lib/telegraph/wire.rb +73 -0
  64. data/test/deep_test/agent_test.rb +175 -0
  65. data/test/deep_test/central_command_test.rb +147 -0
  66. data/test/deep_test/cpu_info_test.rb +33 -0
  67. data/test/deep_test/database/mysql_setup_listener_test.rb +18 -0
  68. data/test/deep_test/demon_test.rb +23 -0
  69. data/test/deep_test/distributed/beachhead_test.rb +67 -0
  70. data/test/deep_test/distributed/dispatch_controller_test.rb +162 -0
  71. data/test/deep_test/distributed/filename_resolver_test.rb +56 -0
  72. data/test/deep_test/distributed/landing_fleet_test.rb +55 -0
  73. data/test/deep_test/distributed/landing_ship_test.rb +48 -0
  74. data/test/deep_test/distributed/remote_deployment_test.rb +134 -0
  75. data/test/deep_test/distributed/rsync_test.rb +47 -0
  76. data/test/deep_test/distributed/shell_environment_test.rb +108 -0
  77. data/test/deep_test/distributed/ssh_client_connection_info_test.rb +34 -0
  78. data/test/deep_test/extensions/object_extension_test.rb +37 -0
  79. data/test/deep_test/listener_list_test.rb +22 -0
  80. data/test/deep_test/local_deployment_test.rb +19 -0
  81. data/test/deep_test/logger_test.rb +38 -0
  82. data/test/deep_test/main_test.rb +12 -0
  83. data/test/deep_test/marshallable_exception_wrapper_test.rb +46 -0
  84. data/test/deep_test/metrics/data_test.rb +22 -0
  85. data/test/deep_test/metrics/measurement_test.rb +18 -0
  86. data/test/deep_test/proxy_io_test.rb +104 -0
  87. data/test/deep_test/result_reader_test.rb +128 -0
  88. data/test/deep_test/test/extensions/error_test.rb +42 -0
  89. data/test/deep_test/test/runner_test.rb +11 -0
  90. data/test/deep_test/test/supervised_test_suite_test.rb +107 -0
  91. data/test/deep_test/test/work_result_test.rb +85 -0
  92. data/test/deep_test/test/work_unit_test.rb +63 -0
  93. data/test/deep_test/test_task_test.rb +15 -0
  94. data/test/deep_test/ui/console_test.rb +13 -0
  95. data/test/deep_test/warlock_test.rb +40 -0
  96. data/test/test_helper.rb +30 -0
  97. data/test/test_task_test.rb +75 -0
  98. metadata +156 -0
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "push executes rsync with using destination as remote location" do
7
+ RSync.expects(:system).
8
+ with("rsync -az --delete #{DeepTest::LIB_ROOT} source host:destination").returns(true)
9
+
10
+ RSync.push('host', {:source => "source"}, "destination")
11
+ end
12
+
13
+ test "raises error if push fails" do
14
+ RSync.expects(:system).returns(false)
15
+
16
+ assert_raises(RuntimeError) do
17
+ RSync.push(mock, {:source => "a", :local => true}, "destination")
18
+ end
19
+ end
20
+
21
+ test "include rsync_options in command" do
22
+ args = RSync::Args.new(mock, {:local => true, :rsync_options => "opt1 opt2"})
23
+ assert_equal "rsync -az --delete opt1 opt2 #{DeepTest::LIB_ROOT}", args.command("", "")
24
+ end
25
+
26
+ test "includes host in remote_location" do
27
+ args = RSync::Args.new('host', {})
28
+ assert_equal "host:dest", args.remote_location('dest')
29
+ end
30
+
31
+ test "separates host and dest with double colon if using daemon" do
32
+ args = RSync::Args.new('host', {:daemon => true})
33
+ assert_equal "host::dest", args.remote_location('dest')
34
+ end
35
+
36
+ test "includes username in dest_location if specified" do
37
+ args = RSync::Args.new('host', {:username => "user"})
38
+ assert_equal "user@host:dest", args.remote_location('dest')
39
+ end
40
+
41
+ test "does not include host in dest_location if local is specified" do
42
+ args = RSync::Args.new(mock, {:local => true})
43
+ assert_equal "dest", args.remote_location('dest')
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,108 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "like_login creates enviroment that will behave like login shell" do
7
+ expected_env = ShellEnvironment.new
8
+ expected_env.include_first '/etc/profile'
9
+ expected_env.include_first '~/.profile', '~/.bash_profile', '~/.bashrc'
10
+
11
+ assert_equal expected_env, ShellEnvironment.like_login
12
+ end
13
+
14
+ test "include_first command loads the specified file when it exists" do
15
+ environment = ShellEnvironment.new
16
+ environment.include_first fixture_path('set_foo_to_bar')
17
+
18
+ assert_enviroment({:FOO => "bar"}, environment)
19
+ end
20
+
21
+ test "include_first does not load the file if it doesnt exist" do
22
+ environment = ShellEnvironment.new
23
+ environment.include_first fixture_path('nonexistent')
24
+ assert_enviroment({:SHELL => ENV['SHELL']}, environment)
25
+ end
26
+
27
+ test "include_first loads second file if first does not exist" do
28
+ environment = ShellEnvironment.new
29
+
30
+ environment.include_first fixture_path('nonexistent'),
31
+ fixture_path('set_foo_to_bar')
32
+
33
+ assert_enviroment({:FOO => "bar"}, environment)
34
+ end
35
+
36
+ test "include_first does not load second file if first exists" do
37
+ environment = ShellEnvironment.new
38
+
39
+ environment.include_first fixture_path('set_foo_to_bar'),
40
+ fixture_path('set_foo_to_baz')
41
+
42
+ assert_enviroment({:FOO => "bar"}, environment)
43
+ end
44
+
45
+ test "include_first loads each file when called two separate times" do
46
+ environment = DeepTest::Distributed::ShellEnvironment.new
47
+ environment.include_first fixture_path('set_foo_to_bar')
48
+ environment.include_first fixture_path('set_bar_to_foo')
49
+
50
+ assert_enviroment({:FOO => "bar", :BAR => "foo"}, environment)
51
+ end
52
+
53
+ test "include_first loads files in order in which it was called" do
54
+ environment = ShellEnvironment.new
55
+ environment.include_first fixture_path('set_foo_to_bar')
56
+ environment.include_first fixture_path('set_foo_to_baz')
57
+
58
+ assert_enviroment({:FOO => "baz"}, environment)
59
+ end
60
+
61
+ test "source file lists are equal when they will load the same files" do
62
+ assert_equal ShellEnvironment::SourceFileList.new(['a','b']),
63
+ ShellEnvironment::SourceFileList.new(['a','b'])
64
+
65
+ assert_not_equal ShellEnvironment::SourceFileList.new(['a','b']),
66
+ ShellEnvironment::SourceFileList.new(['b','a'])
67
+ end
68
+
69
+ test "environments are equal when files will load in the same order" do
70
+ env1, env2 = ShellEnvironment.new, ShellEnvironment.new
71
+
72
+ env1.include_first 'A'; env2.include_first 'A'
73
+ env1.include_first 'B'; env2.include_first 'B'
74
+
75
+ assert_equal env1, env2
76
+ end
77
+
78
+ test "environments are not equal when files will load in the different order" do
79
+ env1, env2 = ShellEnvironment.new, ShellEnvironment.new
80
+
81
+ env1.include_first 'A'; env2.include_first 'B'
82
+ env1.include_first 'B'; env2.include_first 'A'
83
+
84
+ assert_not_equal env1, env2
85
+ end
86
+
87
+ def assert_enviroment(expected_hash, environment)
88
+ output = `#{environment} && env`
89
+ assert $?.success?, "'#{environment} && env' command failed"
90
+
91
+ actual_hash = output.inject({}) do |h, line|
92
+ if line =~ /^(.*?)=(.*)/ && expected_hash.key?($1.to_sym)
93
+ h[$1.to_sym] = $2
94
+ end
95
+ h
96
+ end
97
+
98
+ assert_equal expected_hash, actual_hash
99
+ end
100
+
101
+ def fixture_path(filename)
102
+ File.expand_path(File.join(File.dirname(__FILE__),
103
+ 'shell_environment_fixtures',
104
+ filename))
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "returns ipaddress from SSH_CLIENT as address" do
7
+ info = nil
8
+ with_env("SSH_CLIENT", "168.0.0.1 33345 22") do
9
+ info = SshClientConnectionInfo.new
10
+ end
11
+ assert_equal "168.0.0.1", info.address
12
+ end
13
+
14
+ test "raises an error if SSH_CLIENT is blank" do
15
+ with_env("SSH_CLIENT", "") do
16
+ assert_raises(RuntimeError) { SshClientConnectionInfo.new }
17
+ end
18
+ end
19
+
20
+ test "raises an error if no SSH_CLIENT is found" do
21
+ with_env("SSH_CLIENT", nil) do
22
+ assert_raises(RuntimeError) { SshClientConnectionInfo.new }
23
+ end
24
+ end
25
+
26
+ def with_env(variable, value)
27
+ old_value, ENV[variable] = ENV[variable], value
28
+ yield
29
+ ensure
30
+ ENV[variable] = old_value
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ unit_tests do
4
+ test "retrying once" do
5
+ object = Object.new
6
+ object.expects(:call_it_twice).times(2).raises(RuntimeError).then.returns(:ok)
7
+ result = nil
8
+ capture_stdout do
9
+ result = retrying do
10
+ object.call_it_twice
11
+ end
12
+ end
13
+ assert_equal :ok, result
14
+ end
15
+
16
+ test "retrying defaults to 5 times" do
17
+ object = Object.new
18
+ object.expects(:may_i_please_have_another).times(5).
19
+ raises(RuntimeError).raises(RuntimeError).raises(RuntimeError).raises(RuntimeError).returns("ok")
20
+ capture_stdout do
21
+ retrying do
22
+ object.may_i_please_have_another
23
+ end
24
+ end
25
+ end
26
+
27
+ test "retrying raises exception if still failing after number of attempts" do
28
+ my_error = Class.new(StandardError)
29
+ assert_raises(my_error) do
30
+ capture_stdout do
31
+ retrying "", 1 do
32
+ raise my_error
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "forwards methods defined in NullListener to all listeners" do
6
+ listener_1, listener_2 = mock, mock
7
+ list = ListenerList.new([listener_1, listener_2])
8
+ listener_1.expects(:starting).with(:agent)
9
+ listener_2.expects(:starting).with(:agent)
10
+ listener_1.expects(:starting_work).with(:agent, :work)
11
+ listener_2.expects(:starting_work).with(:agent, :work)
12
+ list.starting(:agent)
13
+ list.starting_work(:agent, :work)
14
+ end
15
+
16
+ test "doesn't forward methods not defined in NullListener" do
17
+ listener = mock
18
+ listener.expects(:to_s).never
19
+ ListenerList.new([listener]).to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "number_of_agents is determined by options" do
6
+ deployment = LocalDeployment.new Options.new(:number_of_agents => 4)
7
+ assert_equal 4, deployment.number_of_agents
8
+ end
9
+
10
+ test "load_files simply loads each file provided" do
11
+ deployment = LocalDeployment.new Options.new({})
12
+
13
+ deployment.expects(:load).with(:file_1)
14
+ deployment.expects(:load).with(:file_2)
15
+
16
+ deployment.load_files([:file_1, :file_2])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "info log level by default" do
6
+ assert_equal Logger::INFO, DeepTest.logger.level
7
+ end
8
+
9
+ test "formatter uses msg only" do
10
+ time = Time.parse("2009-09-22 12:01:33")
11
+ assert_equal "[DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 my_msg\n", DeepTest.logger.formatter.call(nil, time, nil, "my_msg")
12
+ end
13
+
14
+ Logger::Severity.constants.each do |severity|
15
+ test "#{severity.downcase} can not be called with any arguments" do
16
+ logger = Logger.new stub_everything
17
+ assert_raises(ArgumentError) { logger.send severity.downcase, "a" }
18
+ end
19
+
20
+ THE_DATE = '\d{4}-\d\d-\d\d \d\d:\d\d:\d\d' unless defined?(THE_DATE)
21
+
22
+ test "#{severity.downcase} can be called with a block" do
23
+ logger = Logger.new(out = StringIO.new)
24
+ logger.level = Logger.const_get(severity)
25
+ logger.send(severity.downcase) { "a" }
26
+ assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} a\n/, out.string
27
+ end
28
+
29
+ test "#{severity.downcase} rescues errors from block and logs them" do
30
+ logger = Logger.new(out = StringIO.new)
31
+ logger.level = Logger.const_get(severity)
32
+ logger.send(severity.downcase) { raise Exception, "e" }
33
+ assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} Exception: e occurred logging on #{__FILE__}:#{__LINE__ - 1}:in `send'\n/,
34
+ out.string
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "shutdown calls done_with_work" do
6
+ main = Main.new(nil, stub_everything, nil, central_command = mock)
7
+ central_command.expects(:done_with_work)
8
+
9
+ main.shutdown
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "loading a marshallable exception evals the classname and returns an instance of the original exception" do
6
+ original = RuntimeError.new "message"
7
+ original.set_backtrace ['1', '2']
8
+
9
+ marshalled = MarshallableExceptionWrapper.new(original)
10
+ MarshallableExceptionWrapper.any_instance.expects(:eval).
11
+ with("::RuntimeError").returns(RuntimeError)
12
+
13
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
14
+
15
+ assert_equal original.class, loaded.class
16
+ assert_equal original.message, loaded.message
17
+ assert_equal original.backtrace, loaded.backtrace
18
+ end
19
+
20
+ test "loading a marshallable exception when class is not available returns an instance of unloadable exception" do
21
+ original = RuntimeError.new "message"
22
+ original.set_backtrace ['1', '2']
23
+
24
+ marshalled = MarshallableExceptionWrapper.new(original)
25
+ MarshallableExceptionWrapper.any_instance.expects(:eval).
26
+ raises("Eval Error")
27
+
28
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
29
+
30
+ assert_equal UnloadableException, loaded.class
31
+ assert_equal "RuntimeError: " + original.message, loaded.message
32
+ assert_equal original.backtrace, loaded.backtrace
33
+ end
34
+
35
+ test "loading a marshallable exception when class init throws an error returns an unloadable exception" do
36
+ original = RuntimeError.new "message"
37
+
38
+ marshalled = MarshallableExceptionWrapper.new(original)
39
+ RuntimeError.expects(:new).raises(StandardError.new)
40
+
41
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
42
+
43
+ assert_equal UnloadableException, loaded.class
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Metrics
5
+ class DataTest < ::Test::Unit::TestCase
6
+ test "measurements are summarized in report" do
7
+ data = Data.new
8
+ data.add Measurement.new("category a", 1, "bytes")
9
+ data.add Measurement.new("category b", 2, "seconds")
10
+ data.add Measurement.new("category a", 2, "bytes")
11
+ data.add Measurement.new("category b", 3, "seconds")
12
+
13
+ assert_equal <<-end_text, data.summary
14
+ Metrics Data
15
+ ------------
16
+ category a: 1.5 avg / 3 total bytes
17
+ category b: 2.5 avg / 5 total seconds
18
+ end_text
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Metrics
5
+ class MeasurementTest < ::Test::Unit::TestCase
6
+ test "of_time_taken should measure time an operation takes" do
7
+ measurement = Measurement.of_time_taken("category") do
8
+ sleep 0.5
9
+ end
10
+
11
+ assert_equal "category", measurement.category
12
+ assert_in_delta 0.5, measurement.value, 0.1
13
+ assert_equal "seconds", measurement.units
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "should write strings to proxy wire" do
6
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
7
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("my_string")
8
+ io.write "my_string"
9
+ end
10
+
11
+ test "should call to_s on any received objects" do
12
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
13
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("some value")
14
+ io.write mock(:to_s => "some value")
15
+ end
16
+
17
+ test "should clear string buffer after forwarding to wire" do
18
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
19
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 1")
20
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 2")
21
+ io.write "string 1"
22
+ io.write "string 2"
23
+ end
24
+
25
+ test "should forward flush to the wire" do
26
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
27
+ wire.expects(:send_message).with kind_of(ProxyIO::Stdout::Flush)
28
+ io.flush
29
+ end
30
+
31
+ test "Stdout::Output prints to stdout" do
32
+ output = ProxyIO::Stdout::Output.new("output")
33
+ assert_equal "output", capture_stdout { output.execute }
34
+ end
35
+
36
+ test "Stderr::Output prints to stdout" do
37
+ output = ProxyIO::Stderr::Output.new("output")
38
+ assert_equal "output", capture_stderr { output.execute }
39
+ end
40
+
41
+ test "Stdout::Flush prints to stdout" do
42
+ output = ProxyIO::Stdout::Flush.new
43
+ $stdout.expects :flush
44
+ output.execute
45
+ end
46
+
47
+ test "Stderr::Flush prints to stdout" do
48
+ output = ProxyIO::Stderr::Flush.new
49
+ $stderr.expects :flush
50
+ output.execute
51
+ end
52
+
53
+ test "replace_stdout_stderr! yields" do
54
+ yielded = false
55
+ ProxyIO.replace_stdout_stderr!(mock) { yielded = true }
56
+ assert yielded, "didn't yield"
57
+ end
58
+
59
+ test "will replace stdout with proxy to wire" do
60
+ ProxyIO.replace_stdout_stderr!(wire = mock) do
61
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("global string")
62
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("const string")
63
+ $stdout.write "global string"
64
+ STDOUT.write "const string"
65
+ end
66
+ end
67
+
68
+ test "will restore stdout after yielding" do
69
+ old_stdout_global, old_stdout_const = $stdout, STDOUT
70
+ ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
71
+ assert_equal old_stdout_global, $stdout
72
+ assert_equal old_stdout_const, STDOUT
73
+ end
74
+
75
+ test "will replace stderr with proxy to wire" do
76
+ ProxyIO.replace_stdout_stderr!(wire = mock) do
77
+ wire.expects(:send_message).with ProxyIO::Stderr::Output.new("global string")
78
+ wire.expects(:send_message).with ProxyIO::Stderr::Output.new("const string")
79
+ $stderr.write "global string"
80
+ STDERR.write "const string"
81
+ end
82
+ end
83
+
84
+ test "will restore stderr after yielding" do
85
+ old_stderr_global, old_stderr_const = $stderr, STDERR
86
+ ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
87
+ assert_equal old_stderr_global, $stderr
88
+ assert_equal old_stderr_const, STDERR
89
+ end
90
+
91
+ test "reconnect the logger to the new stdout" do
92
+ old_stderr_global, old_stderr_const = $stderr, STDERR
93
+ ProxyIO.replace_stdout_stderr!(mock) do
94
+ assert_equal $stdout, DeepTest.logger.io_stream
95
+ end
96
+ end
97
+
98
+ test "supress warnings restores verbose" do
99
+ old_verbose = $VERBOSE
100
+ ProxyIO.supress_warnings { raise "error" } rescue nil
101
+ assert_equal old_verbose, $VERBOSE
102
+ end
103
+ end
104
+ end