File: integrity_spec.rb

package info (click to toggle)
ruby-pdf-reader 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,908 kB
  • ctags: 569
  • sloc: ruby: 8,330; makefile: 10
file content (37 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: utf-8

require File.dirname(__FILE__) + "/spec_helper"

require 'yaml'

# This spec just checks that the PDFs in the spec suite are intact.
#
# If the PDFs have been modified in some way (like git mangling the
# line endings) then specs wil fail in confusing ways.
#
# This spec will fail if a new PDF is added to the suite but not
# listed in spec/inhtegrity.yml. After adding the new PDF, be sure to
# run 'rake integrity_yaml'

describe "Spec suite PDFs" do
  it "should be intact" do
    yaml_path = File.expand_path("integrity.yml",File.dirname(__FILE__))
    pdfs_path = File.expand_path("data/**/**.pdf",File.dirname(__FILE__))
    integrity = YAML.load_file(yaml_path)

    Dir.glob(pdfs_path).each do |path|
      relative_path = path[/.+(data\/.+)/,1]
      item = integrity[relative_path]

      # every PDF in the suite MUST be included in the integrity file
      item.should_not be_nil, "#{path} not found in integrity YAML file"

      # every PDF in the suite MUST be the correct number of bytes
      File.size(path).should eql(item[:bytes])

      # every PDF in the suite MUST be unchanged
      md5 = Digest::MD5.hexdigest(File.open(path, "rb") { |f|  f.read })
      md5.should == item[:md5]
    end
  end
end