Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dblooman committed Jul 30, 2014
1 parent ded5525 commit 717ba27
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ shots/
data.txt
.DS_Store
*.swp
Gemfile.lock
8 changes: 1 addition & 7 deletions Rakefile
Expand Up @@ -7,7 +7,6 @@ require 'wraith/spider'
require 'wraith/folder'
require 'wraith/thumbnails'
require 'wraith/compare_images'
require 'wraith/images'
require 'wraith/gallery'

@config = ('config')
Expand All @@ -19,7 +18,7 @@ task :config, [:yaml] do |_t, custom|
Rake::Task['default'].invoke
end

task default: [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :check_images, :crop_images, :compare_images, :generate_thumbnails, :generate_gallery] do
task default: [:reset_shots_folder, :check_for_paths, :setup_folders, :save_images, :crop_images, :compare_images, :generate_thumbnails, :generate_gallery] do
puts 'Done!'
end

Expand Down Expand Up @@ -53,11 +52,6 @@ task :crop_images do
crop.crop_images
end

task :check_images do
image = Wraith::Images.new(@config)
image.files
end

task :generate_thumbnails do
thumbs = Wraith::Thumbnails.new(@config)
thumbs.generate_thumbnails
Expand Down
7 changes: 0 additions & 7 deletions lib/wraith/cli.rb
Expand Up @@ -6,7 +6,6 @@
require 'wraith/folder'
require 'wraith/thumbnails'
require 'wraith/compare_images'
require 'wraith/images'
require 'wraith/gallery'

class Wraith::CLI < Thor
Expand Down Expand Up @@ -41,11 +40,6 @@ def check_for_paths(config_name)
spider = Wraith::Spidering.new(config_name)
spider.check_for_paths
end

def check_images(config_name)
image = Wraith::Images.new(config_name)
image.files
end
end

desc 'save_images [config_name]', 'captures screenshots'
Expand Down Expand Up @@ -85,7 +79,6 @@ def capture(config)
check_for_paths(config)
setup_folders(config)
save_images(config)
check_images(config)
crop_images(config)
compare_images(config)
generate_thumbnails(config)
Expand Down
6 changes: 5 additions & 1 deletion lib/wraith/crop.rb
Expand Up @@ -26,10 +26,14 @@ def crop_images
height_to_crop_to = compare_height
end

Wraith::Wraith.crop_images(image_to_crop, height_to_crop_to)
crop_task(image_to_crop, height_to_crop_to)
end
end

def crop_task(crop, height)
`convert #{crop} -background none -extent 0x#{height} #{crop}`
end

def image_height(image)
File.open(image, 'rb') do |fh|
size = ImageSize.new(fh.read).size
Expand Down
20 changes: 0 additions & 20 deletions lib/wraith/images.rb

This file was deleted.

12 changes: 10 additions & 2 deletions lib/wraith/save_images.rb
Expand Up @@ -39,7 +39,7 @@ def file_names(width, label, domain_label)

def attempt_image_capture(width, url, filename, max_attempts)
max_attempts.times do |i|
wraith.capture_page_image engine, url, width, filename
capture_page_image engine, url, width, filename

return if File.exist? filename

Expand Down Expand Up @@ -80,8 +80,16 @@ def save_images
FileUtils.cp invalid, filename

# Set width of fallback image
wraith.set_image_width(filename, width)
set_image_width(filename, width)
end
end
end

def set_image_width(image, width)
`convert #{image} -background none -extent #{width}x0 #{image}`
end

def capture_page_image(browser, url, width, file_name)
puts `"#{browser}" "#{wraith.phantomjs_options}" "#{wraith.snap_file}" "#{url}" "#{width}" "#{file_name}"`
end
end
6 changes: 5 additions & 1 deletion lib/wraith/thumbnails.rb
Expand Up @@ -15,7 +15,11 @@ def generate_thumbnails

Parallel.each(files, in_processes: Parallel.processor_count) do |filename|
new_name = filename.gsub(/^#{wraith.directory}/, "#{wraith.directory}/thumbnails")
wraith.thumbnail_image(filename, new_name)
thumbnail_image(filename, new_name)
end
end

def thumbnail_image(png_path, output_path)
`convert #{png_path} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
end
end
26 changes: 2 additions & 24 deletions lib/wraith/wraith.rb
Expand Up @@ -84,29 +84,7 @@ def mode
end
end

def capture_page_image(browser, url, width, file_name)
puts `"#{browser}" #{@config['phantomjs_options']} "#{snap_file}" "#{url}" "#{width}" "#{file_name}"`
end

def self.crop_images(crop, height)
# For compatibility with windows file structures switch commenting on the following 2 lines
`convert #{crop} -background none -extent 0x#{height} #{crop}`
# puts `convert #{crop.gsub('/', '\\')} -background none -extent 0x#{height} #{crop.gsub('/', '\\')}`
end

def crop_images(_crop, _height)
self.class.crop_images
end

def set_image_width(image, width)
# For compatibility with windows file structures switch commenting on the following 2 lines
`convert #{image} -background none -extent #{width}x0 #{image}`
# puts `convert #{image.gsub('/', '\\')} -background none -extent #{width}x0 #{image.gsub('/', '\\')}`
end

def thumbnail_image(png_path, output_path)
# For compatibility with windows file structures switch commenting on the following 2 lines
`convert #{png_path} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
# `convert #{png_path.gsub('/', '\\')} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
def phantomjs_options
@config['phantomjs_options']
end
end
7 changes: 4 additions & 3 deletions spec/wraith_spec.rb
Expand Up @@ -12,6 +12,7 @@
Given(:test_image2) { 'shots/test/test2.png' }
Given(:diff_image) { 'shots/test/test_diff.png' }
Given(:data_txt) { 'shots/test/test.txt' }
Given(:saving) { Wraith::SaveImages.new(config_name) }

When(:wraith) { Wraith::Wraith.new(config_name) }
Then { wraith.is_a? Wraith::Wraith }
Expand All @@ -31,7 +32,7 @@
# capture_page_image
When do
wraith.engine.each do |_type, engine|
wraith.capture_page_image(engine, test_url1, 320, test_image1)
saving.capture_page_image(engine, test_url1, 320, test_image1)
end
end
When(:image_size) { ImageSize.path(test_image1).size }
Expand All @@ -41,8 +42,8 @@
context 'When comparing images' do
When(:diff_image_size) do
wraith.engine.each do |_type, engine|
wraith.capture_page_image(engine, test_url1, 320, test_image1)
wraith.capture_page_image(engine, test_url2, 320, test_image2)
saving.capture_page_image(engine, test_url1, 320, test_image1)
saving.capture_page_image(engine, test_url2, 320, test_image2)
end
Wraith::CropImages.new(config_name).crop_images
Wraith::CompareImages.new(config_name).compare_task(test_image1, test_image2, diff_image, data_txt)
Expand Down

0 comments on commit 717ba27

Please sign in to comment.