Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/credentials_spec.rb
1865 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__)20require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/credentials', __dir__)2122module Selenium23module WebDriver24class BiDi25describe Credentials do26describe '#initialize' do27it 'initializes with nil username/password by default' do28creds = described_class.new29expect(creds.username).to be_nil30expect(creds.password).to be_nil31end3233it 'allows initialization with username and password' do34creds = described_class.new(username: 'alice', password: 'secret')35expect(creds.username).to eq('alice')36expect(creds.password).to eq('secret')37end38end3940describe '#username / #password' do41it 'allows setting and retrieving username' do42creds = described_class.new43creds.username = 'bob'44expect(creds.username).to eq('bob')45end4647it 'allows setting and retrieving password' do48creds = described_class.new49creds.password = 'my_password'50expect(creds.password).to eq('my_password')51end52end5354describe '#as_json' do55it 'returns nil if username is missing' do56creds = described_class.new(password: 'secret')57expect(creds.as_json).to be_nil58end5960it 'returns nil if password is missing' do61creds = described_class.new(username: 'alice')62expect(creds.as_json).to be_nil63end6465it 'returns a hash of the credentials when both username and password are present' do66creds = described_class.new(username: 'alice', password: 'secret')67formatted_creds = creds.as_json6869expect(formatted_creds).to eq(70type: 'password',71username: 'alice',72password: 'secret'73)74end75end76end77end78end79end808182