PdfMatcher::Testing
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')
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'
class Test::Unit::TestCase
include PdfMatcher::Testing::Assertion
end
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'))
_(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'))
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'
RSpec.configure do |config|
config.include PdfMatcher::Testing::Matcher
end
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.