pdf_matcher-testing 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +35 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +12 -0
- data/lib/pdf_matcher/testing/assertion.rb +17 -0
- data/lib/pdf_matcher/testing/failure_message.rb +19 -0
- data/lib/pdf_matcher/testing/matcher.rb +35 -0
- data/lib/pdf_matcher/testing/minitest_adapter.rb +14 -0
- data/lib/pdf_matcher/testing/rspec_adapter.rb +9 -0
- data/lib/pdf_matcher/testing/test_unit_adapter.rb +10 -0
- data/lib/pdf_matcher/testing/version.rb +7 -0
- data/pdf_matcher-testing.gemspec +25 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1180934421898ae4c82ed36fdaeb5b1be6d17463e0b7aff3ded1e975a364c59d
|
4
|
+
data.tar.gz: 65694222ad05b8e5ea9c8a0ce093be916b2a22be843f0e6922b46e8df04063b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7d862a85f7d4b2018ced2dd13a919c6273d116403db6ded9268be800fe2c42a08c52d0847e9de96e00fbf3c27d025d7cd0beb68c7b49d1f14be465de32987d5
|
7
|
+
data.tar.gz: 8463c6623b18a2e97a3e9313fb36d2e0a8ed838052f0550ff4653f06c53bdef4317f73386c55b796e35f4773ab61957f29005b928edfa06ffc2aa9db99a30c33
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Test on ruby ${{ matrix.ruby_version }}
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
|
11
|
+
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby_version:
|
15
|
+
- 2.6
|
16
|
+
- 2.7
|
17
|
+
- 3.0
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- uses: hidakatsuya/setup-diff-pdf@v1
|
23
|
+
with:
|
24
|
+
diff-pdf-version: 0.5
|
25
|
+
|
26
|
+
- name: Set up Ruby ${{ matrix.ruby_version }}
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby_version }}
|
30
|
+
|
31
|
+
- name: Install dependencies
|
32
|
+
run: bundle install --jobs 4 --retry 3
|
33
|
+
|
34
|
+
- name: Run Tests
|
35
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Katsuya Hidaka
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# PdfMatcher::Testing
|
2
|
+
|
3
|
+
[![Test](https://github.com/hidakatsuya/pdf_matcher-testing/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/hidakatsuya/pdf_matcher-testing/actions/workflows/test.yml)
|
4
|
+
|
5
|
+
This gem allows testing frameworks such as [Test::Unit](https://github.com/test-unit/test-unit), [RSpec](https://github.com/rspec/rspec) and [Minitest](https://github.com/seattlerb/minitest) to perform PDF matching tests with the [pdf_matcher gem](https://github.com/hidakatsuya/pdf_matcher).
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
This gem works with diff-pdf and pdf_matcher gem. See [the documentation of the pdf_matcher gem](https://github.com/hidakatsuya/pdf_matcher#prerequisites).
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'pdf_matcher-testing', require: false
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install pdf_matcher-testing
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### Test::Unit
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'pdf_matcher/testing/test_unit_adapter'
|
33
|
+
```
|
34
|
+
|
35
|
+
You will be able to use the `assert_match_pdf`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
assert_match_pdf expected_pdf_data, actual_pdf_data
|
39
|
+
assert_match_pdf '/path/to/expected.pdf', '/path/to/actual.pdf'
|
40
|
+
assert_match_pdf Pathname('/path/to/expected.pdf'), Pathname('/path/to/actual.pdf')
|
41
|
+
|
42
|
+
# Generating a difference PDF
|
43
|
+
assert_match_pdf expected_pdf_data, actual_pdf_data, output_diff: '/path/to/diff.pdf'
|
44
|
+
```
|
45
|
+
|
46
|
+
Or, you can enable the assertion manually:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'pdf_matcher/testing/assertion'
|
50
|
+
|
51
|
+
# Enabling globally
|
52
|
+
class Test::Unit::TestCase
|
53
|
+
include PdfMatcher::Testing::Assertion
|
54
|
+
end
|
55
|
+
|
56
|
+
# Enabling individually
|
57
|
+
class FooTest < Test::Unit::TestCase
|
58
|
+
include PdfMatcher::Testing::Assertion
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### Minitest
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
require 'pdf_matcher/testing/minitest_adapter'
|
66
|
+
```
|
67
|
+
|
68
|
+
You will be able to use the `assert_match_pdf` and the `must_match_pdf`:
|
69
|
+
|
70
|
+
Assertion:
|
71
|
+
```ruby
|
72
|
+
assert_match_pdf expected_pdf_data, actual_pdf_data
|
73
|
+
```
|
74
|
+
|
75
|
+
Expectation:
|
76
|
+
```ruby
|
77
|
+
expect(actual_pdf_data).to must_match_pdf(expected_pdf_data)
|
78
|
+
expect('/path/to/actual.pdf').to must_match_pdf('/path/to/expected.pdf')
|
79
|
+
expect(Pathname('/path/to/actual.pdf')).to must_match_pdf(Pathname('/path/to/expected.pdf'))
|
80
|
+
|
81
|
+
# Generating a difference PDF
|
82
|
+
expect(actual_pdf_data).to must_match_pdf(expected_pdf_data, output_diff: '/path/to/diff.pdf')
|
83
|
+
```
|
84
|
+
|
85
|
+
Or, you can setup the assertion manually as described in Test::Unit.
|
86
|
+
|
87
|
+
### RSpec
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require 'pdf_matcher/testing/rspec_adapter'
|
91
|
+
```
|
92
|
+
|
93
|
+
You will be able to use the `match_pdf`:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
expect(actual_pdf_data).to match_pdf(expected_pdf_data)
|
97
|
+
expect('/path/to/actual.pdf').to match_pdf('/path/to/expected.pdf')
|
98
|
+
expect(Pathname('/path/to/actual.pdf')).to match_pdf(Pathname('/path/to/expected.pdf'))
|
99
|
+
|
100
|
+
# Generating a differnce PDF
|
101
|
+
expect(actual_pdf_data).to match_pdf(expected_pdf_data, output_diff: '/path/to/diff.pdf')
|
102
|
+
```
|
103
|
+
|
104
|
+
Or, you can enable the matcher manually:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
require 'pdf_matcher/testing/matcher'
|
108
|
+
|
109
|
+
# Enabling globally
|
110
|
+
RSpec.configure do |config|
|
111
|
+
config.include PdfMatcher::Testing::Matcher
|
112
|
+
end
|
113
|
+
|
114
|
+
# Enabling individually
|
115
|
+
RSpec.describe 'foo' do
|
116
|
+
include PdfMatcher::Testing::Matcher
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
### Configuring diff-pdf command options
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
PdfMatcher.config.diff_pdf_opts = %w(
|
124
|
+
--mark-differences
|
125
|
+
--channel-tolerance=40
|
126
|
+
)
|
127
|
+
```
|
128
|
+
|
129
|
+
See `diff-pdf --help` for the available diff-pdf options.
|
130
|
+
|
131
|
+
## Contributing
|
132
|
+
|
133
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/pdf_matcher-testing.
|
134
|
+
|
135
|
+
## Testing
|
136
|
+
|
137
|
+
```
|
138
|
+
$ bundle install
|
139
|
+
$ bundle exec rake test
|
140
|
+
```
|
141
|
+
|
142
|
+
## License
|
143
|
+
|
144
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb', 'test/**/*_spec.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pdf_matcher'
|
4
|
+
require_relative 'failure_message'
|
5
|
+
|
6
|
+
module PdfMatcher
|
7
|
+
module Testing
|
8
|
+
module Assertion
|
9
|
+
def assert_match_pdf(expected_pdf, actual_pdf, options = nil)
|
10
|
+
output_diff = options&.fetch(:output_diff)
|
11
|
+
failure_message = FailureMessage.build(output_diff)
|
12
|
+
|
13
|
+
assert PdfMatcher.match?(expected_pdf, actual_pdf, output_diff: output_diff), failure_message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PdfMatcher
|
4
|
+
module Testing
|
5
|
+
module FailureMessage
|
6
|
+
BASE_MESSAGE = 'The PDF contents did not match.'
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def build(output_diff = nil)
|
11
|
+
[BASE_MESSAGE, message_for_checking_output_diff(output_diff)].compact.join(' ')
|
12
|
+
end
|
13
|
+
|
14
|
+
def message_for_checking_output_diff(output_diff)
|
15
|
+
output_diff ? "Check #{output_diff} for details of the differences." : nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pdf_matcher'
|
4
|
+
require_relative 'failure_message'
|
5
|
+
|
6
|
+
module PdfMatcher
|
7
|
+
module Testing
|
8
|
+
module Matcher
|
9
|
+
def match_pdf(expected_pdf, output_diff: nil)
|
10
|
+
MatchPdf.new(expected_pdf, output_diff)
|
11
|
+
end
|
12
|
+
|
13
|
+
class MatchPdf
|
14
|
+
include ::RSpec::Matchers::Composable
|
15
|
+
|
16
|
+
def initialize(expected_pdf, output_diff)
|
17
|
+
@expected_pdf = expected_pdf
|
18
|
+
@output_diff = output_diff
|
19
|
+
end
|
20
|
+
|
21
|
+
def matches?(actual_pdf)
|
22
|
+
PdfMatcher.match?(@expected_pdf, actual_pdf, output_diff: @output_diff)
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure_message
|
26
|
+
FailureMessage.build(@output_diff)
|
27
|
+
end
|
28
|
+
|
29
|
+
def description
|
30
|
+
'match the expected pdf'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest'
|
4
|
+
require_relative 'assertion'
|
5
|
+
|
6
|
+
module Minitest
|
7
|
+
class Test
|
8
|
+
include PdfMatcher::Testing::Assertion
|
9
|
+
end
|
10
|
+
|
11
|
+
module Expectations
|
12
|
+
infect_an_assertion :assert_match_pdf, :must_match_pdf
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'lib/pdf_matcher/testing/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'pdf_matcher-testing'
|
5
|
+
spec.version = PdfMatcher::Testing::VERSION
|
6
|
+
spec.authors = ['Katsuya Hidaka']
|
7
|
+
spec.email = ['hidakatsuya@gmail.com']
|
8
|
+
|
9
|
+
spec.description = 'This gem allows testing frameworks such as Test::Unit, RSpec and Minitest to perform PDF matching tests with the pdf_matcher gem.'
|
10
|
+
spec.summary = spec.description
|
11
|
+
spec.homepage = 'https://github.com/hidakatsuya/pdf_matcher-testing'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
+
spec.metadata['changelog_uri'] = 'https://github.com/hidakatsuya/pdf_matcher-testing/blob/main/CHANGELOG.md'
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
|
21
|
+
end
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'pdf_matcher', '>= 1.0.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdf_matcher-testing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Katsuya Hidaka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pdf_matcher
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
description: This gem allows testing frameworks such as Test::Unit, RSpec and Minitest
|
28
|
+
to perform PDF matching tests with the pdf_matcher gem.
|
29
|
+
email:
|
30
|
+
- hidakatsuya@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".github/workflows/test.yml"
|
36
|
+
- ".gitignore"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/pdf_matcher/testing/assertion.rb
|
43
|
+
- lib/pdf_matcher/testing/failure_message.rb
|
44
|
+
- lib/pdf_matcher/testing/matcher.rb
|
45
|
+
- lib/pdf_matcher/testing/minitest_adapter.rb
|
46
|
+
- lib/pdf_matcher/testing/rspec_adapter.rb
|
47
|
+
- lib/pdf_matcher/testing/test_unit_adapter.rb
|
48
|
+
- lib/pdf_matcher/testing/version.rb
|
49
|
+
- pdf_matcher-testing.gemspec
|
50
|
+
homepage: https://github.com/hidakatsuya/pdf_matcher-testing
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/hidakatsuya/pdf_matcher-testing
|
55
|
+
source_code_uri: https://github.com/hidakatsuya/pdf_matcher-testing
|
56
|
+
changelog_uri: https://github.com/hidakatsuya/pdf_matcher-testing/blob/main/CHANGELOG.md
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.6.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.1.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: This gem allows testing frameworks such as Test::Unit, RSpec and Minitest
|
76
|
+
to perform PDF matching tests with the pdf_matcher gem.
|
77
|
+
test_files: []
|