Skip to content

Commit e98cc84

Browse files
committed
[rb] fix the guard tests
1 parent 199aaee commit e98cc84

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Guards
2727
#
2828

2929
class Guard
30-
attr_reader :guarded, :type, :messages, :reason
30+
attr_reader :guarded, :type, :messages, :reason, :tracker
3131

3232
def initialize(guarded, type, guards = nil)
3333
@guarded = guarded
@@ -36,20 +36,21 @@ def initialize(guarded, type, guards = nil)
3636
@messages[:unknown] = 'TODO: Investigate why this is failing and file a bug report'
3737
@type = type
3838

39-
@guarded[:reason] ||= 'No reason given'
39+
@reason = @guarded[:reason] || 'No reason given'
40+
@guarded[:reason] = @reason
4041
end
4142

4243
def message
43-
details = case @reason
44+
details = case reason
4445
when Integer
45-
"Bug Filed: #{@tracker}/#{@reason}"
46+
"Bug Filed: #{tracker}/#{reason}"
4647
when Symbol
47-
@messages[@reason]
48+
messages[reason]
4849
else
4950
"Guarded by #{guarded};"
5051
end
5152

52-
case @type
53+
case type
5354
when :exclude
5455
"Test skipped because it breaks test run; #{details}"
5556
when :flaky

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ module Support
7777
guards = described_class.new(example)
7878
guards.add_condition(:foo, false)
7979

80-
expect(guards.disposition).to eq [:pending, 'Test guarded; no reason given']
80+
expect(guards.disposition).to eq [:pending, 'Test guarded; Guarded by {:foo=>false, :reason=>"No reason given"};']
8181
end
8282

8383
it 'is skipped without provided reason', exclusive: {foo: true} do |example|
8484
guards = described_class.new(example)
8585
guards.add_condition(:foo, false)
8686

87-
message = 'Test does not apply to this configuration; no reason given'
87+
message = 'Test does not apply to this configuration; Guarded by {:foo=>true, :reason=>"No reason given"};'
8888
expect(guards.disposition).to eq [:skip, message]
8989
end
9090
end
@@ -138,7 +138,7 @@ module Support
138138
describe '#new' do
139139
it 'requires guarded Hash and type' do
140140
guard = described_class.new({foo: 7}, :only)
141-
expect(guard.guarded).to eq(foo: 7)
141+
expect(guard.guarded).to eq(foo: 7, reason: 'No reason given')
142142
expect(guard.type).to eq :only
143143
end
144144

@@ -157,7 +157,7 @@ module Support
157157
it 'defaults to no reason given' do
158158
guard = described_class.new({}, :only)
159159

160-
expect(guard.message).to eq('Test guarded; no reason given')
160+
expect(guard.message).to eq('Test guarded; Guarded by {:reason=>"No reason given"};')
161161
end
162162

163163
it 'accepts integer' do |example|
@@ -170,7 +170,7 @@ module Support
170170
it 'accepts String' do
171171
guard = described_class.new({reason: 'because'}, :only)
172172

173-
expect(guard.message).to eq('Test guarded; because')
173+
expect(guard.message).to eq('Test guarded; Guarded by {:reason=>"because"};')
174174
end
175175

176176
it 'accepts Symbol of known message' do
@@ -190,19 +190,20 @@ 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 skipped because it breaks test run; because')
193+
expect(guard.message).to eq('Test skipped because it breaks test run; Guarded by {:reason=>"because"};')
194194
end
195195

196196
it 'has special message for flaky' do
197197
guard = described_class.new({reason: 'because'}, :flaky)
198198

199-
expect(guard.message).to eq('Test skipped because it is unreliable in this configuration; because')
199+
msg = 'Test skipped because it is unreliable in this configuration; Guarded by {:reason=>"because"};'
200+
expect(guard.message).to eq(msg)
200201
end
201202

202203
it 'has special message for exclusive' do
203204
guard = described_class.new({reason: 'because'}, :exclusive)
204205

205-
expect(guard.message).to eq('Test does not apply to this configuration; because')
206+
expect(guard.message).to eq('Test does not apply to this configuration; Guarded by {:reason=>"because"};')
206207
end
207208
end
208209
end

0 commit comments

Comments
 (0)