Sha256: cc1021639bab0f09bb63f80c287db87e7f2c00691e7670b350f2a30eb4140511

Contents?: true

Size: 1.38 KB

Versions: 27

Compression:

Stored size: 1.38 KB

Contents

class ScreenshotMaker
  attr_accessor :basedir

  def initialize basedir
    @basedir = basedir
  end

  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

  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

  def screenshot_name name, line_number=nil
    "#{name}#{line_number ? '-'+line_number.to_s : ''}.png"
  end

  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

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
acceptance_test-1.11.7 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.6 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.5 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.4 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.3 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.2 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.1 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.11.0 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.12 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.11 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.10 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.9 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.8 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.7 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.6 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.5 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.4 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.3 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.2 lib/acceptance_test/screenshot_maker.rb
acceptance_test-1.10.1 lib/acceptance_test/screenshot_maker.rb