Class: RSpecQueue::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_queue/worker.rb

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



6
7
8
9
10
11
12
13
# File 'lib/rspec_queue/worker.rb', line 6

def initialize
  @server_socket = ENV["RSPEC_QUEUE_SERVER_ADDRESS"]

  socket = UNIXSocket.open(@server_socket)
  socket.puts "REGISTER"

  @uuid = socket.gets.to_s.strip
end

Instance Method Details

#current_exampleObject



27
28
29
# File 'lib/rspec_queue/worker.rb', line 27

def current_example
  @example_group_key
end

#finish(reporter) ⇒ Object



31
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
# File 'lib/rspec_queue/worker.rb', line 31

def finish(reporter)
  socket = UNIXSocket.open(@server_socket)
  socket.puts "FINISH"

  message = socket.gets.to_s.strip

  if (message == "GET_UUID")
    socket.puts @uuid
  else
    puts "warn"
  end

  message = socket.gets.to_s.strip

  # serialize the rspec reporter results back to the server
  if (message == "GET_RESULTS")
    results = reporter.examples.map { |e|
      {
        location: e.[:location],
        status: e.[:execution_result].status,
        run_time: e.[:execution_result].run_time
      }
    }

    socket.puts results.to_json
  else
    puts "warn"
  end
end

#has_work?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec_queue/worker.rb', line 15

def has_work?
  socket = UNIXSocket.open(@server_socket)
  socket.puts "GET_WORK"
  message = socket.gets.to_s.strip

  if message == "SHUT_DOWN"
    false
  else
    @example_group_key = message
  end
end