brew/Library/Homebrew/test/cask/cmd/style_spec.rb

69 lines
1.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "open3"
require "rubygems"
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
describe "#cask_paths" do
subject { cli.cask_paths }
before do
2017-05-21 02:32:46 +02:00
allow(cli).to receive(:args).and_return(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
it {
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"),
)
}
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"] }
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
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] }
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