Convert List test to spec.

This commit is contained in:
Markus Reiter 2017-02-08 12:37:45 +01:00
parent cd4705b7bc
commit bcaa13b750
2 changed files with 50 additions and 22 deletions

View File

@ -1,16 +1,16 @@
require "test_helper" require "spec_helper"
describe Hbc::CLI::List do describe Hbc::CLI::List do
it "lists the installed Casks in a pretty fashion" do it "lists the installed Casks in a pretty fashion" do
casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) }
casks.each do |c| casks.each do |c|
TestHelper.install_with_caskfile(c) InstallHelper.install_with_caskfile(c)
end end
lambda { expect {
Hbc::CLI::List.run Hbc::CLI::List.run
}.must_output <<-EOS.undent }.to output(<<-EOS.undent).to_stdout
local-caffeine local-caffeine
local-transmission local-transmission
EOS EOS
@ -18,7 +18,7 @@ describe Hbc::CLI::List do
describe "lists versions" do describe "lists versions" do
let(:casks) { ["local-caffeine", "local-transmission"] } let(:casks) { ["local-caffeine", "local-transmission"] }
let(:output) { let(:expected_output) {
<<-EOS.undent <<-EOS.undent
local-caffeine 1.2.3 local-caffeine 1.2.3
local-transmission 2.61 local-transmission 2.61
@ -26,19 +26,19 @@ describe Hbc::CLI::List do
} }
before(:each) do before(:each) do
casks.map(&Hbc.method(:load)).each(&TestHelper.method(:install_with_caskfile)) casks.map(&Hbc.method(:load)).each(&InstallHelper.method(:install_with_caskfile))
end end
it "of all installed Casks" do it "of all installed Casks" do
lambda { expect {
Hbc::CLI::List.run("--versions") Hbc::CLI::List.run("--versions")
}.must_output(output) }.to output(expected_output).to_stdout
end end
it "of given Casks" do it "of given Casks" do
lambda { expect {
Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission") Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission")
}.must_output(output) }.to output(expected_output).to_stdout
end end
end end
@ -50,14 +50,10 @@ describe Hbc::CLI::List do
staged_path.mkpath staged_path.mkpath
end end
after do
caskroom_path.rmtree
end
it "lists installed Casks without backing ruby files (due to renames or otherwise)" do it "lists installed Casks without backing ruby files (due to renames or otherwise)" do
lambda { expect {
Hbc::CLI::List.run Hbc::CLI::List.run
}.must_output <<-EOS.undent }.to output(<<-EOS.undent).to_stdout
ive-been-renamed (!) ive-been-renamed (!)
EOS EOS
end end
@ -69,15 +65,15 @@ describe Hbc::CLI::List do
let(:casks) { [caffeine, transmission] } let(:casks) { [caffeine, transmission] }
it "lists the installed files for those Casks" do it "lists the installed files for those Casks" do
casks.each(&TestHelper.method(:install_without_artifacts_with_caskfile)) casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile))
shutup do shutup do
Hbc::Artifact::App.new(transmission).install_phase Hbc::Artifact::App.new(transmission).install_phase
end end
lambda { expect {
Hbc::CLI::List.run("local-transmission", "local-caffeine") Hbc::CLI::List.run("local-transmission", "local-caffeine")
}.must_output <<-EOS.undent }.to output(<<-EOS.undent).to_stdout
==> Apps ==> Apps
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv}) #{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
==> Apps ==> Apps

View File

@ -1,10 +1,42 @@
module InstallHelper module InstallHelper
class << self module_function
def install_without_artifacts(cask)
require "test/support/helper/shutup"
extend Test::Helper::Shutup
def self.install_without_artifacts(cask)
Hbc::Installer.new(cask).tap do |i| Hbc::Installer.new(cask).tap do |i|
shutup do
i.download i.download
i.extract_primary_container i.extract_primary_container
end end
end end
end end
def self.install_without_artifacts_with_caskfile(cask)
Hbc::Installer.new(cask).tap do |i|
shutup do
i.download
i.extract_primary_container
i.save_caskfile
end
end
end
def install_without_artifacts(cask)
Hbc::Installer.new(cask).tap do |i|
shutup do
i.download
i.extract_primary_container
end
end
end
def install_with_caskfile(cask)
Hbc::Installer.new(cask).tap do |i|
shutup do
i.save_caskfile
end
end
end
end end