Sha256: dffd699192a1812bd1f0a2b56824326ab5f7f0a7984ae928dccccf79b00660d6

Contents?: true

Size: 1.98 KB

Versions: 25

Compression:

Stored size: 1.98 KB

Contents

require 'selenium-webdriver'
require 'nokogiri'
require 'rmagick'

RSpec.describe "compare SASS with LESS screenshots" do
  BASEURL = "http://localhost:9000"
  RESOLUTIONS = [[320, 480], [768, 1024], [1280, 1024]]
  CONTEXTS = %w(less sass)
  TOLERANCE = ENV['TOLERANCE'].to_f || 0.00

  before(:all) { @browser = Selenium::WebDriver.for(:firefox) }

  puts "Starting tests with TOLERANCE=#{TOLERANCE}"
  html = File.read('spec/html/index.html')
  document = Nokogiri::HTML(html)

  document.css(".row a").each do |link|
    file = link['href']
    context "#{file}" do
      title = file.sub('.html', '')
      RESOLUTIONS.each do |w, h|
        it "#{w}x#{h}" do
          @browser.manage.window.resize_to(w, h)
          CONTEXTS.each do |ctx|
            @browser.navigate.to("#{BASEURL}/#{ctx}/patternfly/#{file}")
            @browser.execute_script("
              var style = document.createElement('style');
              style.innerHTML = '* { -moz-animation: none !important; -moz-transition: none !important;';
              document.body.appendChild(style);
            ")
            sleep(1)
            @browser.save_screenshot("spec/results/#{ctx}/#{title}-#{w}x#{h}.png")
          end
          img_less = Magick::Image.read("spec/results/less/#{title}-#{w}x#{h}.png").first
          img_sass = Magick::Image.read("spec/results/sass/#{title}-#{w}x#{h}.png").first

          cols = [img_less.base_columns, img_sass.base_columns].max
          rows = [img_less.base_rows, img_sass.base_rows].max

          img_less.resize_to_fill!(cols, rows)
          img_sass.resize_to_fill!(cols, rows)

          img_diff, diff_rate = img_less.compare_channel img_sass, Magick::MeanAbsoluteErrorMetric, Magick::AllChannels
          img_less.destroy!
          img_sass.destroy!

          img_diff.write("spec/results/#{title}-#{w}x#{h}.png") unless diff_rate <= TOLERANCE
          img_diff.destroy!
          expect(diff_rate).to be <= TOLERANCE
        end
      end
    end
  end

  after(:all) { @browser.quit }
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
patternfly-sass-3.6.0 spec/compare_spec.rb
patternfly-sass-3.5.1 spec/compare_spec.rb
patternfly-sass-3.5.0 spec/compare_spec.rb
patternfly-sass-3.4.0 spec/compare_spec.rb
patternfly-sass-3.3.6 spec/compare_spec.rb
patternfly-sass-3.3.6.pre.alpha spec/compare_spec.rb
patternfly-sass-3.3.5 spec/compare_spec.rb
patternfly-sass-3.3.4 spec/compare_spec.rb
patternfly-sass-3.3.3 spec/compare_spec.rb
patternfly-sass-3.3.2 spec/compare_spec.rb
patternfly-sass-3.3.1 spec/compare_spec.rb
patternfly-sass-3.3.0 spec/compare_spec.rb
patternfly-sass-3.2.0 spec/compare_spec.rb
patternfly-sass-3.1.0 spec/compare_spec.rb
patternfly-sass-2.10.1 spec/compare_spec.rb
patternfly-sass-3.0.0 spec/compare_spec.rb
patternfly-sass-2.10.0 spec/compare_spec.rb
patternfly-sass-2.9.0 spec/compare_spec.rb
patternfly-sass-2.8.0 spec/compare_spec.rb
patternfly-sass-2.7.0 spec/compare_spec.rb