Skip to content

Commit 4244945

Browse files
committed
[rb] add flaky condition to guards to mark unreliable tests
1 parent 889d489 commit 4244945

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

rb/lib/selenium/webdriver/support/guards.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module Selenium
2424
module WebDriver
2525
module Support
2626
class Guards
27-
GUARD_TYPES = %i[except only exclude exclusive].freeze
27+
GUARD_TYPES = %i[except only exclude exclusive flaky].freeze
2828

2929
attr_reader :messages
3030
attr_accessor :bug_tracker

rb/lib/selenium/webdriver/support/guards/guard.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def message
5353

5454
case @type
5555
when :exclude
56-
"Test not guarded because it breaks test run; #{details}"
56+
"Test skipped because it breaks test run; #{details}"
57+
when :flaky
58+
"Test skipped because it is unreliable in this configuration; #{details}"
5759
when :exclusive
5860
"Test does not apply to this configuration; #{details}"
5961
else
@@ -71,9 +73,10 @@ def only?
7173
@type == :only
7274
end
7375

74-
# Bug is present on all configurations specified, but test can not be run because it breaks other tests
76+
# Bug is present on all configurations specified, but test can not be run because it breaks other tests,
77+
# or it is flaky and unreliable
7578
def exclude?
76-
@type == :exclude
79+
@type == :exclude || @type == :flaky
7780
end
7881

7982
# Test only applies to configurations specified

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ module Support
3333
end
3434
end
3535

36+
describe '#flaky' do
37+
it 'skips without running', flaky: {browser: :chrome} do
38+
raise 'This code will not get executed so it will not fail'
39+
end
40+
end
41+
3642
describe '#exclusive' do
3743
it 'skips without running if it does not match', exclusive: {browser: :not_chrome} do
3844
raise 'This code will not get executed so it will not fail'

rb/spec/unit/selenium/webdriver/guard_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ module Support
2626
describe Guards do
2727
describe '#new' do
2828
it 'collects guards from example only for known guard types',
29-
except: {}, exclude: {}, exclusive: {}, ignored: {}, only: {} do |example|
29+
except: {}, exclude: {}, exclusive: {}, ignored: {}, only: {}, flaky: {} do |example|
3030
guards = described_class.new(example)
3131
types = guards.instance_variable_get(:@guards).map { |g| g.instance_variable_get(:@type) }
32-
expect(types).to include :except, :only, :exclusive, :exclude
32+
expect(types).to include :except, :only, :exclusive, :exclude, :flaky
3333
expect(types).not_to include :ignored
3434
end
3535

@@ -190,7 +190,13 @@ module Support
190190
it 'has special message for exclude' do
191191
guard = described_class.new({reason: 'because'}, :exclude)
192192

193-
expect(guard.message).to eq('Test not guarded because it breaks test run; because')
193+
expect(guard.message).to eq('Test skipped because it breaks test run; because')
194+
end
195+
196+
it 'has special message for flaky' do
197+
guard = described_class.new({reason: 'because'}, :flaky)
198+
199+
expect(guard.message).to eq('Test skipped because it is unreliable in this configuration; because')
194200
end
195201

196202
it 'has special message for exclusive' do

0 commit comments

Comments
 (0)