Class: Konacha::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/konacha/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Formatter

Returns a new instance of Formatter.



7
8
9
10
# File 'lib/konacha/formatter.rb', line 7

def initialize(io)
  @io = io
  @examples = []
end

Instance Attribute Details

#examplesObject (readonly)

Returns the value of attribute examples.



5
6
7
# File 'lib/konacha/formatter.rb', line 5

def examples
  @examples
end

#ioObject (readonly)

Returns the value of attribute io.



5
6
7
# File 'lib/konacha/formatter.rb', line 5

def io
  @io
end

Instance Method Details

#closeObject



63
64
65
# File 'lib/konacha/formatter.rb', line 63

def close
  io.close if IO === io && io != $stdout
end

#dump_failuresObject



46
47
48
49
50
51
52
# File 'lib/konacha/formatter.rb', line 46

def dump_failures
  failed_examples = examples.select(&:failed?)
  if failed_examples.present?
    io.puts ""
    io.puts(failed_examples.map {|example| failure_message(example)}.join("\n\n"))
  end
end

#dump_pendingObject



38
39
40
41
42
43
44
# File 'lib/konacha/formatter.rb', line 38

def dump_pending
  pending_examples = examples.select(&:pending?)
  if pending_examples.present?
    io.puts ""
    io.puts(pending_examples.map {|example| pending_message(example)}.join("\n\n"))
  end
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object



54
55
56
57
58
59
# File 'lib/konacha/formatter.rb', line 54

def dump_summary(duration, example_count, failure_count, pending_count)
  seconds = "%.2f" % duration
  io.puts ""
  io.puts "Finished in #{seconds} seconds"
  io.puts "#{example_count} examples, #{failure_count} failed, #{pending_count} pending"
end

#example_failed(example) ⇒ Object



21
22
23
24
# File 'lib/konacha/formatter.rb', line 21

def example_failed(example)
  @examples << example
  io.write(with_color('F', :red))
end

#example_group_finished(group) ⇒ Object



31
# File 'lib/konacha/formatter.rb', line 31

def example_group_finished(group); end

#example_group_started(group) ⇒ Object



13
# File 'lib/konacha/formatter.rb', line 13

def example_group_started(group); end

#example_passed(example) ⇒ Object



16
17
18
19
# File 'lib/konacha/formatter.rb', line 16

def example_passed(example)
  @examples << example
  io.write(with_color('.', :green))
end

#example_pending(example) ⇒ Object



26
27
28
29
# File 'lib/konacha/formatter.rb', line 26

def example_pending(example)
  @examples << example
  io.write(with_color('P', :yellow))
end

#example_started(example) ⇒ Object



14
# File 'lib/konacha/formatter.rb', line 14

def example_started(example); end

#seed(seed) ⇒ Object



61
# File 'lib/konacha/formatter.rb', line 61

def seed(seed); end

#start(expected_example_count = nil) ⇒ Object



12
# File 'lib/konacha/formatter.rb', line 12

def start(expected_example_count=nil); end

#start_dumpObject



34
35
36
# File 'lib/konacha/formatter.rb', line 34

def start_dump
  io.puts ""
end

#stopObject



32
# File 'lib/konacha/formatter.rb', line 32

def stop; end