Skip to content

Commit

Permalink
[rb] allow more versatile guard messages in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jul 15, 2020
1 parent 4e2e26f commit f7f0fea
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
38 changes: 35 additions & 3 deletions rb/spec/integration/selenium/webdriver/guard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,45 @@ module SpecSupport
end
end

context 'guard messages on failing tests' do
it 'gives correct message with single only excludes', except: [{browser: :chrome, message: 'bug1'},
{browser: :not_chrome, message: 'bug2'}] do
context 'guard messages' do
it 'gives correct reason with single only excludes', except: [{browser: :chrome, reason: 'bug1'},
{browser: :not_chrome, reason: 'bug2'}] do
fail
end
end
end

describe Guards::Guard do
it 'Uses default message' do
guard = Guards::Guard.new({}, :except)
expect(guard.message).to eq 'Test guarded; no reason given'
end

it 'Creates message from Integer' do
guard = Guards::Guard.new({reason: 1}, :except)
expect(guard.message).to eq 'Test guarded; Bug Filed: https://github.com/SeleniumHQ/selenium/issues/1'
end

it 'Creates message from Symbol' do
guard = Guards::Guard.new({reason: :unk}, :except)
expect(guard.message).to eq 'Test guarded; TODO: Investigate why this is failing and file bug'
end

it 'Creates message from String' do
guard = Guards::Guard.new({reason: "Foo is bad"}, :except)
expect(guard.message).to eq 'Test guarded; Foo is bad'
end

it 'Uses correct message for exclusive' do
guard = Guards::Guard.new({reason: "Foo is bad"}, :exclusive)
expect(guard.message).to eq 'Test does not apply to this configuration'
end

it 'Uses correct message for exclude' do
guard = Guards::Guard.new({reason: "Foo is bad"}, :exclude)
expect(guard.message).to eq 'Test not guarded because it breaks test run; Foo is bad'
end
end
end # SpecSupport
end # WebDriver
end # Selenium
2 changes: 2 additions & 0 deletions rb/spec/integration/selenium/webdriver/spec_support/guards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module SpecSupport
class Guards
include Enumerable

MESSAGES = {unk: 'TODO: Investigate why this is failing and file bug'}.freeze

GUARD_TYPES = %i[except only exclude exclusive].freeze

def initialize(example, guards = nil)
Expand Down
33 changes: 23 additions & 10 deletions rb/spec/integration/selenium/webdriver/spec_support/guards/guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ module SpecSupport
class Guards
class Guard

attr_reader :message

def initialize(guard, type)
@type = type

reason = guard.delete(:message) || 'no reason given.'
@message = if @type == :exclude
"Test not guarded because it breaks test run; #{reason}."
elsif @type == :exclusive
'Test does not apply to this configuration.'
else
"Test guarded; #{reason}."
end
@reason = guard.delete(:reason)

@drivers = []
@browsers = []
@platforms = []
Expand All @@ -46,6 +38,27 @@ def initialize(guard, type)
expand_platforms(guard)
end

def message
details = case @reason
when Integer
"Bug Filed: https://github.com/SeleniumHQ/selenium/issues/#{@reason}"
when Symbol
Guards::MESSAGES[@reason]
when String
@reason
else
'no reason given'
end

if @type == :exclude
"Test not guarded because it breaks test run; #{details}"
elsif @type == :exclusive
'Test does not apply to this configuration'
else
"Test guarded; #{details}"
end
end

# Bug is present on all configurations specified
def except?
@type == :except
Expand Down

0 comments on commit f7f0fea

Please sign in to comment.