Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb
1990 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Remote
25
module Http
26
describe Common do
27
subject(:common) do
28
common = described_class.new
29
common.server_url = URI.parse('http://server')
30
allow(common).to receive(:request)
31
32
common
33
end
34
35
after do
36
described_class.extra_headers = nil
37
described_class.user_agent = nil
38
end
39
40
it 'sends non-empty body header for POST requests without command data' do
41
common.call(:post, 'clear', nil)
42
43
expect(common).to have_received(:request)
44
.with(:post, URI.parse('http://server/clear'),
45
hash_including('Content-Length' => '2'), '{}')
46
end
47
48
it 'sends a standard User-Agent by default' do
49
user_agent_regexp = %r{\Aselenium/#{WebDriver::VERSION} \(ruby #{Platform.os}\)\z}
50
51
common.call(:post, 'session', nil)
52
53
expect(common).to have_received(:request)
54
.with(:post, URI.parse('http://server/session'),
55
hash_including('User-Agent' => a_string_matching(user_agent_regexp)), '{}')
56
end
57
58
it 'allows registering extra headers' do
59
described_class.extra_headers = {'Foo' => 'bar'}
60
61
common.call(:post, 'session', nil)
62
63
expect(common).to have_received(:request)
64
.with(:post, URI.parse('http://server/session'),
65
hash_including('Foo' => 'bar'), '{}')
66
end
67
68
it 'allows overriding default User-Agent' do
69
described_class.user_agent = 'rspec/1.0 (ruby 3.2)'
70
71
common.call(:post, 'session', nil)
72
73
expect(common).to have_received(:request)
74
.with(:post, URI.parse('http://server/session'),
75
hash_including('User-Agent' => 'rspec/1.0 (ruby 3.2)'), '{}')
76
end
77
end
78
end # Http
79
end # Remote
80
end # WebDriver
81
end # Selenium
82
83