-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add specs for testing greyscale processing
Pixbuf happens to convert everything to RGB, but other processors are not guaranteed to have such property, thus the additional specs. I've also added a new matcher to make colourspace check easy.
- Loading branch information
Showing
5 changed files
with
56 additions
and
2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'open3' | ||
|
||
# For testing that under a given path resides an image with desired colourspace. | ||
# The colourspace is currently extracted using imagemagick's `identify`, resulting in values like 'gray' or 'srgb' | ||
# According to docs (https://www.imagemagick.org/script/escape.php), it may include number of channels and meta channels | ||
RSpec::Matchers.define :match_colourspace do |expected_colourspace| | ||
match do |tested_path| | ||
raise(ArgumentError, "path #{tested_path} is not a file") unless File.file?(tested_path) | ||
|
||
@colourspace, status = Open3.capture2('identify', '-format', '%[channels]', tested_path) | ||
raise "Failed to read colorspace of #{tested_path}" unless status.success? | ||
|
||
@colourspace == expected_colourspace | ||
end | ||
|
||
failure_message do | ||
"Colourspaces don't match. Expected: #{expected_colourspace}, got: #{@colourspace}" | ||
end | ||
end |