Class: Checked::Specs
- Includes:
- Term::ANSIColor
- Defined in:
- lib/Checked/Spec.rb
Instance Method Summary collapse
- #dont_print ⇒ Object
-
#initialize ⇒ Specs
constructor
A new instance of Specs.
- #print ⇒ Object
- #print? ⇒ Boolean
- #spec(val, msg) ⇒ Object
- #spec!(val, msg) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Specs
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_print ⇒ Object
38 39 40 |
# File 'lib/Checked/Spec.rb', line 38 def dont_print @print = false end |
#print ⇒ Object
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
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_a ⇒ Object
34 35 36 |
# File 'lib/Checked/Spec.rb', line 34 def to_a @specs end |