class ScreenshotMaker
Attributes
basedir[RW]
Public Class Methods
new(basedir)
click to toggle source
# File lib/acceptance_test/screenshot_maker.rb, line 4 def initialize basedir @basedir = basedir end
Public Instance Methods
make(page, options)
click to toggle source
# File lib/acceptance_test/screenshot_maker.rb, line 8 def make page, options FileUtils.mkdir_p basedir unless File.exist? basedir file_path = options[:file_path] name = screenshot_name(build_name(file_path), options[:line_number]) path = File.expand_path("#{basedir}/#{name}") page.save_screenshot(path) end
screenshot_url(options)
click to toggle source
# File lib/acceptance_test/screenshot_maker.rb, line 19 def screenshot_url options file_path = options[:file_path] if options[:screenshot_url_base] name = screenshot_name(build_name(file_path), options[:line_number]) "#{options[:screenshot_url_base]}/#{name}" else name = screenshot_name(build_name(file_path), options[:line_number]) path = File.expand_path("#{basedir}/#{name}") "file:///#{path}" end end
Private Instance Methods
build_name(path)
click to toggle source
# File lib/acceptance_test/screenshot_maker.rb, line 41 def build_name path full_path = File.expand_path(path) spec_index = full_path.index("/spec") if spec_index extension = File.extname(path) ext_index = extension.size == 0 ? -1 : full_path.index(extension)-1 name = full_path[spec_index+1..ext_index].gsub("/", "_") name = name[5..-1] if name =~ /^spec_/ name = name[9..-1] if name =~ /^features_/ name = name[11..-1] if name =~ /^acceptance_/ else name = path end name end
screenshot_name(name, line_number=nil)
click to toggle source
# File lib/acceptance_test/screenshot_maker.rb, line 37 def screenshot_name name, line_number=nil "#{name}#{line_number ? '-'+line_number.to_s : ''}.png" end