Sha256: 197defe70438cddfa86560528d061b25dd477b468372df521a64979b6bc17ac5

Contents?: true

Size: 1.64 KB

Versions: 41

Compression:

Stored size: 1.64 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_and_open_page_path = nil
    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.expand_path('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.expand_path('capybara-\d+\.png', alternative_path))
      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

41 entries across 37 versions & 4 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/capybara-2.16.1/lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/capybara-2.18.0/lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.8 vendor/bundle/gems/capybara-2.18.0/lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.18.0 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.17.0 lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.7 vendor/bundle/gems/capybara-2.16.1/lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.16.1 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.16.0 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.15.4 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.15.3 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.15.2 lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.6 vendor/bundle/gems/capybara-2.15.1/lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.15.1 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.15.0 lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.14.3/lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/capybara-2.13.0/lib/capybara/spec/session/save_screenshot_spec.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.13.0/lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.14.4 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.14.3 lib/capybara/spec/session/save_screenshot_spec.rb
capybara-2.14.2 lib/capybara/spec/session/save_screenshot_spec.rb