Path: blob/trunk/rb/spec/unit/selenium/webdriver/guards_spec.rb
1864 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.1819require_relative 'spec_helper'20require 'selenium/webdriver/support/guards'2122module Selenium23module WebDriver24module Support25describe Guards do26before do |example|27guards = described_class.new(example, bug_tracker: 'https://github.com/SeleniumHQ/selenium/issues')28guards.add_condition(:condition, :guarded)2930results = guards.disposition31send(*results) if results32end3334context 'with single guard' do35describe '#exclude' do36it 'ignores an unrecognized guard parameter', invalid: { condition: :guarded } do37# pass38end3940it 'skips without running', exclude: { condition: :guarded } do41raise 'This code will not get executed so it will not fail'42end43end4445describe '#flaky' do46it 'skips without running', flaky: { condition: :guarded } do47raise 'This code will not get executed so it will not fail'48end49end5051describe '#exclusive' do52it 'skips without running if it does not match', exclusive: { condition: :not_guarded } do53raise 'This code will not get executed so it will not fail'54end5556it 'does not guard if it does match', exclusive: { condition: :guarded } do57# pass58end59end6061describe '#only' do62it 'guards when value does not match', only: { condition: :not_guarded } do63raise 'This code is executed but expected to fail'64end6566it 'does not guard when value matches', only: { condition: :guarded } do67# pass68end69end7071describe '#except' do72it 'guards when value matches and test fails', except: { condition: :guarded } do73raise 'This code is executed but expected to fail'74end7576it 'does not guard when value does not match and test passes', except: { condition: :not_guarded } do77# pass78end79end80end8182context 'when multiple guards' do83it 'guards if neither only nor except match and test fails', except: { condition: :not_guarded },84only: { condition: :not_guarded } do85raise 'This code is executed but expected to fail'86end8788it 'guards if both only and except match', except: { condition: :guarded }, only: { condition: :guarded } do89raise 'This code is executed but expected to fail'90end9192it 'guards if except matches and only does not', except: { condition: :guarded }, only: { condition: :not_guarded } do93raise 'This code is executed but expected to fail'94end9596it 'does not guard if only matches and except does not', except: { condition: :not_guarded },97only: { condition: :guarded } do98# pass99end100101it 'gives correct reason', except: [{ condition: :guarded, reason: 'bug1' },102{ condition: :not_guarded, reason: 'bug2' }] do103raise 'This code is executed but expected to fail'104end105end106107context 'when array of hashes' do108it 'guards if any Hash value is satisfied', only: [{ condition: :guarded }, { condition: :not_guarded }] do109raise 'This code is executed but expected to fail'110end111end112end113end # Support114end # WebDriver115end # Selenium116117118