Class: Specjour::Printer

Inherits:
Object
  • Object
show all
Includes:
Protocol
Defined in:
lib/specjour/printer.rb

Constant Summary collapse

RANDOM_PORT =
0

Constants included from Protocol

Specjour::Protocol::TERMINATOR, Specjour::Protocol::TERMINATOR_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Protocol

#dump_object, #load_object

Constructor Details

#initializePrinter

Returns a new instance of Printer.



10
11
12
13
14
15
16
17
18
19
# File 'lib/specjour/printer.rb', line 10

def initialize
  @host = "0.0.0.0"
  @server_socket = TCPServer.new(@host, RANDOM_PORT)
  @port = @server_socket.addr[1]
  @profiler = {}
  @clients = {}
  @tests_to_run = []
  @example_size = 0
  self.examples_complete = 0
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



7
8
9
# File 'lib/specjour/printer.rb', line 7

def clients
  @clients
end

#example_sizeObject

Returns the value of attribute example_size.



8
9
10
# File 'lib/specjour/printer.rb', line 8

def example_size
  @example_size
end

#examples_completeObject

Returns the value of attribute examples_complete.



8
9
10
# File 'lib/specjour/printer.rb', line 8

def examples_complete
  @examples_complete
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/specjour/printer.rb', line 7

def port
  @port
end

#profilerObject

Returns the value of attribute profiler.



8
9
10
# File 'lib/specjour/printer.rb', line 8

def profiler
  @profiler
end

#tests_to_runObject

Returns the value of attribute tests_to_run.



8
9
10
# File 'lib/specjour/printer.rb', line 8

def tests_to_run
  @tests_to_run
end

Instance Method Details

#exit_statusObject



47
48
49
# File 'lib/specjour/printer.rb', line 47

def exit_status
  reporters.all? {|r| r.exit_status == true}
end

#startObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/specjour/printer.rb', line 21

def start
  fds = [@server_socket]
  catch(:stop) do
    while true
      reads = select(fds).first
      reads.each do |socket_being_read|
        if socket_being_read == @server_socket
          client_socket = @server_socket.accept
          fds << client_socket
          clients[client_socket] = Connection.wrap(client_socket)
        elsif socket_being_read.eof?
          socket_being_read.close
          fds.delete(socket_being_read)
          clients.delete(socket_being_read)
          disconnecting
        else
          serve(clients[socket_being_read])
        end
      end
    end
  end
ensure
  stopping
  fds.each {|c| c.close}
end