diff --git a/rb/spec/BUILD.bazel b/rb/spec/BUILD.bazel index 11e51dd89c3e4..c8be424e1dc48 100644 --- a/rb/spec/BUILD.bazel +++ b/rb/spec/BUILD.bazel @@ -22,7 +22,6 @@ rb_library( "//rb/spec/integration/selenium/webdriver:driver", "//rb/spec/integration/selenium/webdriver:element", "//rb/spec/integration/selenium/webdriver:error", - "//rb/spec/integration/selenium/webdriver:guard", "//rb/spec/integration/selenium/webdriver:listener", "//rb/spec/integration/selenium/webdriver:manager", "//rb/spec/integration/selenium/webdriver:navigation", @@ -34,7 +33,6 @@ rb_library( "//rb/spec/integration/selenium/webdriver:timeout", "//rb/spec/integration/selenium/webdriver:virtual_authenticator", "//rb/spec/integration/selenium/webdriver:window", - "//rb/spec/integration/selenium/webdriver:zipper", "//rb/spec/integration/selenium/webdriver/bidi:browsing_context", "//rb/spec/integration/selenium/webdriver/bidi:log_inspector", "//rb/spec/integration/selenium/webdriver/bidi:network", diff --git a/rb/spec/integration/selenium/webdriver/guard_spec.rb b/rb/spec/integration/selenium/webdriver/guard_spec.rb deleted file mode 100644 index 1353f3bae14b1..0000000000000 --- a/rb/spec/integration/selenium/webdriver/guard_spec.rb +++ /dev/null @@ -1,107 +0,0 @@ -# frozen_string_literal: true - -# Licensed to the Software Freedom Conservancy (SFC) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The SFC licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -require_relative 'spec_helper' - -module Selenium - module WebDriver - module Support - describe Guards, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {driver: :chrome}] do - describe '#exclude' do - it 'ignores an unrecognized guard parameter', invalid: {browser: :chrome} do - # pass - end - - it 'skips without running', exclude: {browser: :chrome} do - raise 'This code will not get executed so it will not fail' - end - end - - describe '#flaky' do - it 'skips without running', flaky: {browser: :chrome} do - raise 'This code will not get executed so it will not fail' - end - end - - describe '#exclusive' do - it 'skips without running if it does not match', exclusive: {browser: :not_chrome} do - raise 'This code will not get executed so it will not fail' - end - - it 'does not guard if it does match', exclusive: {browser: :chrome} do - # pass - end - end - - describe '#only' do - it 'guards when value does not match', only: {browser: :not_chrome} do - raise 'This code is executed but expected to fail' - end - - it 'does not guard when value matches', only: {browser: :chrome} do - # pass - end - end - - describe '#except' do - it 'guards when value matches and test fails', except: {browser: :chrome} do - raise 'This code is executed but expected to fail' - end - - it 'does not guard when value does not match and test passes', except: {browser: :not_chrome} do - # pass - end - end - - context 'when multiple guards' do - it 'guards if neither only nor except match and test fails', except: {browser: :not_chrome}, - only: {browser: :not_chrome} do - raise 'This code is executed but expected to fail' - end - - it 'guards if both only and except match', except: {browser: :chrome}, only: {browser: :chrome} do - raise 'This code is executed but expected to fail' - end - - it 'guards if except matches and only does not', except: {browser: :chrome}, only: {browser: :not_chrome} do - raise 'This code is executed but expected to fail' - end - - it 'does not guard if only matches and except does not', except: {browser: :not_chrome}, - only: {browser: :chrome} do - # pass - end - end - - context 'when array of hashes' do - it 'guards if any Hash value is satisfied', only: [{browser: :chrome}, {browser: :not_chrome}] do - raise 'This code is executed but expected to fail' - end - end - - describe 'guard messages' do - it 'gives correct reason with single only excludes', except: [{browser: :chrome, reason: 'bug1'}, - {browser: :not_chrome, reason: 'bug2'}] do - raise 'This code is executed but expected to fail' - end - end - end - end # Support - end # WebDriver -end # Selenium diff --git a/rb/spec/unit/selenium/webdriver/guards_spec.rb b/rb/spec/unit/selenium/webdriver/guards_spec.rb new file mode 100644 index 0000000000000..b223f18a7236f --- /dev/null +++ b/rb/spec/unit/selenium/webdriver/guards_spec.rb @@ -0,0 +1,116 @@ +# frozen_string_literal: true + +# Licensed to the Software Freedom Conservancy (SFC) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The SFC licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require_relative 'spec_helper' +require 'selenium/webdriver/support/guards' + +module Selenium + module WebDriver + module Support + describe Guards do + before do |example| + guards = described_class.new(example, bug_tracker: 'https://github.com/SeleniumHQ/selenium/issues') + guards.add_condition(:condition, :guarded) + + results = guards.disposition + send(*results) if results + end + + context 'with single guard' do + describe '#exclude' do + it 'ignores an unrecognized guard parameter', invalid: { condition: :guarded } do + # pass + end + + it 'skips without running', exclude: { condition: :guarded } do + raise 'This code will not get executed so it will not fail' + end + end + + describe '#flaky' do + it 'skips without running', flaky: { condition: :guarded } do + raise 'This code will not get executed so it will not fail' + end + end + + describe '#exclusive' do + it 'skips without running if it does not match', exclusive: { condition: :not_guarded } do + raise 'This code will not get executed so it will not fail' + end + + it 'does not guard if it does match', exclusive: { condition: :guarded } do + # pass + end + end + + describe '#only' do + it 'guards when value does not match', only: { condition: :not_guarded } do + raise 'This code is executed but expected to fail' + end + + it 'does not guard when value matches', only: { condition: :guarded } do + # pass + end + end + + describe '#except' do + it 'guards when value matches and test fails', except: { condition: :guarded } do + raise 'This code is executed but expected to fail' + end + + it 'does not guard when value does not match and test passes', except: { condition: :not_guarded } do + # pass + end + end + end + + context 'when multiple guards' do + it 'guards if neither only nor except match and test fails', except: { condition: :not_guarded }, + only: { condition: :not_guarded } do + raise 'This code is executed but expected to fail' + end + + it 'guards if both only and except match', except: { condition: :guarded }, only: { condition: :guarded } do + raise 'This code is executed but expected to fail' + end + + it 'guards if except matches and only does not', except: { condition: :guarded }, only: { condition: :not_guarded } do + raise 'This code is executed but expected to fail' + end + + it 'does not guard if only matches and except does not', except: { condition: :not_guarded }, + only: { condition: :guarded } do + # pass + end + + it 'gives correct reason', except: [{ condition: :guarded, reason: 'bug1' }, + { condition: :not_guarded, reason: 'bug2' }] do + raise 'This code is executed but expected to fail' + end + end + + context 'when array of hashes' do + it 'guards if any Hash value is satisfied', only: [{ condition: :guarded }, { condition: :not_guarded }] do + raise 'This code is executed but expected to fail' + end + end + end + end # Support + end # WebDriver +end # Selenium diff --git a/rb/spec/integration/selenium/webdriver/zipper_spec.rb b/rb/spec/unit/selenium/webdriver/zipper_spec.rb similarity index 97% rename from rb/spec/integration/selenium/webdriver/zipper_spec.rb rename to rb/spec/unit/selenium/webdriver/zipper_spec.rb index 266c19ed2962b..ffa49d2ce423c 100644 --- a/rb/spec/integration/selenium/webdriver/zipper_spec.rb +++ b/rb/spec/unit/selenium/webdriver/zipper_spec.rb @@ -21,7 +21,7 @@ module Selenium module WebDriver - describe Zipper, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do + describe Zipper do let(:base_file_name) { 'file.txt' } let(:file_content) { 'content' } let(:zip_file) { File.join(Dir.tmpdir, 'test.zip') }