2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-01 12:29:21 +02:00
|
|
|
require "utils/user"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe User do
|
2024-03-17 22:47:37 -07:00
|
|
|
subject(:user) { described_class.current }
|
2018-10-01 12:29:21 +02:00
|
|
|
|
2022-05-30 04:37:09 +01:00
|
|
|
it { is_expected.to eq ENV.fetch("USER") }
|
2018-10-01 12:29:21 +02:00
|
|
|
|
|
|
|
describe "#gui?" do
|
|
|
|
before do
|
2023-03-03 22:13:41 +00:00
|
|
|
allow(SystemCommand).to receive(:run)
|
|
|
|
.with("who", any_args)
|
2018-10-01 12:29:21 +02:00
|
|
|
.and_return([who_output, "", instance_double(Process::Status, success?: true)])
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the current user is in a console session" do
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:who_output) do
|
2018-10-01 12:29:21 +02:00
|
|
|
<<~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
|
2018-10-01 12:29:21 +02:00
|
|
|
EOS
|
2023-03-08 23:14:46 +00:00
|
|
|
end
|
2018-10-01 12:29:21 +02:00
|
|
|
|
2024-03-17 22:47:37 -07:00
|
|
|
it(:gui?) { expect(user.gui?).to be true }
|
2018-10-01 12:29:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the current user is not in a console session" do
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:who_output) do
|
2018-10-01 12:29:21 +02:00
|
|
|
<<~EOS
|
2022-05-30 04:37:09 +01:00
|
|
|
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
|
|
|
|
fake_user ttys002 Oct 1 11:27
|
2018-10-01 12:29:21 +02:00
|
|
|
EOS
|
2023-03-08 23:14:46 +00:00
|
|
|
end
|
2018-10-01 12:29:21 +02:00
|
|
|
|
2024-03-17 22:47:37 -07:00
|
|
|
it(:gui?) { expect(user.gui?).to be false }
|
2018-10-01 12:29:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|