Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/guards_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
require 'selenium/webdriver/support/guards'
22
23
module Selenium
24
module WebDriver
25
module Support
26
describe Guards do
27
before do |example|
28
guards = described_class.new(example, bug_tracker: 'https://github.com/SeleniumHQ/selenium/issues')
29
guards.add_condition(:condition, :guarded)
30
31
results = guards.disposition
32
send(*results) if results
33
end
34
35
context 'with single guard' do
36
describe '#exclude' do
37
it 'ignores an unrecognized guard parameter', invalid: { condition: :guarded } do
38
# pass
39
end
40
41
it 'skips without running', exclude: { condition: :guarded } do
42
raise 'This code will not get executed so it will not fail'
43
end
44
end
45
46
describe '#flaky' do
47
it 'skips without running', flaky: { condition: :guarded } do
48
raise 'This code will not get executed so it will not fail'
49
end
50
end
51
52
describe '#exclusive' do
53
it 'skips without running if it does not match', exclusive: { condition: :not_guarded } do
54
raise 'This code will not get executed so it will not fail'
55
end
56
57
it 'does not guard if it does match', exclusive: { condition: :guarded } do
58
# pass
59
end
60
end
61
62
describe '#only' do
63
it 'guards when value does not match', only: { condition: :not_guarded } do
64
raise 'This code is executed but expected to fail'
65
end
66
67
it 'does not guard when value matches', only: { condition: :guarded } do
68
# pass
69
end
70
end
71
72
describe '#except' do
73
it 'guards when value matches and test fails', except: { condition: :guarded } do
74
raise 'This code is executed but expected to fail'
75
end
76
77
it 'does not guard when value does not match and test passes', except: { condition: :not_guarded } do
78
# pass
79
end
80
end
81
end
82
83
context 'when multiple guards' do
84
it 'guards if neither only nor except match and test fails', except: { condition: :not_guarded },
85
only: { condition: :not_guarded } do
86
raise 'This code is executed but expected to fail'
87
end
88
89
it 'guards if both only and except match', except: { condition: :guarded }, only: { condition: :guarded } do
90
raise 'This code is executed but expected to fail'
91
end
92
93
it 'guards if except matches and only does not', except: { condition: :guarded }, only: { condition: :not_guarded } do
94
raise 'This code is executed but expected to fail'
95
end
96
97
it 'does not guard if only matches and except does not', except: { condition: :not_guarded },
98
only: { condition: :guarded } do
99
# pass
100
end
101
102
it 'gives correct reason', except: [{ condition: :guarded, reason: 'bug1' },
103
{ condition: :not_guarded, reason: 'bug2' }] do
104
raise 'This code is executed but expected to fail'
105
end
106
end
107
108
context 'when array of hashes' do
109
it 'guards if any Hash value is satisfied', only: [{ condition: :guarded }, { condition: :not_guarded }] do
110
raise 'This code is executed but expected to fail'
111
end
112
end
113
end
114
end # Support
115
end # WebDriver
116
end # Selenium
117
118