class CLIntegracon::Diff
Attributes
expected[R]
@return [Pathname]
the expected file
preprocessor[RW]
@return [Proc<(Pathname)->(to_s)>]
the proc, which transforms the files in a better comparable form
produced[R]
@return [Pathname]
the produced file
relative_path[R]
@return [Pathname]
the relative path to the expected file
Public Class Methods
new(expected, produced, relative_path=nil, &preprocessor)
click to toggle source
Init a new diff
@param [Pathname] expected
the expected file
@param [Pathname] produced
the produced file
@param [Pathname] relative_path
the relative path to the expected file
@param [Block<(Pathname)->(to_s)>] preprocessor
the block, which preprocess the files in a better comparable form
# File lib/CLIntegracon/diff.rb, line 39 def initialize(expected, produced, relative_path=nil, &preprocessor) @expected = expected @produced = produced @relative_path = relative_path preprocessor ||= Proc.new { |x| x } #id self.preprocessor = preprocessor end
Public Instance Methods
compares_files?()
click to toggle source
Check if the preprocessed inputs are files or need to be dumped first to temporary files to be compared.
@return [Bool]
# File lib/CLIntegracon/diff.rb, line 60 def compares_files? preprocessed_expected.is_a? Pathname end
each(options = {}, &block)
click to toggle source
Enumerate all lines which differ.
@param [Hash] options
see Diffy#initialize for help.
@return [Diffy::Diff]
# File lib/CLIntegracon/diff.rb, line 84 def each(options = {}, &block) options = { :source => compares_files? ? 'files' : 'strings', :context => 3 }.merge options Diffy::Diff.new(preprocessed_expected.to_s, preprocessed_produced.to_s, options).each &block end
is_equal?()
click to toggle source
Check if the produced output equals the expected
@return [Bool]
whether the expected is equal to the produced
# File lib/CLIntegracon/diff.rb, line 69 def is_equal? @is_equal ||= if compares_files? FileUtils.compare_file(preprocessed_expected, preprocessed_produced) else preprocessed_expected == preprocessed_produced end end
preprocessed_expected()
click to toggle source
# File lib/CLIntegracon/diff.rb, line 47 def preprocessed_expected @preprocessed_expected ||= preprocessor.call(expected) end
preprocessed_produced()
click to toggle source
# File lib/CLIntegracon/diff.rb, line 51 def preprocessed_produced @preprocessed_produced ||= preprocessor.call(produced) end