pdf_matcher 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a11245a6de1b19f44ca33ac182e325657ac5662696958ff637a63c5a7a0ee50c
4
- data.tar.gz: 3ce202dff0306a6fb81f16f83efe2a2fdf64cac597a815eb6713f656e4e1ef99
3
+ metadata.gz: 3ac5a54cf936002cdbb8fe08c77e9d6efaa9f4ba2f8cad1e923e5d17807634f0
4
+ data.tar.gz: 564c3f2732ec1f014cc49f8617be731e6c26f19e531b15d848d6c18e20b7653e
5
5
  SHA512:
6
- metadata.gz: 2ef1a7e18d03c6eb4a3b57777f850866393e0a9be7176e6ba50a33becc1cec9ec077caa2cac5dbc85a18735726984c94a774dd05f6e3ec0d0c72c20a70e89359
7
- data.tar.gz: 761a3295ad8795988e97c0ca7dc019b17814f851401dcc0e247e06a588d3d78a1f5c1b6664f8e6eb5ab23fd9812aa1f2a962db839b145dbed368eee88ec5f298
6
+ metadata.gz: cf3ce95858ca3f4dba1d3f3f6002583a869fc5bf17e92141e2320bbf55d76839cf5603941019636f1932f7b5c7741c6c06ee681f5e6b690d08d50f70c4255c09
7
+ data.tar.gz: 160fca6ba03dceb3c155c35a7353d0dc70ce0b237195134a8862e763c0e36c0acaeaa6d182641209d6c6041de666b3475cf83e909f00cbfeb8ced13fc17b02ce
@@ -1,35 +1,38 @@
1
1
  name: Test
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - 'dev**'
8
+ pull_request:
4
9
 
5
10
  jobs:
6
11
  test:
7
12
  name: Test on ruby ${{ matrix.ruby_version }}
8
- runs-on: ubuntu-latest
9
13
 
10
- if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
14
+ runs-on: ubuntu-latest
11
15
 
12
16
  strategy:
13
17
  matrix:
14
18
  ruby_version:
15
- - 2.6
16
- - 2.7
17
- - 3.0
19
+ - '3.0'
20
+ - '3.1'
21
+ - '3.2'
22
+ - '3.3'
18
23
 
19
24
  steps:
20
- - uses: actions/checkout@v2
25
+ - uses: actions/checkout@v4
21
26
 
22
- - uses: hidakatsuya/setup-diff-pdf@v1
27
+ - uses: hidakatsuya/action-setup-diff-pdf@v1
23
28
  with:
24
- diff-pdf-version: 0.5
29
+ diff-pdf-version: '0.5'
25
30
 
26
31
  - name: Set up Ruby ${{ matrix.ruby_version }}
27
32
  uses: ruby/setup-ruby@v1
28
33
  with:
29
34
  ruby-version: ${{ matrix.ruby_version }}
30
-
31
- - name: Install dependencies
32
- run: bundle install --jobs 4 --retry 3
35
+ bundler-cache: true
33
36
 
34
37
  - name: Run Tests
35
- run: bundle exec rake test
38
+ run: xvfb-run -a bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## main (Unreleased)
2
+
3
+ ## 2.2.0
4
+
5
+ ### Changes
6
+
7
+ - Drop Ruby2.7 support
8
+
9
+ ## 2.1.0
10
+
11
+ ### Changes
12
+
13
+ - Drop Ruby 2.6 support
14
+
15
+ ### Bug Fixes
16
+
17
+ - Fixes an issue where it would appear diff-pdf ran successfully but actually returned an erroneous exit code. Now raises an error if this occurs.
18
+
1
19
  ## 2.0.0
2
20
 
3
21
  ### Breaking Changes
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gem 'rake'
6
6
  gem 'test-unit'
7
7
  gem 'test-unit-rr'
8
8
  gem 'prawn'
9
+ gem 'matrix'
data/README.md CHANGED
@@ -15,7 +15,7 @@ Note that you can install it with [hidakatsuya/setup-diff-pdf](https://github.co
15
15
 
16
16
  ### Supported Ruby Versions
17
17
 
18
- 2.6, 2.7, 3.0
18
+ 3.0, 3.1, 3.2, 3.3
19
19
 
20
20
  ## Installation
21
21
 
@@ -35,22 +35,43 @@ Or install it yourself as:
35
35
 
36
36
  ## Usage
37
37
 
38
+ ### PdfMatcher.match?
39
+
40
+ Returns true if the PDFs match, false otherwise.
41
+
42
+ ```ruby
43
+ PdfMatcher.match?(pdf_a_data, pdf_b_data)
44
+ PdfMatcher.match?('/path/to/a.pdf', '/path/to/b.pdf')
45
+ PdfMatcher.match?(Pathname('/path/to/a.pdf'), Pathname('/path/to/b.pdf'))
46
+ ```
47
+
48
+ #### `output_diff` option:
49
+
50
+ If the PDFs do not match, a difference PDF file will be generated at the path specified.
51
+
38
52
  ```ruby
39
- require 'pdf_matcher'
53
+ PdfMatcher.match?(pdf_a_data, pdf_b_data, output_diff: '/path/to/diff.pdf')
54
+ ```
40
55
 
41
- PdfMatcher.match?(pdf_a, pdf_b) #=> boolean
56
+ #### `diff_pdf_opts` option:
42
57
 
43
- PdfMatcher.match?('/path/to/a.pdf', '/path/to/b.pdf') #=> boolean
44
- PdfMatcher.match?(Pathname('/path/to/a.pdf'), Pathname('/path/to/b.pdf')) #=> boolean
58
+ The specified values will be set as options for the `diff-pdf` command.
45
59
 
46
- PdfMatcher.match?(pdf_a, pdf_b, output_diff: '/path/to/diff.pdf') #=> boolean
47
- PdfMatcher.match?(pdf_a, pdf_b, diff_pdf_opts: ['--dpi=300']) #=> boolean
60
+ ```ruby
61
+ PdfMatcher.match?(pdf_a_data, pdf_b_data, diff_pdf_opts: ['--mark-differences', '--dpi=600'])
62
+ ```
48
63
 
64
+ ### PdfMatcher.match
65
+
66
+ Returns the PDF match result as a `PdfMatcher::MatchResult` object.
67
+
68
+ ```ruby
49
69
  result = PdfMatcher.match(
50
70
  pdf_a, pdf_b,
51
- output_diff: nil, # or '/path/to/diff.pdf' or Pathname('/path/to/diff.pdf')
52
- diff_pdf_opts: nil # or ['--dpi=300']
71
+ output_diff: nil,
72
+ diff_pdf_opts: nil
53
73
  )
74
+
54
75
  result.matched? #=> boolean
55
76
 
56
77
  # Returns nil if pdf data is passed, otherwise returns path as Pathname.
@@ -60,13 +81,22 @@ result.pdf2_path #=> Pathname or nil
60
81
  result.pdf1_data #=> "%PDF-..."
61
82
  result.pdf2_data #=> "%PDF-..."
62
83
 
63
- # Returns nil if the output_diff parameter is nil or the PDFs are matched.
84
+ # Returns nil if the output_diff parameter is nil or the PDFs do not match.
64
85
  result.diff_pdf_path #=> Pathname or nil
65
86
  result.diff_pdf_data #=> "%PDF-..." or nil
87
+ ```
66
88
 
67
- PdfMatcher.config.diff_pdf_opts = ['--dpi=300']
89
+ ### Configuring the default options for the diff-pdf command
90
+
91
+ ```ruby
92
+ PdfMatcher.config.diff_pdf_opts = %w(
93
+ --mark-differences
94
+ --channel-tolerance=40
95
+ )
68
96
  ```
69
97
 
98
+ See `diff-pdf --help` for available options of the diff-pdf.
99
+
70
100
  ## Use in Testing Frameworks
71
101
 
72
102
  Try [pdf_matcher-testing gem](https://github.com/hidakatsuya/pdf_matcher-testing).
@@ -84,8 +114,8 @@ $ bundle exec rake test
84
114
  However, this gem requires diff-pdf. You can install it locally or use a docker container.
85
115
 
86
116
  ```
87
- $ docker build -t pdf_matcher:latest .
88
- $ docker run -v $PWD:/src:cached -it pdf_matcher bash
117
+ $ docker pull ghcr.io/hidakatsuya/ruby-with-diff-pdf:3.2
118
+ $ docker run -v $PWD:/src:cached -it ghcr.io/hidakatsuya/ruby-with-diff-pdf bash
89
119
 
90
120
  > src# bundle install
91
121
  > src# bundle exec rake test
@@ -94,7 +124,7 @@ $ docker run -v $PWD:/src:cached -it pdf_matcher bash
94
124
  Or, you can run tests instantlly like this:
95
125
 
96
126
  ```
97
- $ docker run --rm -v $PWD:/src -it pdf_matcher bash -c "bundle install && bundle exec rake test"
127
+ $ docker run --rm -v $PWD:/src -it ghcr.io/hidakatsuya/ruby-with-diff-pdf bash -c "bundle install && bundle exec rake test"
98
128
  ```
99
129
 
100
130
 
@@ -19,12 +19,28 @@ module PdfMatcher
19
19
  end
20
20
  end
21
21
 
22
+ class UnknownDiffPdfExitCode < StandardError
23
+ def initialize(code)
24
+ super "pdf_matcher did not recognize the exit code #{code} from the diff-pdf command, " \
25
+ 'this probably means there is a problem with your installed version of diff-pdf.'
26
+ end
27
+ end
28
+
22
29
  def initialize
23
30
  verify_available!
24
31
  end
25
32
 
26
33
  def exec(pdf1_path, pdf2_path, output_diff: nil, options: nil)
27
- system("diff-pdf #{build_options(output_diff, options).join(' ')} #{pdf1_path} #{pdf2_path}")
34
+ `diff-pdf #{build_options(output_diff, options).join(' ')} #{pdf1_path} #{pdf2_path} > /dev/null 2>&1`
35
+
36
+ case $?.exitstatus
37
+ when 0
38
+ true
39
+ when 1
40
+ false
41
+ else
42
+ raise UnknownDiffPdfExitCode, $?.exitstatus
43
+ end
28
44
  end
29
45
 
30
46
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PdfMatcher
4
- VERSION = '2.0.0'
4
+ VERSION = '2.2.0'
5
5
  end
data/pdf_matcher.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = 'PdfMatcher is a gem to compare two PDFs and output the differences using diff-pdf'
11
11
  spec.homepage = 'https://github.com/hidakatsuya/pdf_matcher'
12
12
  spec.license = 'MIT'
13
- spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
14
14
 
15
15
  spec.metadata['homepage_uri'] = spec.homepage
16
16
  spec.metadata['source_code_uri'] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-10 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PdfMatcher is a gem to compare two PDFs and output the differences using
14
14
  diff-pdf
@@ -22,7 +22,6 @@ files:
22
22
  - ".gitignore"
23
23
  - CHANGELOG.md
24
24
  - CODE_OF_CONDUCT.md
25
- - Dockerfile
26
25
  - Gemfile
27
26
  - LICENSE.txt
28
27
  - README.md
@@ -49,14 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
48
  requirements:
50
49
  - - ">="
51
50
  - !ruby/object:Gem::Version
52
- version: 2.6.0
51
+ version: 3.0.0
53
52
  required_rubygems_version: !ruby/object:Gem::Requirement
54
53
  requirements:
55
54
  - - ">="
56
55
  - !ruby/object:Gem::Version
57
56
  version: '0'
58
57
  requirements: []
59
- rubygems_version: 3.1.6
58
+ rubygems_version: 3.4.6
60
59
  signing_key:
61
60
  specification_version: 4
62
61
  summary: A gem to compare two PDFs and output the differences using diff-pdf
data/Dockerfile DELETED
@@ -1,18 +0,0 @@
1
- FROM ruby:3.0.1
2
-
3
- RUN apt-get update -qq && apt-get install -y build-essential xvfb
4
-
5
- WORKDIR /tmp
6
-
7
- RUN apt-get install -y libpoppler-glib-dev poppler-utils libwxgtk3.0-dev && \
8
- curl -L https://github.com/vslavik/diff-pdf/archive/master.tar.gz -o diff-pdf-master.tar.gz && \
9
- tar zxf diff-pdf-master.tar.gz && \
10
- cd diff-pdf-master && \
11
- ./bootstrap && \
12
- ./configure && \
13
- make && make install
14
-
15
- RUN mkdir /src
16
-
17
- WORKDIR /src
18
- VOLUME /src