diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/scripts/lib/glfm/shared_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/scripts/lib/glfm/shared_spec.rb')
-rw-r--r-- | spec/scripts/lib/glfm/shared_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/scripts/lib/glfm/shared_spec.rb b/spec/scripts/lib/glfm/shared_spec.rb new file mode 100644 index 00000000000..f6792b93718 --- /dev/null +++ b/spec/scripts/lib/glfm/shared_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true +require 'fast_spec_helper' +require_relative '../../../../scripts/lib/glfm/shared' + +RSpec.describe Glfm::Shared do + let(:instance) do + Class.new do + include Glfm::Shared + end.new + end + + describe '#run_external_cmd' do + it 'works' do + 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 + + 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 |