brew/Library/Homebrew/test/utils/user_spec.rb

40 lines
980 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "utils/user"
RSpec.describe User do
2024-03-17 22:47:37 -07:00
subject(:user) { described_class.current }
2022-05-30 04:37:09 +01:00
it { is_expected.to eq ENV.fetch("USER") }
describe "#gui?" do
before do
allow(SystemCommand).to receive(:run)
.with("who", any_args)
.and_return([who_output, "", instance_double(Process::Status, success?: true)])
end
context "when the current user is in a console session" do
let(:who_output) do
<<~EOS
2022-05-30 04:37:09 +01:00
#{ENV.fetch("USER")} console Oct 1 11:23
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
EOS
end
2024-03-17 22:47:37 -07:00
it(:gui?) { expect(user.gui?).to be true }
end
context "when the current user is not in a console session" do
let(:who_output) do
<<~EOS
2022-05-30 04:37:09 +01:00
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
fake_user ttys002 Oct 1 11:27
EOS
end
2024-03-17 22:47:37 -07:00
it(:gui?) { expect(user.gui?).to be false }
end
end
end