Class: AvocadoFormatter::RSpec3

Inherits:
Object
  • Object
show all
Defined in:
lib/avocado_formatter/rspec3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ RSpec3

Returns a new instance of RSpec3.



9
10
11
12
13
14
15
16
17
18
# File 'lib/avocado_formatter/rspec3.rb', line 9

def initialize(output)
  @output = output
  @group_level = 0
  @index_offset = 0
  @failed_notifications = []

  @hostname = 'localhost'
  @port = '1336'
  @socket = TCPSocket.open(@hostname, @port)
end

Instance Attribute Details

#failed_notificationsObject (readonly)

See avocado_formatter.rb for formatter registration.



7
8
9
# File 'lib/avocado_formatter/rspec3.rb', line 7

def failed_notifications
  @failed_notifications
end

#outputObject (readonly)

See avocado_formatter.rb for formatter registration.



7
8
9
# File 'lib/avocado_formatter/rspec3.rb', line 7

def output
  @output
end

Instance Method Details

#colorObject



20
21
22
23
24
25
# File 'lib/avocado_formatter/rspec3.rb', line 20

def color
  unless defined?(::RSpec::Core::Formatters::ConsoleCodes)
    require 'rspec/core/formatters/console_codes'
  end
  ::RSpec::Core::Formatters::ConsoleCodes
end

#dump_summary(summary) ⇒ Object



65
66
67
# File 'lib/avocado_formatter/rspec3.rb', line 65

def dump_summary(summary)
  output.puts summary.fully_formatted
end

#example_failed(notification) ⇒ Object



35
36
37
38
# File 'lib/avocado_formatter/rspec3.rb', line 35

def example_failed(notification)
  @failed_notifications << notification
  @socket.puts('failed');
end

#example_group_finished(event) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/avocado_formatter/rspec3.rb', line 49

def example_group_finished(event)
  @group_level -= 1

  if @group_level.zero?
    # print_elapsed_time output, @start_time
    # output.puts

    failed_notifications.each_with_index do |failure, index|
      @socket.puts failure.fully_formatted(@index_offset + index + 1)
    end

    @index_offset += failed_notifications.size
    failed_notifications.clear
  end
end

#example_group_started(event) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/avocado_formatter/rspec3.rb', line 40

def example_group_started(event)
  if @group_level.zero?
    @socket.print "#{event.group.description} "
    @start_time = Time.now
  end

  @group_level += 1
end

#example_passed(notification) ⇒ Object



27
28
29
# File 'lib/avocado_formatter/rspec3.rb', line 27

def example_passed(notification)
  @socket.puts('passed');
end

#example_pending(notification) ⇒ Object



31
32
33
# File 'lib/avocado_formatter/rspec3.rb', line 31

def example_pending(notification)
  @socket.puts('pending');
end

#message(notification) ⇒ Object



74
75
76
# File 'lib/avocado_formatter/rspec3.rb', line 74

def message(notification)
  output.puts notification.message
end

#seed(notification) ⇒ Object



69
70
71
72
# File 'lib/avocado_formatter/rspec3.rb', line 69

def seed(notification)
  return unless notification.seed_used?
  output.puts notification.fully_formatted
end