Sha256: ec0b398f6250db047fd7e379e69c6779f57ee64418f5c61986a2b47d077585e1

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'rspec/expectations'

## matcher to validate if all elements in list are equals
RSpec::Matchers.define :all_list_elements_eq do |expected|
  match do |actual|
    actual.each do |i|
      expect(i).to eq(expected)
    end
  end
  failure_message_for_should do |actual|
    "expected that all elements in #{actual} list would be equals #{expected}"
  end
end

RSpec::Matchers.define :visual_match do |expected|
  match do |actual|
    base_path = File.expand_path(".", Dir.pwd) + '/screenshots/'
    file_atual = File.join(base_path, 'current_images/') + actual + '.png'
    file_baseline = File.join(base_path, 'baseline/') + expected + '.png'
    file_diff = File.join(base_path, 'diffs/') + actual + '_diff_' + expected + '.png'
    comparison = IMATCHER.compare(file_atual, file_baseline)
    @score = comparison.score
    if comparison.match? != true
      comparison.difference_image.save(file_diff)
    end
    expect(comparison.match?).to be true
  end
  failure_message_for_should do |actual|
    "expected that two images are equals, but they are #{@score} different"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
magneton-0.2.0 lib/skeleton/features/support/matchers/custom.rb