Sha256: 0d6b9d18de67ae347195659f81b4f8209a9749e6eb48da55f1bafdd0f91bf4ae

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

require 'fileutils'

# Usage: expect(renderer.render).to match_binary_asset('pdf/test.pdf')
RSpec::Matchers.define(:match_binary_asset) do |file_name|
  match do |actual_output|
    expected_path = File.join('spec/assets', file_name)
    expected_output = File.binread(expected_path)

    (actual_output == expected_output).tap do |result|
      unless result
        output_path = File.join('tmp/rendered_output', file_name)

        FileUtils.mkdir_p(File.dirname(output_path))
        File.binwrite(output_path, actual_output)
      end
    end
  end

  failure_message do |_actual_output|
    expected_output_path = File.join('spec/assets', file_name)
    actual_output_path = File.join('tmp/rendered_output', file_name)

    "expected output to match '#{expected_output_path}' "\
      "(see #{actual_output_path})"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webtranslateit-payday-1.3.0 spec/support/asset_matchers.rb