aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-08 08:54:20 +0100
committerMarkus Reiter2017-02-10 17:19:19 +0100
commitaf8b91746c8ee67cc5c050fdd4182089171dd0ab (patch)
treea0f8d40d7757707c2b7bfaba790cf7add032e64d /Library
parentfe2829a5d2df373bd2353530e84e4d228efb9d97 (diff)
downloadbrew-af8b91746c8ee67cc5c050fdd4182089171dd0ab.tar.bz2
Convert Accessibility test to spec.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/spec/cask/accessibility_spec.rb82
-rw-r--r--Library/Homebrew/cask/test/cask/accessibility_test.rb77
2 files changed, 82 insertions, 77 deletions
diff --git a/Library/Homebrew/cask/spec/cask/accessibility_spec.rb b/Library/Homebrew/cask/spec/cask/accessibility_spec.rb
new file mode 100644
index 000000000..8787a2c6d
--- /dev/null
+++ b/Library/Homebrew/cask/spec/cask/accessibility_spec.rb
@@ -0,0 +1,82 @@
+require "spec_helper"
+
+# TODO: this test should be named after the corresponding class, once
+# that class is abstracted from installer.rb.
+describe "Accessibility Access" do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") }
+ let(:fake_system_command) { class_double(Hbc::SystemCommand) }
+ let(:installer) { Hbc::Installer.new(cask, command: fake_system_command) }
+
+ before(:each) do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new(macos_version))
+ allow(installer).to receive(:bundle_identifier).and_return("com.example.BasicCask")
+ end
+
+ context "on MacOS 10.8 and below" do
+ let(:macos_version) { "10.8" }
+
+ it "can enable accessibility access in macOS releases prior to Mavericks" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/touch",
+ args: [Hbc.pre_mavericks_accessibility_dotfile],
+ sudo: true
+ )
+
+ shutup do
+ installer.enable_accessibility_access
+ end
+ end
+
+ it "warns about disabling accessibility access on old macOS releases" do
+ expect {
+ installer.disable_accessibility_access
+ }.to output(/Warning: Accessibility access cannot be disabled automatically on this version of macOS\./).to_stderr
+ end
+ end
+
+ context "on MacOS 10.9" do
+ let(:macos_version) { "10.9" }
+
+ it "can enable accessibility access" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/sqlite3",
+ args: [Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"],
+ sudo: true
+ )
+
+ shutup do
+ installer.enable_accessibility_access
+ end
+ end
+
+ it "can disable accessibility access" do
+ expect(fake_system_command).to receive(:run!).with(
+ "/usr/bin/sqlite3",
+ args: [Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"],
+ sudo: true
+ )
+
+ shutup do
+ installer.disable_accessibility_access
+ end
+ end
+ end
+
+ context "on MacOS 10.12 and above" do
+ let(:macos_version) { "10.12" }
+
+ it "warns about enabling accessibility access on new macOS releases" do
+ expect {
+ expect {
+ installer.enable_accessibility_access
+ }.to output.to_stdout
+ }.to output(/Warning: Accessibility access cannot be enabled automatically on this version of macOS\./).to_stderr
+ end
+
+ it "warns about disabling accessibility access on new macOS releases" do
+ expect {
+ installer.disable_accessibility_access
+ }.to output(/Warning: Accessibility access cannot be disabled automatically on this version of macOS\./).to_stderr
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/test/cask/accessibility_test.rb b/Library/Homebrew/cask/test/cask/accessibility_test.rb
deleted file mode 100644
index 657629469..000000000
--- a/Library/Homebrew/cask/test/cask/accessibility_test.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require "test_helper"
-
-# TODO: this test should be named after the corresponding class, once
-# that class is abstracted from installer.rb.
-describe "Accessibility Access" do
- let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") }
- let(:with_fake_command) { { command: Hbc::FakeSystemCommand } }
- let(:installer) { Hbc::Installer.new(cask, with_fake_command) }
-
- describe "install" do
- it "can enable accessibility access" do
- MacOS.stub :version, MacOS::Version.new("10.9") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"]
- )
- shutup do
- installer.enable_accessibility_access
- end
- end
- end
- end
-
- it "can enable accessibility access in macOS releases prior to Mavericks" do
- MacOS.stub :version, MacOS::Version.new("10.8") do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/touch", Hbc.pre_mavericks_accessibility_dotfile]
- )
- shutup do
- installer.enable_accessibility_access
- end
- end
- end
-
- it "warns about enabling accessibility access on new macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.12") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.enable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be enabled automatically on this version of macOS.")
- end
- end
- end
- end
-
- describe "uninstall" do
- it "can disable accessibility access" do
- MacOS.stub :version, MacOS::Version.new("10.9") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- Hbc::FakeSystemCommand.expects_command(
- ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"]
- )
- shutup do
- installer.disable_accessibility_access
- end
- end
- end
- end
-
- it "warns about disabling accessibility access on old macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.8") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.disable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be disabled automatically on this version of macOS.")
- end
- end
- end
-
- it "warns about disabling accessibility access on new macOS releases" do
- MacOS.stub :version, MacOS::Version.new("10.12") do
- installer.stub :bundle_identifier, "com.example.BasicCask" do
- capture_io { installer.disable_accessibility_access }[1]
- .must_match("Warning: Accessibility access cannot be disabled automatically on this version of macOS.")
- end
- end
- end
- end
-end