class Fudge::OutputChecker
Task Output Checker
Attributes
checker[R]
formatter[R]
match[R]
pass_block[R]
regex[R]
Public Class Methods
new(checker, formatter)
click to toggle source
# File lib/fudge/output_checker.rb, line 5 def initialize(checker, formatter) @checker = checker @formatter = formatter end
Public Instance Methods
check(output)
click to toggle source
Validates output against initialized checker
# File lib/fudge/output_checker.rb, line 11 def check(output) return true unless checker # We're ok if no output defined extract_matchers matches?(output) && block_passes? end
Private Instance Methods
block_passes?()
click to toggle source
# File lib/fudge/output_checker.rb, line 19 def block_passes? return true unless pass_block # If we've got a callable, call it to check on regex matches result = pass_block.call(match) if success?(result) true else formatter.write {|w| w.error(error_message(result)) } end end
error_message(result)
click to toggle source
# File lib/fudge/output_checker.rb, line 35 def error_message(result) result || "Output matched #{@regex} but condition failed." end
extract_matchers()
click to toggle source
# File lib/fudge/output_checker.rb, line 39 def extract_matchers # Check if we have a callable to parse the regex matches if checker.is_a? Enumerable @regex, @pass_block = checker else @regex = checker end end
matches?(output)
click to toggle source
# File lib/fudge/output_checker.rb, line 48 def matches?(output) # Do regex match and fail if no match return true if (@match = output.match(regex)) formatter.write { |w| w.error( "Output didn't match #{regex}.") } end
success?(result)
click to toggle source
# File lib/fudge/output_checker.rb, line 31 def success?(result) result === true end