Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/file_reaper_spec.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'spec_helper'
21
22
module Selenium
23
module WebDriver
24
describe FileReaper do
25
before { described_class.reap = true }
26
27
let(:tmp_file) do
28
Pathname.new(Dir.tmpdir).join(SecureRandom.uuid).tap(&:mkpath)
29
end
30
31
it 'reaps files that have been added' do
32
expect(tmp_file).to exist
33
34
described_class << tmp_file.to_s
35
expect(described_class.reap!).to be true
36
37
expect(tmp_file).not_to exist
38
end
39
40
it 'fails if the file has not been added' do
41
expect(tmp_file).to exist
42
43
expect {
44
described_class.reap(tmp_file.to_s)
45
}.to raise_error(Error::WebDriverError)
46
end
47
48
it 'does not reap if reaping has been disabled' do
49
expect(tmp_file).to exist
50
51
described_class.reap = false
52
described_class << tmp_file.to_s
53
54
expect(described_class.reap!).to be false
55
56
expect(tmp_file).to exist
57
end
58
59
unless Platform.jruby? || Platform.windows? || Platform.truffleruby?
60
it 'reaps files only for the current pid' do
61
expect(tmp_file).to exist
62
63
described_class << tmp_file.to_s
64
65
pid = fork do
66
described_class.reap!
67
exit
68
end
69
Process.wait pid
70
71
expect(tmp_file).to exist
72
end
73
end
74
end
75
end # WebDriver
76
end # Selenium
77
78