debian-mirror-gitlab/spec/scripts/lib/glfm/shared_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.6 KiB
Ruby
Raw Normal View History

2022-07-16 23:28:13 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
2023-05-27 22:25:52 +05:30
require 'tmpdir'
2022-07-16 23:28:13 +05:30
require_relative '../../../../scripts/lib/glfm/shared'
2023-05-27 22:25:52 +05:30
RSpec.describe Glfm::Shared, feature_category: :team_planning do
2022-07-16 23:28:13 +05:30
let(:instance) do
Class.new do
include Glfm::Shared
end.new
end
2022-10-11 01:57:18 +05:30
describe '#write_file' do
2023-03-04 22:38:38 +05:30
it 'creates the file' do
2022-10-11 01:57:18 +05:30
filename = Dir::Tmpname.create('basename') do |path|
instance.write_file(path, 'test')
end
expect(File.read(filename)).to eq 'test'
end
end
2022-07-16 23:28:13 +05:30
describe '#run_external_cmd' do
2023-03-04 22:38:38 +05:30
it 'runs the external command' do
2022-07-16 23:28:13 +05:30
expect(instance.run_external_cmd('echo "hello"')).to eq("hello\n")
end
context 'when command fails' do
it 'raises error' do
invalid_cmd = 'ls nonexistent_file'
expect(instance).to receive(:warn).with(/Error running command `#{invalid_cmd}`/)
expect(instance).to receive(:warn).with(/nonexistent_file.*no such file/i)
expect { instance.run_external_cmd(invalid_cmd) }.to raise_error(RuntimeError)
end
end
end
2022-10-11 01:57:18 +05:30
describe '#dump_yaml_with_formatting' do
2023-03-04 22:38:38 +05:30
it 'returns formatted yaml' do
2022-10-11 01:57:18 +05:30
hash = { a: 'b' }
yaml = instance.dump_yaml_with_formatting(hash, literal_scalars: true)
expect(yaml).to eq("---\na: |-\n b\n")
end
end
2022-07-16 23:28:13 +05:30
describe '#output' do
# NOTE: The #output method is normally always mocked, to prevent output while the specs are
# running. However, in order to provide code coverage for the method, we have to invoke
# it at least once.
it 'has code coverage' do
allow(instance).to receive(:puts)
instance.output('')
end
end
end