Skip to content

Commit 80a8879

Browse files
authored
[rb] move all guard and zipper tests to unit tests (#15717)
1 parent cc9f7e3 commit 80a8879

File tree

4 files changed

+117
-110
lines changed

4 files changed

+117
-110
lines changed

rb/spec/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ rb_library(
2222
"//rb/spec/integration/selenium/webdriver:driver",
2323
"//rb/spec/integration/selenium/webdriver:element",
2424
"//rb/spec/integration/selenium/webdriver:error",
25-
"//rb/spec/integration/selenium/webdriver:guard",
2625
"//rb/spec/integration/selenium/webdriver:listener",
2726
"//rb/spec/integration/selenium/webdriver:manager",
2827
"//rb/spec/integration/selenium/webdriver:navigation",
@@ -34,7 +33,6 @@ rb_library(
3433
"//rb/spec/integration/selenium/webdriver:timeout",
3534
"//rb/spec/integration/selenium/webdriver:virtual_authenticator",
3635
"//rb/spec/integration/selenium/webdriver:window",
37-
"//rb/spec/integration/selenium/webdriver:zipper",
3836
"//rb/spec/integration/selenium/webdriver/bidi:browsing_context",
3937
"//rb/spec/integration/selenium/webdriver/bidi:log_inspector",
4038
"//rb/spec/integration/selenium/webdriver/bidi:network",

rb/spec/integration/selenium/webdriver/guard_spec.rb

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

rb/spec/integration/selenium/webdriver/zipper_spec.rb renamed to rb/spec/unit/selenium/webdriver/zipper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
module Selenium
2323
module WebDriver
24-
describe Zipper, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
24+
describe Zipper do
2525
let(:base_file_name) { 'file.txt' }
2626
let(:file_content) { 'content' }
2727
let(:zip_file) { File.join(Dir.tmpdir, 'test.zip') }

0 commit comments

Comments
 (0)