Sha256: 7ff4ad12664f56dee6358179f42ae881376662fc4fa9145aeb4a83464bbecad5

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
  let(:alternative_path) { File.join(Dir.pwd, "save_screenshot_tmp") }
  before do
    @session.visit '/foo'
  end

  after do
    Capybara.save_path = nil
    FileUtils.rm_rf alternative_path
  end

  it "generates sensible filename" do
    allow(@session.driver).to receive(:save_screenshot)

    @session.save_screenshot

    regexp = Regexp.new(File.join(Dir.pwd, 'capybara-\d+\.png'))
    expect(@session.driver).to have_received(:save_screenshot).with(regexp, {})
  end

  it "allows to specify another path" do
    allow(@session.driver).to receive(:save_screenshot)

    custom_path = 'screenshots/1.png'
    @session.save_screenshot(custom_path)

    expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/, {})
  end

  context "with Capybara.save_path" do
    it "file is generated in the correct location" do
      Capybara.save_path = alternative_path
      allow(@session.driver).to receive(:save_screenshot)

      @session.save_screenshot

      regexp = Regexp.new(File.join(alternative_path, 'capybara-\d+\.png'))
      expect(@session.driver).to have_received(:save_screenshot).with(regexp, {})
    end

    it "relative paths are relative to save_path" do
      Capybara.save_path = alternative_path
      allow(@session.driver).to receive(:save_screenshot)

      custom_path = 'screenshots/2.png'
      @session.save_screenshot(custom_path)

      expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path), {})
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
tdiary-5.0.9 vendor/bundle/gems/capybara-3.2.1/lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.2.1 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.2.0 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.1.1 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.1.0 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.0.3 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.0.2 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.0.1 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.0.0 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-3.0.0.rc2 lib/capybara/spec/session/save_screenshot_spec.rb