2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-03 14:05:07 +01:00
|
|
|
require "open3"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
require_relative "shared_examples/invalid_option"
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Cmd::Style, :cask do
|
2016-08-18 22:11:42 +03:00
|
|
|
let(:args) { [] }
|
2017-05-20 03:46:52 +02:00
|
|
|
let(:cli) { described_class.new(*args) }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-03 10:49:58 +02:00
|
|
|
it_behaves_like "a command that handles invalid options"
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2020-09-01 18:31:09 +02:00
|
|
|
describe "::run" do
|
2019-12-01 15:04:30 +00:00
|
|
|
subject { described_class.rubocop(cask_path) }
|
|
|
|
|
|
|
|
context "with a valid Cask" do
|
|
|
|
let(:cask_path) do
|
2020-09-01 18:31:09 +02:00
|
|
|
Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/cask/Casks/version-latest.rb")
|
2019-12-01 15:04:30 +00:00
|
|
|
end
|
|
|
|
|
2020-09-01 18:31:09 +02:00
|
|
|
it "is successful" do
|
|
|
|
expect {
|
|
|
|
described_class.run(cask_path)
|
|
|
|
}.not_to raise_error
|
2019-12-01 15:04:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
describe "#cask_paths" do
|
|
|
|
subject { cli.cask_paths }
|
|
|
|
|
|
|
|
before do
|
2020-08-01 02:30:46 +02:00
|
|
|
allow(cli).to receive(:args).and_return(instance_double(Homebrew::CLI::Args, named: tokens))
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when no cask tokens are given" do
|
|
|
|
let(:tokens) { [] }
|
|
|
|
|
2018-04-14 11:32:29 +02:00
|
|
|
matcher :a_path_ending_with do |end_string|
|
|
|
|
match do |actual|
|
|
|
|
expect(actual.to_s).to end_with(end_string)
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2018-09-02 16:15:09 +01:00
|
|
|
it {
|
2019-09-22 11:41:46 -04:00
|
|
|
expect(subject).to contain_exactly(
|
|
|
|
a_path_ending_with("/homebrew/homebrew-cask/Casks"),
|
|
|
|
a_path_ending_with("/third-party/homebrew-tap/Casks"),
|
|
|
|
a_path_ending_with("/Homebrew/test/support/fixtures/cask/Casks"),
|
|
|
|
a_path_ending_with("/Homebrew/test/support/fixtures/third-party/Casks"),
|
|
|
|
)
|
2018-09-02 16:15:09 +01:00
|
|
|
}
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when at least one cask token is a path that exists" do
|
|
|
|
let(:tokens) { ["adium", "Casks/dropbox.rb"] }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
before do
|
|
|
|
allow(File).to receive(:exist?).and_return(false, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "treats all tokens as paths" do
|
2018-10-17 01:50:39 +02:00
|
|
|
expect(subject).to eq [
|
|
|
|
Pathname("adium").expand_path,
|
|
|
|
Pathname("Casks/dropbox.rb").expand_path,
|
|
|
|
]
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no cask tokens are paths that exist" do
|
|
|
|
let(:tokens) { %w[adium dropbox] }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
before do
|
|
|
|
allow(File).to receive(:exist?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "tries to find paths for all tokens" do
|
2018-09-06 08:29:14 +02:00
|
|
|
expect(Cask::CaskLoader).to receive(:load).twice.and_return(double("cask", sourcefile_path: nil))
|
2016-08-18 22:11:42 +03:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|