Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Rspec content matcher (for files, directories, strings, pat…
…hnames) Implement #fixture_path helper returning pathname object or array of pathnames Implement attach_files specs
- Loading branch information
elmatou
committed
Nov 15, 2011
1 parent
e0ff870
commit 7e75c08
Showing
7 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
/output.spec |
Binary file not shown.
4 changes: 2 additions & 2 deletions
4
spec/fixtures/attach_files/spec.txt → spec/fixtures/attach_files/expect/first.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,5 @@ | |||
Testing pdftk_forms | Testing active_pdftk | ||
https://github.com/tcocca/active_pdftk | https://github.com/tcocca/active_pdftk | ||
|
|
||
This file can be attached to any PDF. | This file can be attached to any PDF. | ||
And any files can be attached to this PDF. | And any files can be attached to this PDF. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
Testing active_pdftk | |||
https://github.com/tcocca/active_pdftk | |||
|
|||
Second attached file !! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
RSpec::Matchers.define :have_the_content_of do |expected| | |||
match do |actual| | |||
sha256_hash_of(actual) == sha256_hash_of(expected) | |||
end | |||
|
|||
failure_message_for_should do |actual| | |||
"expected that #{actual} would have the content of #{expected}" | |||
end | |||
|
|||
failure_message_for_should_not do |actual| | |||
"expected that #{actual} would differ from #{expected}" | |||
end | |||
end | |||
|
|||
#TODO it would be great to implement an inclusion matcher, just for fun. | |||
#RSpec::Matchers.define :include_the_content_of do |expected| | |||
# match do |actual| | |||
# !(sha256_hash_of(expected) & sha256_hash_of(actual)).empty? | |||
# end | |||
#end | |||
|
|||
def sha256_hash_of(entry) | |||
case entry | |||
when File, Tempfile then Digest::SHA256.file(entry.path).hexdigest | |||
when Dir then (entry.entries - ['.', '..']).collect { |filename| sha256_hash_of(Pathname.new(File.join(entry.path, filename))) }.compact.sort | |||
when StringIO then sha256_hash_of(entry.read) | |||
when String then | |||
if entry.size < 256 && (Pathname.new(entry).file? || Pathname.new(entry).directory?) # Would be deprecated in favor of Pathname object | |||
sha256_hash_of(Pathname.new(entry)) | |||
else | |||
Digest::SHA256.hexdigest(entry) | |||
end | |||
when Pathname then | |||
if entry.directory? | |||
sha256_hash_of(Dir.new(entry)) | |||
elsif entry.file? | |||
sha256_hash_of(File.new(entry)) | |||
end | |||
end | |||
end |