class Chance::Test

Attributes

name[RW]

Public Class Methods

new(name, directory) click to toggle source
# File vendor/chance/lib/tester/test.rb, line 7
def initialize(name, directory)
  @directory = directory
  @name = name

  @input = File.join(directory, "input")
  @output = File.join(directory, "output")

  @chance = Chance::Instance.new
end

Public Instance Methods

approve() click to toggle source

Used to overwrite current results due to behavior change

# File vendor/chance/lib/tester/test.rb, line 94
def approve
  setup

  output_files.each {|file|
    if not check_output_for(file)
      puts "Updating file: #{file}"
      File.new(File.join(@output, file), "w").write(output_for(file)) 
    end
  }

  clean
end
check(result, expected, name) click to toggle source
# File vendor/chance/lib/tester/test.rb, line 73
def check(result, expected, name)
  if result == expected
    if Chance::CONFIG[:verbose]
      puts "OK: " + name
    end

    true
  else
    if Chance::CONFIG[:verbose]
      puts "NOT OK: " + name
      puts "GOT:"
      puts result
      puts "EXPECTED:"
      puts expected
    end

    false
  end
end
check_output_for(file) click to toggle source
# File vendor/chance/lib/tester/test.rb, line 68
def check_output_for(file)
  expected = File.new(File.join(@output, file)).read
  return check(output_for(file), expected, file)
end
clean() click to toggle source
# File vendor/chance/lib/tester/test.rb, line 29
def clean
  Chance.remove_all_files
end
output_files() click to toggle source
# File vendor/chance/lib/tester/test.rb, line 43
def output_files
  Dir.glob(File.join(@output, "**/*")).map {|file|
    next if File.directory? file

    file[@output.length + 1..-1]
  }
end
output_for(file) click to toggle source
# File vendor/chance/lib/tester/test.rb, line 51
def output_for(file)
  if file.end_with? ".parsed.css"
    input_file = file[0..-1-".parsed.css".length] + ".css"

    # Create a parser; skip Chance instance.
    parser = Chance::Parser.new(@chance.get_file(input_file)[:content], { :slices => {} })
    parser.parse

    return parser.css

  else
    # assume standard Chance file
    return @chance.output_for(file)
  end

end
run() click to toggle source
# File vendor/chance/lib/tester/test.rb, line 33
def run
  setup

  failures = output_files.count {|file| not check_output_for(file) }

  clean

  return failures
end
setup() click to toggle source

Maps files into Chance

# File vendor/chance/lib/tester/test.rb, line 18
def setup
  Dir.glob(File.join(@input, "**/*")).each {|file|
    next if File.directory? file

    rel = file[@input.length+1..-1]

    Chance.add_file(file)
    @chance.map_file(rel, file)
  }
end