Path: blob/trunk/rb/lib/selenium/webdriver/support/guards/guard.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Support22class Guards23#24# Guard derived from RSpec example metadata.25# @api private26#2728class Guard29attr_reader :guarded, :type, :messages, :reason, :tracker3031def initialize(guarded, type, guards = nil)32@guarded = guarded33@tracker = guards&.bug_tracker || ''34@messages = guards&.messages || {}35@messages[:unknown] = 'TODO: Investigate why this is failing and file a bug report'36@type = type3738@reason = @guarded[:reason] || 'No reason given'39@guarded[:reason] = @reason40end4142def message43details = case reason44when Integer45"Bug Filed: #{tracker}/#{reason}"46when Symbol47messages[reason]48else49"Guarded by #{guarded};"50end5152case type53when :exclude54"Test skipped because it breaks test run; #{details}"55when :flaky56"Test skipped because it is unreliable in this configuration; #{details}"57when :exclusive58"Test does not apply to this configuration; #{details}"59else60"Test guarded; #{details}"61end62end6364# Bug is present on all configurations specified65def except?66@type == :except67end6869# Bug is present on all configurations not specified70def only?71@type == :only72end7374# Bug is present on all configurations specified, but test can not be run because it breaks other tests,75# or it is flaky and unreliable76def exclude?77@type == :exclude || @type == :flaky78end7980# Test only applies to configurations specified81def exclusive?82@type == :exclusive83end84end # Guard85end # Guards86end # Support87end # WebDriver88end # Selenium899091