Sha256: d5d0fb8552aa93288b13b188b238aa6615aaa96726460276206784b0a458ba18

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

#encoding: UTF-8
# frozen_string_literal: true

require 'spec_helper'
require 'rbconfig'

describe 'OS' do
  subject { PDFKit::OS }

  describe 'host_is_windows?' do
    it 'is callable' do
      expect(subject).to respond_to(:host_is_windows?)
    end

    def test_is_windows(bool, host_os)
      allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return(host_os)

      expect(subject.host_is_windows?).to be bool
    end

    it 'returns true if the host_os is set to "mswin"' do
      test_is_windows(true, 'mswin')
    end

    it 'returns true if the host_os is set to "msys"' do
      test_is_windows(true, 'msys')
    end

    it 'returns false if the host_os is set to "linux-gnu"' do
      test_is_windows(false, 'linux-gnu')
    end

    it 'returns false if the host_os is set to "darwin14.1.0"' do
      test_is_windows(false, 'darwin14.1.0')
    end
  end

  describe 'shell_escape_for_os' do
    it 'is callable' do
      expect(subject).to respond_to(:shell_escape_for_os)
    end

    it 'calls shelljoin on linux' do
      args = double(:shelljoin)
      allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('linux-gnu')

      expect(args).to receive(:shelljoin)
      PDFKit::OS.shell_escape_for_os(args)
    end

    it 'calls shelljoin on darwin14.1.10' do
      args = double(:shelljoin)
      allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('darwin14.1.10-gnu')

      expect(args).to receive(:shelljoin)
      PDFKit::OS.shell_escape_for_os(args)
    end

    it 'escapes special characters on Windows' do
      args = ['foo|bar', 'biz(baz)', 'foo<baz>bar', 'hello^world&goodbye']
      allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('mswin')

      escaped_args = PDFKit::OS.shell_escape_for_os(args)
      expect(escaped_args).to eq('foo^|bar biz^(baz^) foo^<baz^>bar hello^^world^&goodbye')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pdfkit-0.8.7.3 spec/os_spec.rb
pdfkit-0.8.7.2 spec/os_spec.rb
pdfkit-0.8.7.1 spec/os_spec.rb
pdfkit-0.8.7 spec/os_spec.rb
pdfkit-0.8.6 spec/os_spec.rb