No release in over 3 years
This gem provides assert_match_pdf assertion by PdfMatcher to Test::Unit.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0.0
>= 3.4.0
 Project Readme

PdfMatcher::Testing

Gem Version Test

This gem allows testing frameworks such as Test::Unit, RSpec and Minitest to perform PDF matching tests with the pdf_matcher gem.

Prerequisites

This gem works with diff-pdf and pdf_matcher gem. See the documentation of the pdf_matcher gem.

Installation

Add this line to your application's Gemfile:

gem 'pdf_matcher-testing', require: false

And then execute:

$ bundle install

Or install it yourself as:

$ gem install pdf_matcher-testing

Usage

Test::Unit

require 'pdf_matcher/testing/test_unit_adapter'

You will be able to use the assert_match_pdf:

assert_match_pdf expected_pdf_data, actual_pdf_data
assert_match_pdf '/path/to/expected.pdf', '/path/to/actual.pdf'
assert_match_pdf Pathname('/path/to/expected.pdf'), Pathname('/path/to/actual.pdf')

# Generating a difference PDF
assert_match_pdf expected_pdf_data, actual_pdf_data, output_diff: '/path/to/diff.pdf'

Or, you can enable the assertion manually:

require 'pdf_matcher/testing/assertion'

# Enabling globally
class Test::Unit::TestCase
  include PdfMatcher::Testing::Assertion
end

# Enabling individually
class FooTest < Test::Unit::TestCase
  include PdfMatcher::Testing::Assertion
end

Minitest

require 'pdf_matcher/testing/minitest_adapter'

You will be able to use the assert_match_pdf and the must_match_pdf:

Assertion:

assert_match_pdf expected_pdf_data, actual_pdf_data

Expectation:

_(actual_pdf_data).must_match_pdf(expected_pdf_data)
_('/path/to/actual.pdf').must_match_pdf('/path/to/expected.pdf')
_(Pathname('/path/to/actual.pdf')).must_match_pdf(Pathname('/path/to/expected.pdf'))

# Generating a difference PDF
_(actual_pdf_data).must_match_pdf(expected_pdf_data, output_diff: '/path/to/diff.pdf')

Or, you can setup the assertion manually as described in Test::Unit.

RSpec

require 'pdf_matcher/testing/rspec_adapter'

You will be able to use the match_pdf:

expect(actual_pdf_data).to match_pdf(expected_pdf_data)
expect('/path/to/actual.pdf').to match_pdf('/path/to/expected.pdf')
expect(Pathname('/path/to/actual.pdf')).to match_pdf(Pathname('/path/to/expected.pdf'))

# Generating a differnce PDF
expect(actual_pdf_data).to match_pdf(expected_pdf_data, output_diff: '/path/to/diff.pdf')

Or, you can enable the matcher manually:

require 'pdf_matcher/testing/matcher'

# Enabling globally
RSpec.configure do |config|
  config.include PdfMatcher::Testing::Matcher
end

# Enabling individually
RSpec.describe 'foo' do
  include PdfMatcher::Testing::Matcher
end

Configuring diff-pdf command options

PdfMatcher.config.diff_pdf_opts = %w(
  --mark-differences
  --channel-tolerance=40
)

See diff-pdf --help for the available diff-pdf options.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/pdf_matcher-testing.

Testing

$ bundle install
$ bundle exec rake test

License

The gem is available as open source under the terms of the MIT License.