Browse Source

sanity: initial rewrite of sanity testing

dev
Andy Meneely 10 years ago
parent
commit
61afecd95d
  1. 4
      Rakefile
  2. 1
      spec/sanity/.gitignore
  3. 42
      spec/sanity/sanity.html.erb
  4. 42
      spec/sanity/sanity_test.rb
  5. 12
      spec/sanity/tests.yml

4
Rakefile

@ -40,8 +40,8 @@ end
desc 'Run sanity tests without a full rebuild'
task :sanity_only do
require_relative 'spec/samples/sanity.rb'
Sanity.new.run
require_relative 'spec/sanity/sanity_test.rb'
SanityTest.new.run
end
desc 'Run full rebuild with sanity tests'

1
spec/sanity/.gitignore vendored

@ -0,0 +1 @@
sanity.html

42
spec/sanity/sanity.html.erb

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Diff with CSS Example</title>
<style>
body{
/*background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAHElEQVQYlWO4ePFiAzGY4eLFiw0MxIBRhVRRCADsljgKUbBKPgAAAABJRU5ErkJggg==) repeat;*/
}
img{
height: 6in;
}
.diff {
width: 4in;
height: 6in;
background-repeat: none, none;
background-size: contain, contain;
background-blend-mode: difference;
display: inline-block;
}
</style>
</head>
<body>
<% images.each_with_index do |(expected, actual), i| %>
<img src="<%= expected %>"/>
<img src="<%= actual %>"/>
<style>
.mine<%= i %> {
background-image: url(<%= expected %>), url(<%= actual %>);"
}
</style>
<div class="diff mine<%= i %>"/>
<% end %>
</body>
</html>

42
spec/sanity/sanity_test.rb

@ -0,0 +1,42 @@
require 'launchy'
require 'erb'
require 'yaml'
# An pixel-by-pixel comparison of sample images for visual regression testing
class SanityTest
@@ERB = "#{File.expand_path(File.dirname(__FILE__))}/sanity.html.erb"
@@HTML = "#{File.expand_path(File.dirname(__FILE__))}/sanity.html"
@@COMPARES = "#{File.expand_path(File.dirname(__FILE__))}/tests.yml"
@@SAMPLES = "file:///#{File.expand_path("samples/")}"
def images
require 'pp'
comps = YAML.load_file(@@COMPARES)
pp comps
comps.each do | test, data |
pp data
end
[
["#{@@SAMPLES}/images/_images_00_expected.png", "#{@@SAMPLES}/images/_images_00.png"]
]
end
def run
puts @@SAMPLES
puts 'Building sanity test...'
process_erb(File.read(@@ERB))
Launchy.open('file:///' + @@HTML)
puts 'Done.'
end
private
def process_erb(sanity_template)
renderer = ERB.new(sanity_template)
File.open(@@HTML, 'w+') do |html|
html.write(renderer.result(binding))
end
end
end

12
spec/sanity/tests.yml

@ -0,0 +1,12 @@
images:
dir: images
expected: _images_00_expected.png
actual: _images_00.png
text:
dir: text
expected: _text_00_expected.png
actual: _text_00.png
autoscale_font:
dir: autoscale_font
expected: card_00_expected.png
actual: card_00.png
Loading…
Cancel
Save