pdf_matcher 2.0.0 → 2.1.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: 4b25a11b945dc8e7518398bde01819aa6c7c938eb55d0a337c2ab96d8a39acd6
4
+ data.tar.gz: c8bf17486d738bd1860f9aef05130e1c8937ebe7e64f223ac01730c2f5261235
5
5
  SHA512:
6
- metadata.gz: 2ef1a7e18d03c6eb4a3b57777f850866393e0a9be7176e6ba50a33becc1cec9ec077caa2cac5dbc85a18735726984c94a774dd05f6e3ec0d0c72c20a70e89359
7
- data.tar.gz: 761a3295ad8795988e97c0ca7dc019b17814f851401dcc0e247e06a588d3d78a1f5c1b6664f8e6eb5ab23fd9812aa1f2a962db839b145dbed368eee88ec5f298
6
+ metadata.gz: f3b37821e911c44dd6fecb67c7a27bff348ad857e34e358f06a26501267a8d5298fd457bbdebb4e7c442fcb6d26f7bdffa9e11adb55154ee7c018a7394696001
7
+ data.tar.gz: b2b96542029235f9e6a95316660a3faa596477e208d3c082957e35e86bc519197b5ec6988eb3a6f849b4a4137c499696fcd7f1f5e0e91e316f1924db0ee3df4e
@@ -12,12 +12,13 @@ jobs:
12
12
  strategy:
13
13
  matrix:
14
14
  ruby_version:
15
- - 2.6
16
- - 2.7
17
- - 3.0
15
+ - '2.7'
16
+ - '3.0'
17
+ - '3.1'
18
+ - '3.2'
18
19
 
19
20
  steps:
20
- - uses: actions/checkout@v2
21
+ - uses: actions/checkout@v3
21
22
 
22
23
  - uses: hidakatsuya/setup-diff-pdf@v1
23
24
  with:
@@ -32,4 +33,4 @@ jobs:
32
33
  run: bundle install --jobs 4 --retry 3
33
34
 
34
35
  - name: Run Tests
35
- run: bundle exec rake test
36
+ run: xvfb-run -a bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.1.0
2
+
3
+ ### Changes
4
+
5
+ - Drop Ruby 2.6 support
6
+
7
+ ### Bug Fixes
8
+
9
+ - 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.
10
+
1
11
  ## 2.0.0
2
12
 
3
13
  ### 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
+ 2.7, 3.0, 3.1, 3.2
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.1.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('>= 2.7.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.1.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-02-12 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,7 +48,7 @@ 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: 2.7.0
53
52
  required_rubygems_version: !ruby/object:Gem::Requirement
54
53
  requirements:
55
54
  - - ">="
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