Skip to content

Commit

Permalink
Make Homebrew the default Mas installation method
Browse files Browse the repository at this point in the history
Homebrew is now explicitly stated as the prefered installation
method for Mas, so let's adhere to that recommendation while also
making reattach-to-user-namespace and mac-app-store have the same
defaults.
  • Loading branch information
hartmantis committed Mar 30, 2017
1 parent 4fbf3da commit acedb77
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 97 deletions.
2 changes: 0 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ suites:
apps:
Microsoft Remote Desktop: true
White Noise Free: true
mas:
version: 1.3.1
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Unreleased
- Remove all system_user attributes and properties
- Respect a version property in mac_app_store_mas::install
- Raise an error if trying to use Mas before it's installed
- Make Homebrew the default Mas installation method

v2.1.0 (2016-06-08)
-------------------
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ and value is true to install it or false to not. For example:

default['mac_app_store']['apps']['Growl'] = true

Mas can be installed via GitHub download (`:direct`, the default) or from
`:homebrew`.
Mas can be installed via Homebrew (`:homebrew`, the default) or GitHub
download (`:direct`).

default['mac_app_store']['mas']['source'] = nil

Expand Down Expand Up @@ -102,7 +102,7 @@ Properties:

| Property | Default | Description |
|-------------|-----------------------|------------------------------------------------|
| source | `:direct` | Install from GitHub (`:direct`) or `:homebrew` |
| source | `:homebrew` | Install from `:homebrew` or GitHub (`:direct`) |
| version | `nil` | The version of Mas to install |
| username | `nil` | An Apple ID username |
| password | `nil` | An Apple ID password |
Expand Down
27 changes: 14 additions & 13 deletions libraries/resource_mac_app_store_mas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ class MacAppStoreMas < Resource
provides :mac_app_store_mas, platform_family: 'mac_os_x'

#
# The method of installation for Mas, either :direct (GitHub) or :homebrew
# The method of installation for Mas, either :homebrew or :direct
# (GitHub).
#
property :source,
Symbol,
coerce: proc { |v| v.to_sym },
equal_to: %i(direct homebrew),
default: :direct
equal_to: %i(homebrew direct),
default: :homebrew

#
# Optionally specify a version of Mas to install.
Expand Down Expand Up @@ -88,6 +89,9 @@ class MacAppStoreMas < Resource
#
action :install do
case new_resource.source
when :homebrew
include_recipe 'homebrew'
homebrew_package 'mas'
when :direct
return if current_resource && \
(new_resource.version.nil? || \
Expand All @@ -103,9 +107,6 @@ class MacAppStoreMas < Resource
execute 'Extract Mas-CLI zip file' do
command "unzip -d /usr/local/bin/ -o #{path}"
end
when :homebrew
include_recipe 'homebrew'
homebrew_package 'mas'
end
end

Expand All @@ -115,6 +116,9 @@ class MacAppStoreMas < Resource
#
action :upgrade do
case new_resource.source
when :homebrew
include_recipe 'homebrew'
homebrew_package('mas') { action :upgrade }
when :direct
ver = new_resource.version || \
MacAppStore::Helpers::Mas.latest_version?
Expand All @@ -128,25 +132,22 @@ class MacAppStoreMas < Resource
execute 'Extract Mas-CLI zip file' do
command "unzip -d /usr/local/bin/ -o #{path}"
end
when :homebrew
include_recipe 'homebrew'
homebrew_package('mas') { action :upgrade }
end
end

#
# Uninstall Mas by either deleting the file or removing the Homebrew
# package.
# Uninstall Mas by either removing the Homebrew package or deleting the
# file.
#
action :remove do
return unless current_resource

case new_resource.source
when :direct
file('/usr/local/bin/mas') { action :delete }
when :homebrew
include_recipe 'homebrew'
homebrew_package('mas') { action :remove }
when :direct
file('/usr/local/bin/mas') { action :delete }
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/resources/mac_app_store_mas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
end

before(:each) do
stub_command('which git').and_return('/usr/bin/git')
end

shared_context 'the :install action' do
Expand Down Expand Up @@ -85,14 +86,11 @@
end

shared_context 'an overridden source property' do
let(:source) { :homebrew }

before do
stub_command('which git').and_return('/usr/bin/git')
end
let(:source) { :direct }
end

shared_context 'an overridden version property' do
shared_context 'an overridden source and version property' do
let(:source) { :direct }
let(:version) { '0.1.0' }
end

Expand Down
146 changes: 73 additions & 73 deletions spec/resources/mac_app_store_mas/mac_os_x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,24 @@
context 'not already installed' do
include_context description

it 'downloads mas-cli.zip from GitHub' do
expect(chef_run).to create_remote_file(
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
).with(source: 'https://github.com/mas-cli/mas/releases/download/' \
'v1.3.0/mas-cli.zip')
it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
end

it 'unzips mas-cli.zip into place' do
expect(chef_run).to run_execute('Extract Mas-CLI zip file').with(
command: 'unzip -d /usr/local/bin/ -o ' \
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
)
it 'installs Mas via Homebrew' do
expect(chef_run).to install_homebrew_package('mas')
end
end

context 'already installed' do
include_context description

it 'does not download mas-cli.zip from GitHub' do
expect(chef_run).to_not create_remote_file(
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
)
it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
end

it 'does not unzip mas-cli.zip into place' do
expect(chef_run).to_not run_execute('Extract Mas-CLI zip file')
it 'installs Mas via Homebrew' do
expect(chef_run).to install_homebrew_package('mas')
end
end
end
Expand All @@ -56,29 +48,37 @@
context 'not already installed' do
include_context description

it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
it 'downloads mas-cli.zip from GitHub' do
expect(chef_run).to create_remote_file(
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
).with(source: 'https://github.com/mas-cli/mas/releases/download/' \
'v1.3.0/mas-cli.zip')
end

it 'installs Mas via Homebrew' do
expect(chef_run).to install_homebrew_package('mas')
it 'unzips mas-cli.zip into place' do
expect(chef_run).to run_execute('Extract Mas-CLI zip file').with(
command: 'unzip -d /usr/local/bin/ -o ' \
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
)
end
end

context 'already installed' do
include_context description

it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
it 'does not download mas-cli.zip from GitHub' do
expect(chef_run).to_not create_remote_file(
"#{Chef::Config[:file_cache_path]}/mas-cli.zip"
)
end

it 'installs Mas via Homebrew' do
expect(chef_run).to install_homebrew_package('mas')
it 'does not unzip mas-cli.zip into place' do
expect(chef_run).to_not run_execute('Extract Mas-CLI zip file')
end
end
end

context 'an overridden version property' do
context 'an overridden source and version property' do
include_context description

context 'not already installed' do
Expand Down Expand Up @@ -125,6 +125,38 @@
context 'all default properties' do
include_context description

shared_examples_for 'any installed state' do
it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
end

it 'upgrades Mas via Homebrew' do
expect(chef_run).to upgrade_homebrew_package('mas')
end
end

context 'not already installed' do
include_context description

it_behaves_like 'any installed state'
end

context 'already installed' do
include_context description

it_behaves_like 'any installed state'
end

context 'installed and upgradable' do
include_context description

it_behaves_like 'any installed state'
end
end

context 'an overridden source property' do
include_context description

context 'not already installed' do
include_context description

Expand Down Expand Up @@ -175,38 +207,6 @@
end
end
end

context 'an overridden source property' do
include_context description

shared_examples_for 'any installed state' do
it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
end

it 'upgrades Mas via Homebrew' do
expect(chef_run).to upgrade_homebrew_package('mas')
end
end

context 'not already installed' do
include_context description

it_behaves_like 'any installed state'
end

context 'already installed' do
include_context description

it_behaves_like 'any installed state'
end

context 'installed and upgradable' do
include_context description

it_behaves_like 'any installed state'
end
end
end

context 'the :remove action' do
Expand All @@ -218,14 +218,6 @@
context 'all default properties' do
include_context description

it 'deletes the mas file' do
expect(chef_run).to delete_file('/usr/local/bin/mas')
end
end

context 'an overridden source property' do
include_context description

it 'includes the homebrew default recipe' do
expect(chef_run).to include_recipe('homebrew')
end
Expand All @@ -234,20 +226,20 @@
expect(chef_run).to remove_homebrew_package('mas')
end
end
end

context 'not already installed' do
include_context description

context 'all default properties' do
context 'an overridden source property' do
include_context description

it 'does not delete the mas file' do
expect(chef_run).to_not delete_file('/usr/local/bin/mas')
it 'deletes the mas file' do
expect(chef_run).to delete_file('/usr/local/bin/mas')
end
end
end

context 'an overridden source property' do
context 'not already installed' do
include_context description

context 'all default properties' do
include_context description

it 'does not include the homebrew default recipe' do
Expand All @@ -258,6 +250,14 @@
expect(chef_run).to_not remove_homebrew_package('mas')
end
end

context 'an overridden source property' do
include_context description

it 'does not delete the mas file' do
expect(chef_run).to_not delete_file('/usr/local/bin/mas')
end
end
end
end

Expand Down

0 comments on commit acedb77

Please sign in to comment.