class AssertFile

assert-file

Example1:

es = AssertFile.new("testdata/shorten-test.e")
el = AssertFile.new("testdata/shorten-test.el")
system "shorten.rb -l #{el} -e #{es}  testdata/shorten-test-input.e"
assert_file(es)
assert_file(el)

Example2:

assert_file(:expected=>expected, :actual=>actual, :no_remove=>true)

Example3:

AssertFile.transaction(expected) {|asf|
  system "foo input > #{asf}"
}

Attributes

actual[RW]
diff[RW]
expected[RW]
no_remove[RW]

Public Class Methods

basedir=(basedir) click to toggle source
# File lib/el4r/el4r-sub.rb, line 308
def self.basedir=(basedir)
  @@basedir = basedir
end
new(arg) click to toggle source

new(“expected_filename”) new(:expeced=>“expected_filename”, :actual=>“actual_filename”) new(:expeced=>“expected_filename”, :actual=>“actual_filename”, :diff=>“diff”)

# File lib/el4r/el4r-sub.rb, line 335
def initialize(arg)
  require 'test/unit'

  case arg
  when String               # expected
    @expected = arg
    @actual = arg+".actual"
    @diff = arg+".diff"
  when Hash
    @basedir = arg[:basedir]
    @expected = arg[:expected]
    @no_remove = arg[:no_remove]

    @actual = arg[:actual] || (@expected+".actual")
    @diff = arg[:diff] || (@expected+".diff")
  else
    raise TypeError, "AssertFile.new: must be String or Hash."
  end
  @basedir ||= @@basedir
  FileUtils.mkdir_p @basedir if @basedir
  @expected = pathconv(@expected)
  @actual = pathconv(@actual)
  @diff = pathconv(@diff)
end
transaction(*args) { |assert_files| ... } click to toggle source
# File lib/el4r/el4r-sub.rb, line 312
def self.transaction(*args, &block)
  if block_given?
    testcase = eval("self", block)
    assert_files = args.map{|x| new(x) }

    if @@basedir
      Dir.chdir(@@basedir) { yield assert_files }
    else
      yield(assert_files)
    end
    assert_files.each{|asf| testcase.assert_file(asf)}
  else
    raise ArgumentError, "must have block"
  end
end

Public Instance Methods

make_diff() click to toggle source
# File lib/el4r/el4r-sub.rb, line 374
def make_diff
  system "diff -u #{expected} #{actual} | tee #{diff}"
end
pathconv(path) click to toggle source
# File lib/el4r/el4r-sub.rb, line 361
def pathconv(path)
  if @basedir
    File.expand_path(path, @basedir)
  else
    path
  end
end
to_s() click to toggle source
# File lib/el4r/el4r-sub.rb, line 378
def to_s
  actual
end
Also aliased as: to_str
to_str()
Alias for: to_s