Class: Checked::Specs

Inherits:
Object show all
Includes:
Term::ANSIColor
Defined in:
lib/Checked/Spec.rb

Instance Method Summary collapse

Constructor Details

#initializeSpecs

Returns a new instance of Specs.



12
13
14
15
# File 'lib/Checked/Spec.rb', line 12

def initialize
  @specs = []
  @print = true
end

Instance Method Details

#dont_printObject



38
39
40
# File 'lib/Checked/Spec.rb', line 38

def dont_print
  @print = false
end


46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/Checked/Spec.rb', line 46

def print
  @specs.each { |pair|
    
    val, msg = pair
    
    if val
      $stdout.print green(msg), "\n"
    else
      $stdout.print red(msg), "\n"
    end
    
  }
end

#print?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/Checked/Spec.rb', line 42

def print?
  @print
end

#spec(val, msg) ⇒ Object



17
18
19
20
21
22
# File 'lib/Checked/Spec.rb', line 17

def spec val, msg
  if to_a.empty?
    at_exit { ::Checked::SPECS.print if !$! && ::Checked::SPECS.print? }
  end
  @specs << [val, msg]
end

#spec!(val, msg) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/Checked/Spec.rb', line 24

def spec! val, msg
  if val
    spec val, msg
  else
    print
    dont_print
    raise Checked::Spec::Fail, red(msg)
  end
end

#to_aObject



34
35
36
# File 'lib/Checked/Spec.rb', line 34

def to_a
  @specs
end