Module: TestServer
- Defined in:
- lib/test_server.rb,
lib/test_server/version.rb
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
- .notify(msg) ⇒ Object
- .run!(options) ⇒ Object
- .serve!(options) ⇒ Object
- .test(options) ⇒ Object
- .with_client(options) ⇒ Object
- .with_server(options) ⇒ Object
Class Method Details
.notify(msg) ⇒ Object
87 88 89 90 |
# File 'lib/test_server.rb', line 87 def notify(msg) require 'terminal-notifier' TerminalNotifier.notify(msg) end |
.run!(options) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/test_server.rb', line 6 def run!() case [:mode] when :serve serve!() when :push test() end end |
.serve!(options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test_server.rb', line 32 def serve!() with_server() do |server| puts "Initializing TestServer with pid #{$$}..." eval [:preload] if [:preload].length > 0 puts "Ready!" loop do conn = server.accept files, _ = conn.recvmsg pid = fork do puts "> Testing files: #{files}" eval [:after_fork] if [:after_fork].length > 0 if files == ":all".freeze all_glob = ENV['ALL_GLOB'] || 'test/**/*_test.rb' Dir.glob(all_glob).each { |f| load f } else files.split(' ').each { |f| load f } end end _, status = Process.wait2(pid) exit_code = status.exitstatus if [:forward_exit_code] conn.sendmsg exit_code.to_s else if exit_code == 0 notify("Tests passed :)") if [:notify_on_pass] else notify("Warning! Tests failed :(") if [:notify_on_fail] end end end end end |
.test(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/test_server.rb', line 15 def test() with_client() do |client| client.sendmsg [:files].join(' ') if [:forward_exit_code] exit_code, _ = client.recvmsg exit_code = exit_code.to_i if exit_code == 0 notify("Tests passed :)") if [:notify_on_pass] else notify("Warning! Tests failed :(") if [:notify_on_fail] end exit(exit_code) end end end |
.with_client(options) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/test_server.rb', line 66 def with_client() if [:remote] yield TCPSocket.new([:host], [:port]) else yield UNIXSocket.new([:sock]) end end |
.with_server(options) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/test_server.rb', line 74 def with_server() if [:remote] yield TCPServer.new([:host], [:port]) else begin `rm #{[:sock]}` if File.exist?([:sock]) yield UNIXServer.new([:sock]) ensure `rm #{[:sock]}` if File.exist?([:sock]) end end end |