Class: AutoBrewster::Screenshot
- Inherits:
-
Object
- Object
- AutoBrewster::Screenshot
- Defined in:
- lib/auto_brewster/screenshot.rb
Instance Attribute Summary collapse
-
#failed_fast ⇒ Object
Returns the value of attribute failed_fast.
-
#path ⇒ Object
Returns the value of attribute path.
-
#screen_widths ⇒ Object
Returns the value of attribute screen_widths.
-
#server ⇒ Object
Returns the value of attribute server.
-
#url_paths ⇒ Object
Returns the value of attribute url_paths.
Instance Method Summary collapse
- #capture(output_directory) ⇒ Object
- #check_source_compare_screens_exist(label, width) ⇒ Object
- #clear_compare_screens ⇒ Object
- #clear_diff_screens ⇒ Object
- #clear_source_screens ⇒ Object
- #compare_captured_screens(failfast = false) ⇒ Object
-
#initialize(server, path, url_paths, screen_widths) ⇒ Screenshot
constructor
A new instance of Screenshot.
Constructor Details
#initialize(server, path, url_paths, screen_widths) ⇒ Screenshot
Returns a new instance of Screenshot.
9 10 11 12 13 14 |
# File 'lib/auto_brewster/screenshot.rb', line 9 def initialize(server, path, url_paths, screen_widths) @server = server @path = path @url_paths = url_paths @screen_widths = screen_widths end |
Instance Attribute Details
#failed_fast ⇒ Object
Returns the value of attribute failed_fast.
3 4 5 |
# File 'lib/auto_brewster/screenshot.rb', line 3 def failed_fast @failed_fast end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/auto_brewster/screenshot.rb', line 3 def path @path end |
#screen_widths ⇒ Object
Returns the value of attribute screen_widths.
3 4 5 |
# File 'lib/auto_brewster/screenshot.rb', line 3 def screen_widths @screen_widths end |
#server ⇒ Object
Returns the value of attribute server.
3 4 5 |
# File 'lib/auto_brewster/screenshot.rb', line 3 def server @server end |
#url_paths ⇒ Object
Returns the value of attribute url_paths.
3 4 5 |
# File 'lib/auto_brewster/screenshot.rb', line 3 def url_paths @url_paths end |
Instance Method Details
#capture(output_directory) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/auto_brewster/screenshot.rb', line 16 def capture(output_directory) @url_paths.each do |label, path| @screen_widths.each do |width| output_path = get_output_path(output_directory, label, width) if File.exist?(output_path) puts "Screenshot already exists for #{label} at #{width}. Skipping..." else puts `phantomjs #{snap_js_path} "#{get_url(path)}" "#{width}" "#{output_path}"` end end end end |
#check_source_compare_screens_exist(label, width) ⇒ Object
55 56 57 58 59 |
# File 'lib/auto_brewster/screenshot.rb', line 55 def check_source_compare_screens_exist(label, width) [get_output_path(:source, label, width), get_output_path(:compare, label, width)].each do |path| raise "Screenshot at #{path} does not exist" unless File.exist?(path) end end |
#clear_compare_screens ⇒ Object
65 66 67 |
# File 'lib/auto_brewster/screenshot.rb', line 65 def clear_compare_screens clear_screenshot_directory(:compare) end |
#clear_diff_screens ⇒ Object
69 70 71 |
# File 'lib/auto_brewster/screenshot.rb', line 69 def clear_diff_screens clear_screenshot_directory(:diff) end |
#clear_source_screens ⇒ Object
61 62 63 |
# File 'lib/auto_brewster/screenshot.rb', line 61 def clear_source_screens clear_screenshot_directory(:source) end |
#compare_captured_screens(failfast = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/auto_brewster/screenshot.rb', line 29 def compare_captured_screens(failfast = false) create_diff_dir failures = 0 @url_paths.each do |label, path| @screen_widths.each do |width| check_source_compare_screens_exist(label, width) source_path = get_output_path(:source, label, width) compare_path = get_output_path(:compare, label, width) diff_path = get_output_path(:diff, label, width) output = `compare -fuzz 20% -metric AE -highlight-color blue #{source_path} #{compare_path} #{diff_path} 2>&1` failures += get_failure_count(output, label, width) if failfast @failed_fast = true exit 1 end end end exit 1 if failures > 0 end |