File: executable_file_spec.rb

package info (click to toggle)
ruby-tty-which 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 196 kB
  • sloc: ruby: 274; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

RSpec.describe TTY::Which, "#executable_file?" do
  it "checks if file in directory is executable" do
    path = "/usr/local/bin/ruby"
    allow(::File).to receive(:join).and_call_original
    allow(::File).to receive(:file?).and_call_original
    allow(::File).to receive(:join).with("/usr/local/bin", "ruby").and_return(path)
    allow(::File).to receive(:file?).with(path).and_return(true)
    allow(::File).to receive(:executable?).with(path).and_return(true)

    expect(TTY::Which.executable_file?("ruby", "/usr/local/bin")).to eq(true)
  end

  it "checks if only a file is executable" do
    allow(::File).to receive(:file?).and_call_original
    allow(::File).to receive(:file?).with("ruby").and_return(true)
    allow(::File).to receive(:executable?).with("ruby").and_return(true)

    expect(TTY::Which.executable_file?("ruby")).to eql(true)
  end
end