class Minitest::Stately::Watcher

Constants

Public Class Methods

new() click to toggle source
# File lib/minitest/stately/watcher.rb, line 4
def initialize
  @watch    = {}
  @run      = []
  @failures = {}

  @results = {}
  @report  = []
end

Public Instance Methods

check_failures(result) click to toggle source
# 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) click to toggle source
# File lib/minitest/stately/watcher.rb, line 22
def fail_if(name,&blk)
  @failures[name] = blk
end
message(result, name, value) click to toggle source
# File lib/minitest/stately/watcher.rb, line 61
def message(result, name, value)
  "#{result.class.name}\##{result.name}: #{name} changed from #{@results[name].inspect} to #{value.inspect}"
end
record(result) click to toggle source
# File lib/minitest/stately/watcher.rb, line 26
def record(result)
  record_changes(result)
  run_blocks()
  check_failures(result)
end
record_changes(result) click to toggle source
# 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 << message(result, name, value)
    end
    @results[name] = value
  end
end
report() click to toggle source
# File lib/minitest/stately/watcher.rb, line 72
def report
  return "" if @report.empty?

  HEADER + @report.join("\n") + "\n\n"
end
run(&blk) click to toggle source
# File lib/minitest/stately/watcher.rb, line 18
def run(&blk)
  @run << blk
end
run_blocks() click to toggle source
# File lib/minitest/stately/watcher.rb, line 42
def run_blocks()
  @run.each do |blk|
    blk.call
  end
end
value_changed?(name, value) click to toggle source
# File lib/minitest/stately/watcher.rb, line 57
def value_changed?(name, value)
  @results[name] != value
end
watch(name, &blk) click to toggle source
# File lib/minitest/stately/watcher.rb, line 13
def watch(name, &blk)
  @watch[name]   = blk
  @results[name] = blk.call(nil)
end