require 'base64'
Given(/^there is no cache directory yet$/) do
if directory? MiddlemanSimpleThumbnailer::Extension.config.cache_dir
remove MiddlemanSimpleThumbnailer::Extension.config.cache_dir
end
end
Then(/^I should see base64ed thumbnails of the images$/) do
image10x10 = ""
image5x5 = ""
step %Q{I should see '#{image10x10}'}
step %Q{I should see '#{image5x5}'}
end
Then(/^the cache directory should exist (?:at "([^"]+)" )?with the following files$/) do |cache_dir, files|
cache_dir ||= MiddlemanSimpleThumbnailer::Extension.config.cache_dir
check_directory_presence([cache_dir], true)
cd cache_dir
files.raw.map{|file_row| file_row[0]}.each { |f| expect(f).to be_existing_file }
end
Then(/^I should see base64ed data of the cached thumbnails$/) do
# data that won't ever be generated by resizing an actual image
cached_10x10_data = "foo"
cached_5x5_data = "bar"
image10x10 = ""
image5x5 = ""
step %Q{I should see '#{image10x10}'}
step %Q{I should see '#{image5x5}'}
end
Then(/^the following images should exist:$/) do |table|
table.hashes.each do |row|
in_current_dir do
image = MiniMagick::Image.open(row["filename"])
expect(image.dimensions).to eq row["dimensions"].split("x").map(&:to_i)
end
end
end