Path: blob/trunk/rb/spec/unit/selenium/webdriver/zipper_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'2021module Selenium22module WebDriver23describe Zipper do24let(:base_file_name) { 'file.txt' }25let(:file_content) { 'content' }26let(:zip_file) { File.join(Dir.tmpdir, 'test.zip') }27let(:dir_to_zip) { Dir.mktmpdir('webdriver-spec-zipper') }2829def create_file30filename = File.join(dir_to_zip, base_file_name)31File.open(filename, 'w') { |io| io << file_content }3233filename34end3536after { FileUtils.rm_rf zip_file }3738describe '#zip' do39it 'a file' do40File.open(zip_file, 'wb') do |io|41io << Base64.decode64(described_class.zip_file(create_file))42end4344expect(File).to exist(zip_file)45end4647it 'a folder' do48create_file4950File.open(zip_file, 'wb') do |io|51io << Base64.decode64(described_class.zip(dir_to_zip))52end5354expect(File).to exist(zip_file)55end5657it 'follows symlinks' do58filename = create_file59File.symlink(filename, File.join(dir_to_zip, 'link'))6061zip_file = File.join(Dir.tmpdir, 'test.zip')62File.open(zip_file, 'wb') do |io|63io << Base64.decode64(described_class.zip(dir_to_zip))64end6566unzipped = described_class.unzip(zip_file)67expect(File.read(File.join(unzipped, 'link'))).to eq(file_content)68end69end7071describe '#unzip' do72it 'a file' do73File.open(zip_file, 'wb') do |io|74io << Base64.decode64(described_class.zip_file(create_file))75end7677unzipped = described_class.unzip(zip_file)78expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content)79end8081it 'a folder' do82create_file8384File.open(zip_file, 'wb') do |io|85io << Base64.decode64(described_class.zip(dir_to_zip))86end8788unzipped = described_class.unzip(zip_file)89expect(File.read(File.join(unzipped, base_file_name))).to eq(file_content)90end91end92end # Zipper93end # WebDriver94end # Selenium959697