diff options
| author | Mike McQuaid | 2016-08-19 13:38:09 +0100 |
|---|---|---|
| committer | GitHub | 2016-08-19 13:38:09 +0100 |
| commit | bd1ded93ec46b2ae9c37dbf17dd6d74d3f727440 (patch) | |
| tree | cbe75815cbd4a20fd450429a0091b2997907a0fc /Library/Homebrew/cask/test/support/shared_examples | |
| parent | 9967bc99f030e83f0e16fe279b4ee1d90456da2a (diff) | |
| parent | 092e2797e156a36acd750d2783a18b47305a9747 (diff) | |
| download | brew-bd1ded93ec46b2ae9c37dbf17dd6d74d3f727440.tar.bz2 | |
Merge pull request #725 from AnastasiaSulyagina/move-cask
Move Cask core code to Homebrew
Diffstat (limited to 'Library/Homebrew/cask/test/support/shared_examples')
| -rw-r--r-- | Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb | 23 | ||||
| -rw-r--r-- | Library/Homebrew/cask/test/support/shared_examples/staged.rb | 109 |
2 files changed, 132 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb b/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb new file mode 100644 index 000000000..28115bb4b --- /dev/null +++ b/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb @@ -0,0 +1,23 @@ +require "test_helper" + +shared_examples_for Hbc::DSL::Base do + it "supports the token method" do + dsl.token.must_equal cask.token + end + + it "supports the version method" do + dsl.version.must_equal cask.version + end + + it "supports the caskroom_path method" do + dsl.caskroom_path.must_equal cask.caskroom_path + end + + it "supports the staged_path method" do + dsl.staged_path.must_equal cask.staged_path + end + + it "supports the appdir method" do + dsl.appdir.must_equal cask.appdir + end +end diff --git a/Library/Homebrew/cask/test/support/shared_examples/staged.rb b/Library/Homebrew/cask/test/support/shared_examples/staged.rb new file mode 100644 index 000000000..ef4ff0341 --- /dev/null +++ b/Library/Homebrew/cask/test/support/shared_examples/staged.rb @@ -0,0 +1,109 @@ +require "test_helper" + +shared_examples_for Hbc::Staged do + let(:fake_pathname_exists) { + fake_pathname = Pathname("/path/to/file/that/exists") + fake_pathname.stubs(exist?: true, expand_path: fake_pathname) + fake_pathname + } + + let(:fake_pathname_does_not_exist) { + fake_pathname = Pathname("/path/to/file/that/does/not/exist") + fake_pathname.stubs(exist?: false, expand_path: fake_pathname) + fake_pathname + } + + 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 Hbc.appdir.join("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 + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname] + ) + staged.set_permissions(fake_pathname.to_s, "777") + end + + it "can set the permissions of multiple files" do + fake_pathname = fake_pathname_exists + staged.stubs(:Pathname).returns(fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname, fake_pathname] + ) + staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777") + end + + it "cannot set the permissions of a file that does not exist" do + fake_pathname = fake_pathname_does_not_exist + staged.stubs(Pathname: fake_pathname) + staged.set_permissions(fake_pathname.to_s, "777") + end + + it "can set the ownership of a file" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname] + ) + staged.set_ownership(fake_pathname.to_s) + end + + it "can set the ownership of multiple files" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname, fake_pathname] + ) + staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s]) + end + + it "can set the ownership of a file with a different user and group" do + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "other_user:other_group", fake_pathname] + ) + staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group") + end + + it "cannot set the ownership of a file that does not exist" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_does_not_exist + staged.stubs(Pathname: fake_pathname) + staged.set_ownership(fake_pathname.to_s) + end +end |
