pdf_spec 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01b0301bfd2cdbf3764c61e5f3ca1158371710c5
4
+ data.tar.gz: 691e9d263d47ab13a08c35808b6b9fc62c364ba4
5
+ SHA512:
6
+ metadata.gz: 4dd4ba4eef8400c6f1352ffe3f5caa1d049c0ce48518cbb703bc7e815cd25be15cca3baa0454ad6f5aae46bab6f40f8d33c41f598916ba13ba93658888c2eeac
7
+ data.tar.gz: bc130fc88ef5a3a9943cca719a2d11cee02c6a14ea84d9a9a36310eadbaeea8fb69d26aa0ddea525d3e3b8313562593edf549222106bfe2b789a0ae64a1e168d
@@ -0,0 +1,6 @@
1
+ .yardoc/*
2
+
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
@@ -0,0 +1 @@
1
+ pdf_spec
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pdf_spec.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'pry'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 TMXCredit, authors Zach Belzer, Sergey Potapov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ PdfSpec
2
+ -------
3
+
4
+ PdfSpec includes rspec matchers to compare the appearance of PDF files.
5
+ This is obviously most useful when you need to verify that you can produce
6
+ a PDF that looks identical to a sample PDF file.
7
+
8
+ # Installation
9
+
10
+ This library depends on the `rmagick` ruby gem.
11
+
12
+ ## Homebrew
13
+
14
+ brew install imagemagick
15
+ brew install ghostscript
16
+
17
+ ## MacPorts
18
+ sudo port install ImageMagick
19
+
20
+ ## Debian (Ubuntu)
21
+
22
+ The following was tested on Ubuntu 11.10 and 12.04.
23
+
24
+ sudo apt-get install libmagickwand-dev
25
+
26
+ ## (TODO) Gentoo
27
+
28
+ # Install libmagickwand
29
+
30
+ # Use
31
+
32
+ To use the matchers in your tests, simple include the Matchers module into RSpec:
33
+
34
+ RSpec.configure do |config|
35
+ config.include(PdfSpec::Matchers)
36
+ end
37
+
38
+ Or include it in certain tests:
39
+
40
+ describe "Testing PDFs" do
41
+ include PdfSpec::Matchers
42
+
43
+ it "should match..."; end
44
+ end
45
+
46
+ Matchers contains the `have_same_pdf_appearance_as` expectation which will render
47
+ out PDF files to pixel buffers in memory and then compare them pixel by pixel.
48
+
49
+
50
+ it "should be the same PDF" do
51
+ source_pdf = File.read("path/to/source")
52
+ expected_pdf = File.read("path/to/expected")
53
+
54
+ source.should have_same_pdf_appearance_as(expected_pdf)
55
+ end
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,7 @@
1
+ require 'RMagick'
2
+
3
+ require 'tempfile'
4
+
5
+ require "pdf_spec/version"
6
+ require "pdf_spec/matchers"
7
+
@@ -0,0 +1,48 @@
1
+ module PdfSpec # :nodoc:
2
+ module Matchers # :nodoc:
3
+ # Class that conforms to RSpec specifications for matchers
4
+ #
5
+ # @param [String] pdf_data PDF content as a Ruby string
6
+ class IdenticalPdfs
7
+ def initialize(pdf_data)
8
+ @expected_pages = pdf_to_pixel_pages(pdf_data)
9
+ end
10
+
11
+ # Compares given PDF data against
12
+ #
13
+ # @param [String] pdf_data PDF content as a Ruby string
14
+ def matches?(pdf_data)
15
+ @target_pages = pdf_to_pixel_pages(pdf_data)
16
+ @target_pages == @expected_pages
17
+ end
18
+
19
+ def failure_message # :nodoc:
20
+ "expected #{@target_pages.inspect} to look the same as #{@expected_pages.inspect}"
21
+ end
22
+
23
+ def negative_failure_message # :nodoc:
24
+ "expected #{@target_pages.inspect} not to look the same as #{@expected_pages.inspect}"
25
+ end
26
+
27
+ # Get array of page pixels. The first level array represents PDF pages,
28
+ # the second level array - pixels.
29
+ #
30
+ # @param [String] pdf_data binary string that represents pdf
31
+ #
32
+ # @return [Array<Array<Integer>>] array of arrays of pixels
33
+ def pdf_to_pixel_pages(pdf_data)
34
+ Magick::ImageList.new.
35
+ from_blob(pdf_data).
36
+ remap { |page| page.export_pixels }
37
+ end
38
+ private :pdf_to_pixel_pages
39
+ end
40
+
41
+ # Compares the pixel by pixel appearance of two strings of PDF data
42
+ #
43
+ # @param [String] expected The expected PDF file contents
44
+ def have_same_pdf_appearance_as(expected)
45
+ IdenticalPdfs.new(expected)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module PdfSpec # :nodoc:
2
+ VERSION = "0.2.0" # :nodoc:
3
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pdf_spec/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pdf_spec"
7
+ s.version = PdfSpec::VERSION
8
+ s.authors = ["TMX Credit", "Zachary Belzer", "Sergey Potapov"]
9
+ s.email = ["rubygems@tmxcredit.com", "zach@tmxcredit.com"]
10
+ s.homepage = "https://github.com/TMXCredit/pdf_spec"
11
+ s.licenses = ["LICENSE"]
12
+ s.summary = %q{RSpec matchers for comparing PDF files}
13
+ s.description = %q{This library includes matchers that use Poppler and Cairo
14
+ to render PDF files as images and compare them by the pixel}
15
+
16
+ s.rubyforge_project = "pdf_spec"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "rake"
26
+
27
+ s.add_runtime_dependency "rmagick", "~> 2.13.0"
28
+ end
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head>
3
+ </head>
4
+ <body>
5
+ The first sample PDF
6
+ </body>
7
+ </html>
Binary file
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <style type="text/css">
4
+ p {
5
+ page-break-before: always;
6
+ }
7
+ </style>
8
+ </head>
9
+ <body>
10
+ The first page
11
+ </body>
12
+ </html>
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head>
3
+ </head>
4
+ <body>
5
+ The second sample PDF
6
+ </body>
7
+ </html>
Binary file
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <style type="text/css">
4
+ p {
5
+ page-break-before: always;
6
+ }
7
+ </style>
8
+ </head>
9
+ <body>
10
+ The first page
11
+ <p>
12
+ The second page
13
+ </p>
14
+ </body>
15
+ </html>
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module PdfSpec
4
+ module Matchers
5
+ describe "IdenticalPdfs" do
6
+ describe "matches?" do
7
+ it "should be true for matching pdfs" do
8
+ path = "#{FIXTURES}/one.pdf"
9
+ first_pdf = File.read("#{FIXTURES}/one.pdf")
10
+ second_pdf = File.read("#{FIXTURES}/one.pdf")
11
+
12
+ matcher = IdenticalPdfs.new(first_pdf)
13
+ matcher.matches?(second_pdf).should be_true
14
+ end
15
+
16
+ it "should be false for differing pdfs" do
17
+ first_pdf = File.read("#{FIXTURES}/one.pdf")
18
+ second_pdf = File.read("#{FIXTURES}/two.pdf")
19
+
20
+ matcher = IdenticalPdfs.new(first_pdf)
21
+ matcher.matches?(second_pdf).should be_false
22
+ end
23
+
24
+ it "should be false for pdfs with a different number of pages" do
25
+ first_pdf = File.read("#{FIXTURES}/one_page.pdf")
26
+ second_pdf = File.read("#{FIXTURES}/two_pages.pdf")
27
+
28
+ matcher = IdenticalPdfs.new(first_pdf)
29
+ matcher.matches?(second_pdf).should be_false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'pdf_spec'
2
+
3
+ FIXTURES = File.expand_path("../fixtures", __FILE__)
4
+
5
+ RSpec.configure do |config|
6
+ config.include(PdfSpec::Matchers)
7
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdf_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - TMX Credit
8
+ - Zachary Belzer
9
+ - Sergey Potapov
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-11-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rmagick
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 2.13.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 2.13.0
57
+ description: |-
58
+ This library includes matchers that use Poppler and Cairo
59
+ to render PDF files as images and compare them by the pixel
60
+ email:
61
+ - rubygems@tmxcredit.com
62
+ - zach@tmxcredit.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - .rspec
69
+ - .ruby-gemset
70
+ - .ruby-version
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - lib/pdf_spec.rb
76
+ - lib/pdf_spec/matchers.rb
77
+ - lib/pdf_spec/version.rb
78
+ - pdf_spec.gemspec
79
+ - spec/fixtures/one.html
80
+ - spec/fixtures/one.pdf
81
+ - spec/fixtures/one_page.html
82
+ - spec/fixtures/one_page.pdf
83
+ - spec/fixtures/two.html
84
+ - spec/fixtures/two.pdf
85
+ - spec/fixtures/two_pages.html
86
+ - spec/fixtures/two_pages.pdf
87
+ - spec/matchers_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: https://github.com/TMXCredit/pdf_spec
90
+ licenses:
91
+ - LICENSE
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project: pdf_spec
109
+ rubygems_version: 2.0.7
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: RSpec matchers for comparing PDF files
113
+ test_files:
114
+ - spec/fixtures/one.html
115
+ - spec/fixtures/one.pdf
116
+ - spec/fixtures/one_page.html
117
+ - spec/fixtures/one_page.pdf
118
+ - spec/fixtures/two.html
119
+ - spec/fixtures/two.pdf
120
+ - spec/fixtures/two_pages.html
121
+ - spec/fixtures/two_pages.pdf
122
+ - spec/matchers_spec.rb
123
+ - spec/spec_helper.rb