Path: blob/trunk/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb
1864 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require_relative 'spec_helper'2021module Selenium22module WebDriver23describe FileReaper do24before { described_class.reap = true }2526let(:tmp_file) do27Pathname.new(Dir.tmpdir).join(SecureRandom.uuid).tap(&:mkpath)28end2930it 'reaps files that have been added' do31expect(tmp_file).to exist3233described_class << tmp_file.to_s34expect(described_class.reap!).to be true3536expect(tmp_file).not_to exist37end3839it 'fails if the file has not been added' do40expect(tmp_file).to exist4142expect {43described_class.reap(tmp_file.to_s)44}.to raise_error(Error::WebDriverError)45end4647it 'does not reap if reaping has been disabled' do48expect(tmp_file).to exist4950described_class.reap = false51described_class << tmp_file.to_s5253expect(described_class.reap!).to be false5455expect(tmp_file).to exist56end5758unless Platform.jruby? || Platform.windows? || Platform.truffleruby?59it 'reaps files only for the current pid' do60expect(tmp_file).to exist6162described_class << tmp_file.to_s6364pid = fork do65described_class.reap!66exit67end68Process.wait pid6970expect(tmp_file).to exist71end72end73end74end # WebDriver75end # Selenium767778