Class: Fivemat::RSpec3

Inherits:
Object
  • Object
show all
Includes:
ElapsedTime
Defined in:
lib/fivemat/rspec3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ElapsedTime

#print_elapsed_time

Constructor Details

#initialize(output) ⇒ RSpec3

Returns a new instance of RSpec3.



8
9
10
11
12
13
# File 'lib/fivemat/rspec3.rb', line 8

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

Instance Attribute Details

#failed_notificationsObject (readonly)

See fivemat.rb for formatter registration.



6
7
8
# File 'lib/fivemat/rspec3.rb', line 6

def failed_notifications
  @failed_notifications
end

#outputObject (readonly)

See fivemat.rb for formatter registration.



6
7
8
# File 'lib/fivemat/rspec3.rb', line 6

def output
  @output
end

Instance Method Details

#colorObject



15
16
17
18
19
20
# File 'lib/fivemat/rspec3.rb', line 15

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

#dump_summary(summary) ⇒ Object



60
61
62
# File 'lib/fivemat/rspec3.rb', line 60

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

#example_failed(notification) ⇒ Object



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

def example_failed(notification)
  @failed_notifications << notification
  output.print color.wrap('F', :failure)
end

#example_group_finished(event) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fivemat/rspec3.rb', line 44

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|
      output.puts failure.fully_formatted(@index_offset + index + 1)
    end

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

#example_group_started(event) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/fivemat/rspec3.rb', line 35

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

  @group_level += 1
end

#example_passed(notification) ⇒ Object



22
23
24
# File 'lib/fivemat/rspec3.rb', line 22

def example_passed(notification)
  output.print color.wrap('.', :success)
end

#example_pending(notification) ⇒ Object



26
27
28
# File 'lib/fivemat/rspec3.rb', line 26

def example_pending(notification)
  output.print color.wrap('*', :pending)
end

#message(notification) ⇒ Object



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

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

#seed(notification) ⇒ Object



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

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