Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/lib/selenium/webdriver/support/guards/guard.rb
1990 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
module Selenium
21
module WebDriver
22
module Support
23
class Guards
24
#
25
# Guard derived from RSpec example metadata.
26
# @api private
27
#
28
29
class Guard
30
attr_reader :guarded, :type, :messages, :reason, :tracker
31
32
def initialize(guarded, type, guards = nil)
33
@guarded = guarded
34
@tracker = guards&.bug_tracker || ''
35
@messages = guards&.messages || {}
36
@messages[:unknown] = 'TODO: Investigate why this is failing and file a bug report'
37
@type = type
38
39
@reason = @guarded[:reason] || 'No reason given'
40
@guarded[:reason] = @reason
41
end
42
43
def message
44
details = case reason
45
when Integer
46
"Bug Filed: #{tracker}/#{reason}"
47
when Symbol
48
messages[reason]
49
else
50
"Guarded by #{guarded};"
51
end
52
53
case type
54
when :exclude
55
"Test skipped because it breaks test run; #{details}"
56
when :flaky
57
"Test skipped because it is unreliable in this configuration; #{details}"
58
when :exclusive
59
"Test does not apply to this configuration; #{details}"
60
else
61
"Test guarded; #{details}"
62
end
63
end
64
65
# Bug is present on all configurations specified
66
def except?
67
@type == :except
68
end
69
70
# Bug is present on all configurations not specified
71
def only?
72
@type == :only
73
end
74
75
# Bug is present on all configurations specified, but test can not be run because it breaks other tests,
76
# or it is flaky and unreliable
77
def exclude?
78
@type == :exclude || @type == :flaky
79
end
80
81
# Test only applies to configurations specified
82
def exclusive?
83
@type == :exclusive
84
end
85
end # Guard
86
end # Guards
87
end # Support
88
end # WebDriver
89
end # Selenium
90
91