Use shared examples to DRY up *flight tests

This commit is contained in:
Josh Hagins 2015-12-21 19:29:00 -05:00
parent 7b486a827f
commit fbfa795683
5 changed files with 78 additions and 198 deletions

View File

@ -6,72 +6,8 @@ describe Hbc::DSL::Postflight do
@dsl = Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand)
end
it "can run system commands with list-form arguments" do
Hbc::FakeSystemCommand.expects_command(
['echo', 'homebrew-cask', 'rocks!']
)
@dsl.system_command("echo", :args => ["homebrew-cask", "rocks!"])
end
it "can get the Info.plist file for the primary app" do
@dsl.info_plist_file.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
end
it "can execute commands on the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist_file]
)
@dsl.plist_exec('Print CFBundleIdentifier')
end
it "can set a key in the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist_file]
)
@dsl.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
it "can set the permissions of a file" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file')]
)
@dsl.set_permissions('/path/to/file', '777')
end
it "can set the permissions of multiple files" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_permissions(['/path/to/file', '/path/to/other-file'], '777')
end
it "can set the ownership of a file" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file')
end
it "can set the ownership of multiple files" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_ownership(['/path/to/file', '/path/to/other-file'])
end
it "can set the ownership of a file with a different user and group" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'other_user:other_group', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file', user: 'other_user', group: 'other_group')
it_behaves_like Hbc::Staged do
let(:staged) { @dsl }
end
it "can suppress move to applications folder alert " do

View File

@ -6,71 +6,7 @@ describe Hbc::DSL::Preflight do
@dsl = Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand)
end
it "can run system commands with list-form arguments" do
Hbc::FakeSystemCommand.expects_command(
['echo', 'homebrew-cask', 'rocks!']
)
@dsl.system_command("echo", :args => ["homebrew-cask", "rocks!"])
end
it "can get the Info.plist file for the primary app" do
@dsl.info_plist_file.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
end
it "can execute commands on the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist_file]
)
@dsl.plist_exec('Print CFBundleIdentifier')
end
it "can set a key in the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist_file]
)
@dsl.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
it "can set the permissions of a file" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file')]
)
@dsl.set_permissions('/path/to/file', '777')
end
it "can set the permissions of multiple files" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_permissions(['/path/to/file', '/path/to/other-file'], '777')
end
it "can set the ownership of a file" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file')
end
it "can set the ownership of multiple files" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_ownership(['/path/to/file', '/path/to/other-file'])
end
it "can set the ownership of a file with a different user and group" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'other_user:other_group', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file', user: 'other_user', group: 'other_group')
it_behaves_like Hbc::Staged do
let(:staged) { @dsl }
end
end

View File

@ -6,71 +6,7 @@ describe Hbc::DSL::UninstallPreflight do
@dsl = Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand)
end
it "can run system commands with list-form arguments" do
Hbc::FakeSystemCommand.expects_command(
['echo', 'homebrew-cask', 'rocks!']
)
@dsl.system_command("echo", :args => ["homebrew-cask", "rocks!"])
end
it "can get the Info.plist file for the primary app" do
@dsl.info_plist_file.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
end
it "can execute commands on the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist_file]
)
@dsl.plist_exec('Print CFBundleIdentifier')
end
it "can set a key in the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist_file]
)
@dsl.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
it "can set the permissions of a file" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file')]
)
@dsl.set_permissions('/path/to/file', '777')
end
it "can set the permissions of multiple files" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_permissions(['/path/to/file', '/path/to/other-file'], '777')
end
it "can set the ownership of a file" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file')
end
it "can set the ownership of multiple files" do
@dsl.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
@dsl.set_ownership(['/path/to/file', '/path/to/other-file'])
end
it "can set the ownership of a file with a different user and group" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'other_user:other_group', Pathname('/path/to/file')]
)
@dsl.set_ownership('/path/to/file', user: 'other_user', group: 'other_group')
it_behaves_like Hbc::Staged do
let(:staged) { @dsl }
end
end

View File

@ -0,0 +1,71 @@
require 'test_helper'
shared_examples_for Hbc::Staged do
it "can run system commands with list-form arguments" do
Hbc::FakeSystemCommand.expects_command(
['echo', 'homebrew-cask', 'rocks!']
)
staged.system_command("echo", :args => ["homebrew-cask", "rocks!"])
end
it "can get the Info.plist file for the primary app" do
staged.info_plist_file.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
end
it "can execute commands on the Info.plist file" do
staged.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', staged.info_plist_file]
)
staged.plist_exec('Print CFBundleIdentifier')
end
it "can set a key in the Info.plist file" do
staged.stubs(:bundle_identifier => 'com.example.BasicCask')
Hbc::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', staged.info_plist_file]
)
staged.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
it "can set the permissions of a file" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file')]
)
staged.set_permissions('/path/to/file', '777')
end
it "can set the permissions of multiple files" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
staged.set_permissions(['/path/to/file', '/path/to/other-file'], '777')
end
it "can set the ownership of a file" do
staged.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file')]
)
staged.set_ownership('/path/to/file')
end
it "can set the ownership of multiple files" do
staged.stubs(:current_user => 'fake_user')
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', Pathname('/path/to/file'), Pathname('/path/to/other-file')]
)
staged.set_ownership(['/path/to/file', '/path/to/other-file'])
end
it "can set the ownership of a file with a different user and group" do
Hbc::FakeSystemCommand.expects_command(
['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'other_user:other_group', Pathname('/path/to/file')]
)
staged.set_ownership('/path/to/file', user: 'other_user', group: 'other_group')
end
end

View File

@ -120,6 +120,7 @@ end
# Extend MiniTest API with support for RSpec-style shared examples
require 'support/shared_examples'
require 'support/shared_examples/staged.rb'
require 'support/fake_fetcher'
require 'support/fake_dirs'