Class: RSpec::By::Formatter

Inherits:
Core::Formatters::DocumentationFormatter
  • Object
show all
Defined in:
lib/rspec/by/formatter.rb

Defined Under Namespace

Classes: Bullet

Constant Summary collapse

RIGHT_MARGIN =
80

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Returns a new instance of Formatter.



22
23
24
25
26
# File 'lib/rspec/by/formatter.rb', line 22

def initialize(output)
  super(output)
  @failed_examples = []
  @bullets = [Bullet.new('', true)]
end

Instance Method Details

#bullet_end(color = :white) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/rspec/by/formatter.rb', line 82

def bullet_end(color = :white)
  bullet = @bullets.pop
  if bullet.nested?
    bullet.message = ''
  end
  offset = RIGHT_MARGIN - bullet.offset
  output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(bullet.delta_t.rjust(offset, ' '), color)
end

#bullet_start(message, color = :white) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rspec/by/formatter.rb', line 70

def bullet_start(message, color = :white)
  unless current_bullet.nested?
    offset = RIGHT_MARGIN - current_bullet.offset
    output.print RSpec::Core::Formatters::ConsoleCodes.wrap(current_bullet.delta_t.rjust(offset, ' '), color)
    output.puts ''
    current_bullet.nest
  end
  res = indent message
  output.print RSpec::Core::Formatters::ConsoleCodes.wrap(res, color)
  @bullets.push(Bullet.new(res))
end

#by_ended(message) ⇒ Object



54
55
56
# File 'lib/rspec/by/formatter.rb', line 54

def by_ended(message)
  bullet_end(:cyan)
end

#by_started(message) ⇒ Object



50
51
52
# File 'lib/rspec/by/formatter.rb', line 50

def by_started message
  bullet_start(message, :cyan)
end

#current_bulletObject



66
67
68
# File 'lib/rspec/by/formatter.rb', line 66

def current_bullet
  @bullets.last
end

#current_indentationObject



62
63
64
# File 'lib/rspec/by/formatter.rb', line 62

def current_indentation
  '  ' * (@bullets.size - 1)
end

#example_failed(failure) ⇒ Object



44
45
46
47
48
# File 'lib/rspec/by/formatter.rb', line 44

def example_failed(failure)
  @failed_examples << failure.example
  output.puts failure.fully_formatted(@failed_examples.size)
  bullet_end
end

#example_group_finished(_notification) ⇒ Object



32
33
34
# File 'lib/rspec/by/formatter.rb', line 32

def example_group_finished(_notification)
  @bullets.pop
end

#example_group_started(notification) ⇒ Object



28
29
30
# File 'lib/rspec/by/formatter.rb', line 28

def example_group_started(notification)
  bullet_start(notification.group.description)
end

#example_passed(passed) ⇒ Object



40
41
42
# File 'lib/rspec/by/formatter.rb', line 40

def example_passed(passed)
  bullet_end(:success)
end

#example_started(notification) ⇒ Object



36
37
38
# File 'lib/rspec/by/formatter.rb', line 36

def example_started(notification)
  bullet_start(notification.example.description)
end

#indent(message) ⇒ Object



58
59
60
# File 'lib/rspec/by/formatter.rb', line 58

def indent message
  "#{current_indentation}#{message}"
end