brew/Library/Homebrew/test/utils/user_spec.rb
Issy Long 734a651f93
rubocop: Enable Layout/MultilineMethodCallIndentation & fix offenses
- Part of trying to reduce the number of `Excludes:` we have in our
  RuboCop configs.
- The fixes here all seemed reasonable, with some minimal tweaks for
  line length and less floatiness. Apart from `test/dev-cmd/bottle_spec.rb`
  where RuboCop wanted to do some ridiculously floaty indentation and there
  wasn't an obvious alternative place to break the lines, so I opted for
  in-line disables instead.
2023-03-03 22:18:51 +00:00

41 lines
966 B
Ruby

# typed: false
# frozen_string_literal: true
require "utils/user"
describe User do
subject { described_class.current }
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) {
<<~EOS
#{ENV.fetch("USER")} console Oct 1 11:23
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
EOS
}
its(:gui?) { is_expected.to be true }
end
context "when the current user is not in a console session" do
let(:who_output) {
<<~EOS
#{ENV.fetch("USER")} ttys001 Oct 1 11:25
fake_user ttys002 Oct 1 11:27
EOS
}
its(:gui?) { is_expected.to be false }
end
end
end