Class: Minitest::Stately::Watcher
- Inherits:
-
Object
- Object
- Minitest::Stately::Watcher
- Defined in:
- lib/minitest/stately/watcher.rb
Constant Summary collapse
- HEADER =
<<-EOS ****************************** Minitest::Stately Changes!!! ****************************** EOS
Instance Method Summary collapse
- #check_failures(result) ⇒ Object
- #fail_if(name, &blk) ⇒ Object
-
#initialize ⇒ Watcher
constructor
A new instance of Watcher.
- #message(result, name, value) ⇒ Object
- #record(result) ⇒ Object
- #record_changes(result) ⇒ Object
- #report ⇒ Object
- #run(&blk) ⇒ Object
- #run_blocks ⇒ Object
- #value_changed?(name, value) ⇒ Boolean
- #watch(name, &blk) ⇒ Object
Constructor Details
#initialize ⇒ Watcher
Returns a new instance of Watcher.
4 5 6 7 8 9 10 11 |
# File 'lib/minitest/stately/watcher.rb', line 4 def initialize @watch = {} @run = [] @failures = {} @results = {} @report = [] end |
Instance Method Details
#check_failures(result) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/minitest/stately/watcher.rb', line 48 def check_failures(result) failed = [] @failures.each do |name, blk| failed << name if blk.call end result.flunk("#{failed.join(",")}") if failed.any? end |
#fail_if(name, &blk) ⇒ Object
22 23 24 |
# File 'lib/minitest/stately/watcher.rb', line 22 def fail_if(name,&blk) @failures[name] = blk end |
#message(result, name, value) ⇒ Object
61 62 63 |
# File 'lib/minitest/stately/watcher.rb', line 61 def (result, name, value) "#{result.class.name}\##{result.name}: #{name} changed from #{@results[name].inspect} to #{value.inspect}" end |
#record(result) ⇒ Object
26 27 28 29 30 |
# File 'lib/minitest/stately/watcher.rb', line 26 def record(result) record_changes(result) run_blocks() check_failures(result) end |
#record_changes(result) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/minitest/stately/watcher.rb', line 32 def record_changes(result) @watch.each do |name, blk| value = blk.call(result) if value_changed?(name, value) @report << (result, name, value) end @results[name] = value end end |
#report ⇒ Object
72 73 74 75 76 |
# File 'lib/minitest/stately/watcher.rb', line 72 def report return "" if @report.empty? HEADER + @report.join("\n") + "\n\n" end |
#run(&blk) ⇒ Object
18 19 20 |
# File 'lib/minitest/stately/watcher.rb', line 18 def run(&blk) @run << blk end |
#run_blocks ⇒ Object
42 43 44 45 46 |
# File 'lib/minitest/stately/watcher.rb', line 42 def run_blocks() @run.each do |blk| blk.call end end |
#value_changed?(name, value) ⇒ Boolean
57 58 59 |
# File 'lib/minitest/stately/watcher.rb', line 57 def value_changed?(name, value) @results[name] != value end |
#watch(name, &blk) ⇒ Object
13 14 15 16 |
# File 'lib/minitest/stately/watcher.rb', line 13 def watch(name, &blk) @watch[name] = blk @results[name] = blk.call(nil) end |