Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdf_matcher-testing

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf_matcher-testing

  • 1.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 30 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc