pdf_matcher 1.0.1 → 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: c72b513695745c25fe76222180e4696e1f193792bcbe5b414ac7566ca6df67e5
4
- data.tar.gz: 7e3733f4f0a62233268d78e539c3bcb122309863aa4d344109668b85f3acdfb5
3
+ metadata.gz: 4b25a11b945dc8e7518398bde01819aa6c7c938eb55d0a337c2ab96d8a39acd6
4
+ data.tar.gz: c8bf17486d738bd1860f9aef05130e1c8937ebe7e64f223ac01730c2f5261235
5
5
  SHA512:
6
- metadata.gz: 19e1830cf927f2674a712036bf180865e2d3b12a1860bf8ee485d18482a21be4be250777dbe45ca349e735b0658317474dbeec0d63f762c12eaadee58bd8b4de
7
- data.tar.gz: 314cdaf0e906a8702a03c9dea1c548318b8415adca85904539e46084260b54524b087f6c3e37ba39ee6764cadf8a76f89cd1cf45bf52a39e0a0cf3274e47c24d
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,19 @@
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
+
11
+ ## 2.0.0
12
+
13
+ ### Breaking Changes
14
+
15
+ - Delete (not keep) the difference PDF when the PDFs are matched [44b05f8](https://github.com/hidakatsuya/pdf_matcher/commit/44b05f8c0df8d2429e3b6c50e2fbb02ed87ee139)
16
+
1
17
  ## 1.0.1
2
18
 
3
19
  ### Bug Fixes
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,16 +81,25 @@ 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.
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
- - [test-unit-pdf_matcher](https://github.com/hidakatsuya/test-unit-pdf_matcher)
102
+ Try [pdf_matcher-testing gem](https://github.com/hidakatsuya/pdf_matcher-testing).
73
103
 
74
104
  ## Contributing
75
105
 
@@ -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
@@ -14,7 +14,18 @@ module PdfMatcher
14
14
  end
15
15
 
16
16
  def match
17
- @result ||= MatchResult.new(match_pdfs, pdf1, pdf2, output_diff_path)
17
+ @result ||= begin
18
+ matched = match_pdfs
19
+
20
+ if matched
21
+ # [NOTE] The diff-pdf command will generate a diff PDF file
22
+ # regardless of the result if the `--output_diff` option is given.
23
+ output_diff_path.unlink if output_diff_path&.exist?
24
+ MatchResult.new(matched, pdf1, pdf2, nil)
25
+ else
26
+ MatchResult.new(matched, pdf1, pdf2, output_diff_path)
27
+ end
28
+ end
18
29
  end
19
30
 
20
31
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PdfMatcher
4
- VERSION = '1.0.1'
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: 1.0.1
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-07 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