Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/http/common_spec.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.1819require File.expand_path('../../spec_helper', __dir__)2021module Selenium22module WebDriver23module Remote24module Http25describe Common do26subject(:common) do27common = described_class.new28common.server_url = URI.parse('http://server')29allow(common).to receive(:request)3031common32end3334after do35described_class.extra_headers = nil36described_class.user_agent = nil37end3839it 'sends non-empty body header for POST requests without command data' do40common.call(:post, 'clear', nil)4142expect(common).to have_received(:request)43.with(:post, URI.parse('http://server/clear'),44hash_including('Content-Length' => '2'), '{}')45end4647it 'sends a standard User-Agent by default' do48user_agent_regexp = %r{\Aselenium/#{WebDriver::VERSION} \(ruby #{Platform.os}\)\z}4950common.call(:post, 'session', nil)5152expect(common).to have_received(:request)53.with(:post, URI.parse('http://server/session'),54hash_including('User-Agent' => a_string_matching(user_agent_regexp)), '{}')55end5657it 'allows registering extra headers' do58described_class.extra_headers = {'Foo' => 'bar'}5960common.call(:post, 'session', nil)6162expect(common).to have_received(:request)63.with(:post, URI.parse('http://server/session'),64hash_including('Foo' => 'bar'), '{}')65end6667it 'allows overriding default User-Agent' do68described_class.user_agent = 'rspec/1.0 (ruby 3.2)'6970common.call(:post, 'session', nil)7172expect(common).to have_received(:request)73.with(:post, URI.parse('http://server/session'),74hash_including('User-Agent' => 'rspec/1.0 (ruby 3.2)'), '{}')75end76end77end # Http78end # Remote79end # WebDriver80end # Selenium818283