require 'base64' def calculate_resized_image_b64(resize_str) base_image = MiniMagick::Image.open(File.expand_path("../../fixtures/basic-app/source/images/original.jpg", __dir__)) base_image.resize(resize_str) Base64.strict_encode64(base_image.to_blob) end image10x10 = "")+"\" class=\"image-resized-to10x10\" />" image5x5 = "" srcset20x20 = "" srcset15x15 = "" 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 step %Q{I should see '#{image10x10}'} step %Q{I should see '#{image5x5}'} end Then(/^I should see base64ed thumbnails and srcset of the images$/) do step %Q{I should see '#{image10x10}'} step %Q{I should see '#{image5x5}'} step %Q{I should see '#{srcset20x20}'} step %Q{I should see '#{srcset15x15}'} 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 with image path$/) do # data that won't ever be generated by resizing an actual image cached_10x10_data = "foo" cached_5x5_data = "bar" cached_15x15_data = "hello" cached_20x20_data = "world" cachedimage10x10 = "" cachedimage5x5 = "" cachedsrcset20x20 = "" cachedsrcset15x15 = "" step %Q{I should see '#{cachedimage10x10}'} step %Q{I should see '#{cachedimage5x5}'} step %Q{I should see '#{cachedsrcset20x20}'} step %Q{I should see '#{cachedsrcset15x15}'} 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" cachedimage10x10 = "" cachedimage5x5 = "" step %Q{I should see '#{cachedimage10x10}'} step %Q{I should see '#{cachedimage5x5}'} 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