diff --git a/.rubocop.yml b/.rubocop.yml index 740421f973..ed3de618ae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,16 +4,8 @@ AllCops: TargetRubyVersion: 2.0 Exclude: - '**/Casks/**/*' - - '**/spec/*.rb' - - '**/spec/support/*.rb' - - '**/test/*.rb' - - '**/test/support/*.rb' - 'developer/**/*' - 'lib/vendor/**/*' - - 'spec/cask/**/*' - - 'test/cask/**/*' - - 'test/plist/**/*' - - 'test/support/shared_examples/**/*' Metrics/AbcSize: Enabled: false @@ -37,6 +29,53 @@ Metrics/ModuleLength: - 'lib/hbc/macos.rb' - 'lib/hbc/utils.rb' +Style/BlockDelimiters: + EnforcedStyle: semantic + FunctionalMethods: + - expect + - let + - let! + - subject + - watch + - inject + - map + - map! + - collect + - collect! + - reject + - reject! + - delete_if + - with_object + ProceduralMethods: + - after + - at_exit + - before + - benchmark + - bm + - bmbm + - capture_io + - capture_output + - capture_subprocess_io + - chdir + - context + - create + - each_with_object + - fork + - measure + - new + - open + - realtime + - shutup + - tap + - each + - reverse_each + IgnoredMethods: + - it + - its + - lambda + - proc + + Style/ClassAndModuleChildren: EnforcedStyle: compact diff --git a/developer/bin/generate_cask_token b/developer/bin/generate_cask_token index 4584074c18..401da7adbb 100755 --- a/developer/bin/generate_cask_token +++ b/developer/bin/generate_cask_token @@ -15,12 +15,12 @@ ### dependencies ### -require 'pathname' -require 'open3' +require "pathname" +require "open3" begin # not available by default - require 'active_support/inflector' + require "active_support/inflector" rescue LoadError end @@ -29,95 +29,95 @@ end ### EXPANDED_SYMBOLS = { - '+' => 'plus', - '@' => 'at', - } + "+" => "plus", + "@" => "at", + }.freeze -CASK_FILE_EXTENSION = '.rb' +CASK_FILE_EXTENSION = ".rb".freeze # Hardcode App names that cannot be transformed automatically. # Example: in "x48.app", "x48" is not a version number. # The value in the hash should be a valid Cask token. APP_EXCEPTION_PATS = { - # looks like a trailing version, but is not. - %r{\Aiterm\Z}i => 'iterm2', - %r{\Aiterm2\Z}i => 'iterm2', - %r{\Apgadmin3\Z}i => 'pgadmin3', - %r{\Ax48\Z}i => 'x48', - %r{\Avitamin-r[\s\d\.]*\Z}i => 'vitamin-r', - %r{\Aimagealpha\Z}i => 'imagealpha', - # upstream is in the midst of changing branding - %r{\Abitcoin-?qt\Z}i => 'bitcoin-core', - # "mac" cannot be separated from the name because it is in an English phrase - %r{\Aplayonmac\Z}i => 'playonmac', - %r{\Acleanmymac[\s\d\.]*\Z}i => 'cleanmymac', - # arguably we should not have kept these two exceptions - %r{\Akismac\Z}i => 'kismac', - %r{\Avoicemac\Z}i => 'voicemac', - } + # looks like a trailing version, but is not. + %r{\Aiterm\Z}i => "iterm2", + %r{\Aiterm2\Z}i => "iterm2", + %r{\Apgadmin3\Z}i => "pgadmin3", + %r{\Ax48\Z}i => "x48", + %r{\Avitamin-r[\s\d\.]*\Z}i => "vitamin-r", + %r{\Aimagealpha\Z}i => "imagealpha", + # upstream is in the midst of changing branding + %r{\Abitcoin-?qt\Z}i => "bitcoin-core", + # "mac" cannot be separated from the name because it is in an English phrase + %r{\Aplayonmac\Z}i => "playonmac", + %r{\Acleanmymac[\s\d\.]*\Z}i => "cleanmymac", + # arguably we should not have kept these two exceptions + %r{\Akismac\Z}i => "kismac", + %r{\Avoicemac\Z}i => "voicemac", + }.freeze # Preserve trailing patterns on App names that could be mistaken # for version numbers, etc PRESERVE_TRAILING_PATS = [ - %r{id3}i, - %r{mp3}i, - %r{3[\s-]*d}i, - %r{diff3}i, - %r{\A[^\d]+\+\Z}i, - ] + %r{id3}i, + %r{mp3}i, + %r{3[\s-]*d}i, + %r{diff3}i, + %r{\A[^\d]+\+\Z}i, + ].freeze # The code that employs these patterns against App names # - hacks a \b (word-break) between CamelCase and snake_case transitions # - anchors the pattern to end-of-string # - applies the patterns repeatedly until there is no match REMOVE_TRAILING_PATS = [ - # spaces - %r{\s+}i, + # spaces + %r{\s+}i, - # generic terms - %r{\bapp}i, - %r{\b(?:quick[\s-]*)?launcher}i, + # generic terms + %r{\bapp}i, + %r{\b(?:quick[\s-]*)?launcher}i, - # "mac", "for mac", "for OS X", "macOS", "for macOS". - %r{\b(?:for)?[\s-]*mac(?:intosh|OS)?}i, - %r{\b(?:for)?[\s-]*os[\s-]*x}i, + # "mac", "for mac", "for OS X", "macOS", "for macOS". + %r{\b(?:for)?[\s-]*mac(?:intosh|OS)?}i, + %r{\b(?:for)?[\s-]*os[\s-]*x}i, - # hardware designations such as "for x86", "32-bit", "ppc" - %r{(?:\bfor\s*)?x.?86}i, - %r{(?:\bfor\s*)?\bppc}i, - %r{(?:\bfor\s*)?\d+.?bits?}i, + # hardware designations such as "for x86", "32-bit", "ppc" + %r{(?:\bfor\s*)?x.?86}i, + %r{(?:\bfor\s*)?\bppc}i, + %r{(?:\bfor\s*)?\d+.?bits?}i, - # frameworks - %r{\b(?:for)?[\s-]*(?:oracle|apple|sun)*[\s-]*(?:jvm|java|jre)}i, - %r{\bgtk}i, - %r{\bqt}i, - %r{\bwx}i, - %r{\bcocoa}i, + # frameworks + %r{\b(?:for)?[\s-]*(?:oracle|apple|sun)*[\s-]*(?:jvm|java|jre)}i, + %r{\bgtk}i, + %r{\bqt}i, + %r{\bwx}i, + %r{\bcocoa}i, - # localizations - %r{en\s*-\s*us}i, + # localizations + %r{en\s*-\s*us}i, - # version numbers - %r{[^a-z0-9]+}i, - %r{\b(?:version|alpha|beta|gamma|release|release.?candidate)(?:[\s\.\d-]*\d[\s\.\d-]*)?}i, - %r{\b(?:v|ver|vsn|r|rc)[\s\.\d-]*\d[\s\.\d-]*}i, - %r{\d+(?:[a-z\.]\d+)*}i, - %r{\b\d+\s*[a-z]}i, - %r{\d+\s*[a-c]}i, # constrained to a-c b/c of false positives - ] + # version numbers + %r{[^a-z0-9]+}i, + %r{\b(?:version|alpha|beta|gamma|release|release.?candidate)(?:[\s\.\d-]*\d[\s\.\d-]*)?}i, + %r{\b(?:v|ver|vsn|r|rc)[\s\.\d-]*\d[\s\.\d-]*}i, + %r{\d+(?:[a-z\.]\d+)*}i, + %r{\b\d+\s*[a-z]}i, + %r{\d+\s*[a-c]}i, # constrained to a-c b/c of false positives + ].freeze # Patterns which are permitted (undisturbed) following an interior version number AFTER_INTERIOR_VERSION_PATS = [ - %r{ce}i, - %r{pro}i, - %r{professional}i, - %r{client}i, - %r{server}i, - %r{host}i, - %r{viewer}i, - %r{launcher}i, - %r{installer}i, - ] + %r{ce}i, + %r{pro}i, + %r{professional}i, + %r{client}i, + %r{server}i, + %r{host}i, + %r{viewer}i, + %r{launcher}i, + %r{installer}i, + ].freeze ### ### classes @@ -137,68 +137,65 @@ class AppName < String end def english_from_app_bundle - return self if self.ascii_only? + return self if ascii_only? return self unless File.exist?(self) # check Info.plist CFBundleDisplayName bundle_name = Open3.popen3(*%w[ - /usr/libexec/PlistBuddy -c - ], - 'Print CFBundleDisplayName', - Pathname.new(self).join('Contents', 'Info.plist').to_s - ) do |stdin, stdout, stderr| + /usr/libexec/PlistBuddy -c + ], + "Print CFBundleDisplayName", + Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr| begin stdout.gets.force_encoding("UTF-8").chomp rescue end end - return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only? + return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only? # check Info.plist CFBundleName bundle_name = Open3.popen3(*%w[ - /usr/libexec/PlistBuddy -c - ], - 'Print CFBundleName', - Pathname.new(self).join('Contents', 'Info.plist').to_s - ) do |stdin, stdout, stderr| + /usr/libexec/PlistBuddy -c + ], + "Print CFBundleName", + Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr| begin stdout.gets.force_encoding("UTF-8").chomp rescue end end - return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only? + return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only? # check localization strings - local_strings_file = Pathname.new(self).join('Contents', 'Resources', 'en.lproj', 'InfoPlist.strings') - local_strings_file = Pathname.new(self).join('Contents', 'Resources', 'English.lproj', 'InfoPlist.strings') unless local_strings_file.exist? + local_strings_file = Pathname.new(self).join("Contents", "Resources", "en.lproj", "InfoPlist.strings") + local_strings_file = Pathname.new(self).join("Contents", "Resources", "English.lproj", "InfoPlist.strings") unless local_strings_file.exist? if local_strings_file.exist? - bundle_name = File.open(local_strings_file, 'r:UTF-16LE:UTF-8') do |fh| - %r{\ACFBundle(?:Display)?Name\s*=\s*"(.*)";\Z}.match(fh.readlines.grep(/^CFBundle(?:Display)?Name\s*=\s*/).first) do |match| + bundle_name = File.open(local_strings_file, "r:UTF-16LE:UTF-8") do |fh| + %r{\ACFBundle(?:Display)?Name\s*=\s*"(.*)";\Z}.match(fh.readlines.grep(%r{^CFBundle(?:Display)?Name\s*=\s*}).first) do |match| match.captures.first end end - return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only? + return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only? end # check Info.plist CFBundleExecutable bundle_name = Open3.popen3(*%w[ - /usr/libexec/PlistBuddy -c - ], - 'Print CFBundleExecutable', - Pathname.new(self).join('Contents', 'Info.plist').to_s - ) do |stdin, stdout, stderr| + /usr/libexec/PlistBuddy -c + ], + "Print CFBundleExecutable", + Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr| begin stdout.gets.force_encoding("UTF-8").chomp rescue end end - return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only? + return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only? self end def basename - if Pathname.new(self).exist? then + if Pathname.new(self).exist? AppName.new(Pathname.new(self).basename.to_s) else self @@ -206,56 +203,54 @@ class AppName < String end def remove_extension - self.sub(/\.app\Z/i, '') + sub(%r{\.app\Z}i, "") end def decompose_to_ascii # crudely (and incorrectly) decompose extended latin characters to ASCII - return self if self.ascii_only? - return self unless self.respond_to?(:mb_chars) - AppName.new(self.mb_chars.normalize(:kd).each_char.select(&:ascii_only?).join) + return self if ascii_only? + return self unless respond_to?(:mb_chars) + AppName.new(mb_chars.normalize(:kd).each_char.select(&:ascii_only?).join) end def hardcoded_exception APP_EXCEPTION_PATS.each do |regexp, exception| - if regexp.match(self) then - return AppName.new(exception) - end + return AppName.new(exception) if regexp.match(self) end - return nil + nil end def insert_vertical_tabs_for_camel_case app_name = AppName.new(self) - if app_name.sub!(/(#{self.class.preserve_trailing_pat})\Z/i, '') - trailing = $1 + if app_name.sub!(%r{(#{self.class.preserve_trailing_pat})\Z}i, "") + trailing = Regexp.last_match(1) end - app_name.gsub!(/([^A-Z])([A-Z])/, "\\1\v\\2") - app_name.sub!(/\Z/, trailing) if trailing + app_name.gsub!(%r{([^A-Z])([A-Z])}, "\\1\v\\2") + app_name.sub!(%r{\Z}, trailing) if trailing app_name end def insert_vertical_tabs_for_snake_case - self.gsub(/_/, "\v") + gsub(%r{_}, "\v") end def clean_up_vertical_tabs - self.gsub(/\v/, '') + gsub(%r{\v}, "") end def remove_interior_versions! # done separately from REMOVE_TRAILING_PATS because this # requires a substitution with a backreference - self.sub!(%r{(?<=.)[\.\d]+(#{self.class.after_interior_version_pat})\Z}i, '\1') - self.sub!(%r{(?<=.)[\s\.\d-]*\d[\s\.\d-]*(#{self.class.after_interior_version_pat})\Z}i, '-\1') + sub!(%r{(?<=.)[\.\d]+(#{self.class.after_interior_version_pat})\Z}i, '\1') + sub!(%r{(?<=.)[\s\.\d-]*\d[\s\.\d-]*(#{self.class.after_interior_version_pat})\Z}i, '-\1') end def remove_trailing_strings_and_versions - app_name = self.insert_vertical_tabs_for_camel_case - .insert_vertical_tabs_for_snake_case - while self.class.remove_trailing_pat.match(app_name) and - not self.class.preserve_trailing_pat.match(app_name) - app_name.sub!(self.class.remove_trailing_pat, '') + app_name = insert_vertical_tabs_for_camel_case + .insert_vertical_tabs_for_snake_case + while self.class.remove_trailing_pat.match(app_name) && + !self.class.preserve_trailing_pat.match(app_name) + app_name.sub!(self.class.remove_trailing_pat, "") end app_name.remove_interior_versions! app_name.clean_up_vertical_tabs @@ -263,10 +258,10 @@ class AppName < String def simplified return @simplified if @simplified - @simplified = self.english_from_app_bundle - .basename - .decompose_to_ascii - .remove_extension + @simplified = english_from_app_bundle + .basename + .decompose_to_ascii + .remove_extension @simplified = @simplified.hardcoded_exception || @simplified.remove_trailing_strings_and_versions @simplified end @@ -274,23 +269,23 @@ end class CaskFileName < String def spaces_to_hyphens - self.gsub(/ +/, '-') + gsub(%r{ +}, "-") end def delete_invalid_chars - self.gsub(/[^a-z0-9-]+/, '') + gsub(%r{[^a-z0-9-]+}, "") end def collapse_multiple_hyphens - self.gsub(/--+/, '-') + gsub(%r{--+}, "-") end def delete_leading_hyphens - self.gsub(/^--+/, '') + gsub(%r{^--+}, "") end def delete_hyphens_before_numbers - self.gsub(/-([0-9])/, '\1') + gsub(%r{-([0-9])}, '\1') end def spell_out_symbols @@ -298,32 +293,32 @@ class CaskFileName < String EXPANDED_SYMBOLS.each do |k, v| cask_file_name.gsub!(k, " #{v} ") end - cask_file_name.sub(/ +\Z/, '') + cask_file_name.sub(%r{ +\Z}, "") end def add_extension - self.sub(/(?:#{escaped_cask_file_extension})?\Z/i, CASK_FILE_EXTENSION) + sub(%r{(?:#{escaped_cask_file_extension})?\Z}i, CASK_FILE_EXTENSION) end def remove_extension - self.sub(/#{escaped_cask_file_extension}\Z/i, '') + sub(%r{#{escaped_cask_file_extension}\Z}i, "") end def from_simplified_app_name return @from_simplified_app_name if @from_simplified_app_name - @from_simplified_app_name = if APP_EXCEPTION_PATS.rassoc(self.remove_extension) - self.remove_extension - else - self.remove_extension - .downcase - .spell_out_symbols - .spaces_to_hyphens - .delete_invalid_chars - .collapse_multiple_hyphens - .delete_leading_hyphens - .delete_hyphens_before_numbers + @from_simplified_app_name = if APP_EXCEPTION_PATS.rassoc(remove_extension) + remove_extension + else + remove_extension + .downcase + .spell_out_symbols + .spaces_to_hyphens + .delete_invalid_chars + .collapse_multiple_hyphens + .delete_leading_hyphens + .delete_hyphens_before_numbers end - raise "Could not determine Simplified App name" unless @from_simplified_app_name.length > 0 + raise "Could not determine Simplified App name" if @from_simplified_app_name.empty? @from_simplified_app_name.add_extension end end @@ -335,8 +330,8 @@ end def project_root Dir.chdir File.dirname(File.expand_path(__FILE__)) @git_root ||= Open3.popen3(*%w[ - git rev-parse --show-toplevel - ]) do |stdin, stdout, stderr| + git rev-parse --show-toplevel + ]) do |_stdin, stdout, _stderr| begin Pathname.new(stdout.gets.chomp) rescue @@ -352,7 +347,7 @@ def escaped_cask_file_extension end def simplified_app_name - @simplified_app_name ||= AppName.new("#{ARGV.first}".force_encoding("UTF-8")).simplified + @simplified_app_name ||= AppName.new(ARGV.first.to_s.force_encoding("UTF-8")).simplified end def cask_file_name @@ -367,11 +362,11 @@ def warnings return @warnings if @warnings @warnings = [] unless APP_EXCEPTION_PATS.rassoc(cask_token) - if %r{\d}.match(cask_token) + if %r{\d} =~ cask_token @warnings.push "WARNING: '#{cask_token}' contains digits. Digits which are version numbers should be removed." end end - filename = project_root.join('Casks', cask_file_name) + filename = project_root.join("Casks", cask_file_name) if filename.exist? @warnings.push "WARNING: the file '#{filename}' already exists. Prepend the vendor name if this is not a duplicate." end @@ -383,7 +378,7 @@ def report puts "Proposed token: #{cask_token}" puts "Proposed file name: #{cask_file_name}" puts "Cask Header Line: cask '#{cask_token}' do" - if warnings.length > 0 + unless warnings.empty? $stderr.puts "\n" $stderr.puts warnings $stderr.puts "\n" diff --git a/developer/bin/generate_issue_template_urls b/developer/bin/generate_issue_template_urls index 3baec63850..916d849875 100755 --- a/developer/bin/generate_issue_template_urls +++ b/developer/bin/generate_issue_template_urls @@ -7,13 +7,13 @@ ### dependencies ### -require 'erb' +require "erb" ### ### constants ### -BASE_URL = 'https://github.com/caskroom/homebrew-cask/issues/new' +BASE_URL = "https://github.com/caskroom/homebrew-cask/issues/new".freeze ### ### methods @@ -21,7 +21,7 @@ BASE_URL = 'https://github.com/caskroom/homebrew-cask/issues/new' def main(args) args.each do |file| - File.read(file).scan(/(.*?)\n(.*)/m) do |title, body| + File.read(file).scan(%r{(.*?)\n(.*)}m) do |title, body| puts generate_url(title, body) end end diff --git a/developer/bin/list_login_items_for_app b/developer/bin/list_login_items_for_app index 6bc4703581..ae1dc41536 100755 --- a/developer/bin/list_login_items_for_app +++ b/developer/bin/list_login_items_for_app @@ -7,7 +7,7 @@ ### dependencies ### -require 'open3' +require "open3" ### ### methods @@ -32,7 +32,7 @@ EOS end def process_args - if ARGV.first =~ /^-+h(?:elp)?$/ + if ARGV.first =~ %r{^-+h(?:elp)?$} puts usage exit 0 elsif ARGV.length == 1 @@ -45,7 +45,7 @@ end def list_login_items_for_app(app_path) out, err, status = Open3.capture3( - '/usr/bin/osascript', '-e', + "/usr/bin/osascript", "-e", "tell application \"System Events\" to get the name of every login item " \ "whose path contains \"#{File.basename(app_path)}\"" ) @@ -53,7 +53,7 @@ def list_login_items_for_app(app_path) $stderr.puts err exit status.exitstatus end - puts out.gsub(', ', "\n") + puts out.gsub(", ", "\n") end ### diff --git a/developer/bin/list_running_app_ids b/developer/bin/list_running_app_ids index 430045f9f7..7261f55bfb 100755 --- a/developer/bin/list_running_app_ids +++ b/developer/bin/list_running_app_ids @@ -7,8 +7,8 @@ ### dependencies ### -require 'open3' -require 'set' +require "open3" +require "set" ### ### globals @@ -47,11 +47,11 @@ EOS end def process_args - while ! ARGV.empty? do - if ARGV.first =~ /^-+t(?:est)?$/ and ARGV.length > 1 + until ARGV.empty? + if ARGV.first =~ %r{^-+t(?:est)?$} && ARGV.length > 1 ARGV.shift $opt_test = ARGV.shift - elsif ARGV.first =~ /^-+h(?:elp)?$/ + elsif ARGV.first =~ %r{^-+h(?:elp)?$} puts usage exit 0 else @@ -62,12 +62,12 @@ def process_args end def load_apps - out, err, status = Open3.capture3('/usr/bin/osascript', '-e', 'tell application "System Events" to get (name, bundle identifier, unix id) of every process') + out, err, status = Open3.capture3("/usr/bin/osascript", "-e", 'tell application "System Events" to get (name, bundle identifier, unix id) of every process') if status.exitstatus > 0 puts err exit status.exitstatus end - out = out.split(', ') + out = out.split(", ") one_third = out.length / 3 @app_names = out.shift(one_third) @bundle_ids = out.shift(one_third) @@ -83,15 +83,15 @@ def excluded_bundle_id(bundle_id) end def excluded_app_name(app_name) - %r{^osascript$}.match(app_name) # this script itself + %r{^osascript$}.match(app_name) # this script itself end def report_apps running = Set.new - @app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, unix_id| + @app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, _unix_id| next if excluded_bundle_id bundle_id next if excluded_app_name app_name - bundle_id.gsub!(/^(missing value)$/, '<\1>') + bundle_id.gsub!(%r{^(missing value)$}, '<\1>') running.add "#{bundle_id}\t#{app_name}" end diff --git a/developer/bin/the_long_tail b/developer/bin/the_long_tail index 9e1f2d021a..2a4cb8e7c3 100755 --- a/developer/bin/the_long_tail +++ b/developer/bin/the_long_tail @@ -15,49 +15,49 @@ ### dependencies ### -require 'open3' -require 'set' +require "open3" +require "set" ### ### configurable constants ### BINS = [ - (1..10).to_a, - 100, - 1000, + (1..10).to_a, + 100, + 1000, ].flatten OCCASIONAL_CUTOFF = 5 -CASK_PATH = 'Casks' +CASK_PATH = "Casks".freeze # all maintainers, past and present MAINTAINERS = %w[ - paul.t.hinze@gmail.com - fanquake@users.noreply.github.com - fanquake@gmail.com - kevin@suttle.io - leoj3n@gmail.com - nano@fdp.io - nanoid.xd@gmail.com - me@passcod.name - walker@pobox.com - info@vitorgalvao.com - calebcenter@live.com - ndr@qef.io - josh@joshbutts.com - goxberry@gmail.com - radek.simko@gmail.com - federicobond@gmail.com - claui@users.noreply.github.com - amorymeltzer@gmail.com - hagins.josh@gmail.com - dragon.vctr@gmail.com - mail@sebastianroeder.de - github@adityadalal.com - adityadalal924@users.noreply.github.com - ] + paul.t.hinze@gmail.com + fanquake@users.noreply.github.com + fanquake@gmail.com + kevin@suttle.io + leoj3n@gmail.com + nano@fdp.io + nanoid.xd@gmail.com + me@passcod.name + walker@pobox.com + info@vitorgalvao.com + calebcenter@live.com + ndr@qef.io + josh@joshbutts.com + goxberry@gmail.com + radek.simko@gmail.com + federicobond@gmail.com + claui@users.noreply.github.com + amorymeltzer@gmail.com + hagins.josh@gmail.com + dragon.vctr@gmail.com + mail@sebastianroeder.de + github@adityadalal.com + adityadalal924@users.noreply.github.com + ].freeze ### ### git methods @@ -66,8 +66,8 @@ MAINTAINERS = %w[ def cd_to_project_root Dir.chdir File.dirname(File.expand_path(__FILE__)) @git_root ||= Open3.popen3(*%w[ - git rev-parse --show-toplevel - ]) do |stdin, stdout, stderr| + git rev-parse --show-toplevel + ]) do |_stdin, stdout, _stderr| begin stdout.gets.chomp rescue @@ -79,8 +79,8 @@ end def authors @authors ||= Open3.popen3(*%w[ - git log --no-merges --format=%ae -- - ]) do |stdin, stdout, stderr| + git log --no-merges --format=%ae -- + ]) do |_stdin, stdout, _stderr| h = {} stdout.each_line do |line| line.chomp! @@ -93,14 +93,14 @@ end def casks_by_author @casks_by_author ||= Open3.popen3(*%w[ - git log --no-merges --name-only --format=%ae -- - ], - CASK_PATH) do |stdin, stdout, stderr| + git log --no-merges --name-only --format=%ae -- + ], + CASK_PATH) do |_stdin, stdout, _stderr| email = nil h = {} - stdout.each_line.to_a.join('').split("\n\n").each do |paragraph| - if paragraph.include?('Casks/') - lines=paragraph.split("\n") + stdout.each_line.to_a.join("").split("\n\n").each do |paragraph| + if paragraph.include?("Casks/") + lines = paragraph.split("\n") email = lines.pop h[email] ||= Set.new h[email].merge(lines.compact) @@ -109,7 +109,7 @@ def casks_by_author end end h - end + end end ### @@ -117,10 +117,9 @@ end ### def all_casks - @all_casks ||= Open3.popen3('/usr/bin/find', - CASK_PATH, - *%w[-type f -name *.rb] - ) do |stdin, stdout, stderr| + @all_casks ||= Open3.popen2("/usr/bin/find", + CASK_PATH, + *%w[-type f -name *.rb]) do |_stdin, stdout| stdout.each_line.map(&:chomp) end end @@ -131,13 +130,11 @@ end def histogram if @histogram.nil? - @histogram = Hash[*BINS.map{ |elt| [elt, 0] }.flatten] - authors.each do |name, num_commits| + @histogram = Hash[*BINS.map { |elt| [elt, 0] }.flatten] + authors.each do |_name, num_commits| bottom = 0 BINS.each do |top| - if num_commits >= bottom and num_commits < top - @histogram[bottom] += 1 - end + @histogram[bottom] += 1 if num_commits >= bottom && num_commits < top bottom = top end end @@ -149,7 +146,7 @@ def historic_occasional_cask_set @historic_occasional_cask_set = authors.each.collect do |name, num_commits| if num_commits > OCCASIONAL_CUTOFF nil - elsif ! casks_by_author.key?(name) + elsif !casks_by_author.key?(name) nil else casks_by_author[name].to_a @@ -163,7 +160,7 @@ def extant_occasional_cask_count end def historic_nonmaintainer_cask_set - @historic_nonmaintainer_cask_set = authors.each.collect do |name, num_commits| + @historic_nonmaintainer_cask_set = authors.each.collect do |name, _num_commits| if MAINTAINERS.include?(name) nil else @@ -203,7 +200,7 @@ end def occasional_author_percentage # why is it so hard to slice a hash? @occasional_author_percentage ||= (100 * - (1 .. OCCASIONAL_CUTOFF).to_a.collect{ |bin| histogram[bin] }.reduce(:+) / + (1..OCCASIONAL_CUTOFF).to_a.collect { |bin| histogram[bin] }.reduce(:+) / authors.length).to_i end @@ -227,14 +224,14 @@ end def print_table BINS.each do |bin| - plural = (bin % 10) == 0 ? "'s" : '' - graph = '.' * ((histogram[bin]/graph_normalization) * graph_width) + plural = (bin % 10) == 0 ? "'s" : "" + graph = "." * ((histogram[bin] / graph_normalization) * graph_width) puts "#{bin}#{plural}\t#{histogram[bin]}\t#{graph}" end end def print_footer - puts %Q[\n#{occasional_author_percentage}% of contributors are "occasional" (with <= #{OCCASIONAL_CUTOFF} commits)] + puts %Q{\n#{occasional_author_percentage}% of contributors are "occasional" (with <= #{OCCASIONAL_CUTOFF} commits)} puts "\n#{onetime_author_percentage}% of contributors commit only once" puts "\n#{extant_occasional_cask_percentage}% - #{historic_occasional_cask_percentage}% of Casks depend on an occasional contributor" puts "\n#{extant_nonmaintainer_cask_percentage}% - #{historic_nonmaintainer_cask_percentage}% of Casks depend on a contributor who is not a maintainer" diff --git a/developer/examples/brewcask-doutdated.rb b/developer/examples/brewcask-doutdated.rb index 82474caa6b..de0234c2f1 100755 --- a/developer/examples/brewcask-doutdated.rb +++ b/developer/examples/brewcask-doutdated.rb @@ -5,7 +5,7 @@ # (c) 2014 MIT license # -require 'rubygems' +require "rubygems" class Hbc def installed_version? @@ -14,9 +14,13 @@ class Hbc def installed_version # returns latest installed version if possible - Pathname.glob(caskroom_path.join('*')).map(&:basename).sort{|x,y| + + Pathname.glob(caskroom_path.join("*")).map(&:basename).sort do |x, y| Gem::Version.new(x) <=> Gem::Version.new(y) # throws exception if invalid version is provided ... - }.last rescue nil # ... return nil in this case + end.last + rescue + nil + # ... return nil in this case end def update_available? @@ -36,4 +40,4 @@ end upgradable_casks = Hbc.upgradable -puts upgradable_casks.empty? && 'No outdated packages' || upgradable_casks +puts upgradable_casks.empty? && "No outdated packages" || upgradable_casks diff --git a/lib/hbc/artifact/moved.rb b/lib/hbc/artifact/moved.rb index ba5993705d..90233ca607 100644 --- a/lib/hbc/artifact/moved.rb +++ b/lib/hbc/artifact/moved.rb @@ -2,9 +2,9 @@ require "hbc/artifact/relocated" class Hbc::Artifact::Moved < Hbc::Artifact::Relocated def summary - contents = @cask.artifacts[self.class.artifact_dsl_key].map do |artifact| + contents = @cask.artifacts[self.class.artifact_dsl_key].map { |artifact| summarize_artifact(artifact) - end - [nil] + }.compact { english_description: "#{self.class.artifact_english_name}s managed by brew-cask:", diff --git a/lib/hbc/artifact/uninstall_base.rb b/lib/hbc/artifact/uninstall_base.rb index 804ab06c2a..cf69d301b2 100644 --- a/lib/hbc/artifact/uninstall_base.rb +++ b/lib/hbc/artifact/uninstall_base.rb @@ -30,9 +30,9 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base end def self.remove_relative_path_strings(action, path_strings) - relative = path_strings.map do |path_string| + relative = path_strings.map { |path_string| path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string) - end.compact + }.compact relative.each do |path_string| opoo "Skipping #{action} for relative path #{path_string}" end @@ -40,9 +40,9 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base end def self.remove_undeletable_path_strings(action, path_strings) - undeletable = path_strings.map do |path_string| + undeletable = path_strings.map { |path_string| path_string if Hbc::MacOS.undeletable?(Pathname.new(path_string)) - end.compact + }.compact undeletable.each do |path_string| opoo "Skipping #{action} for undeletable path #{path_string}" end diff --git a/lib/hbc/cask_dependencies.rb b/lib/hbc/cask_dependencies.rb index e5f6e42329..6cbfd05af2 100644 --- a/lib/hbc/cask_dependencies.rb +++ b/lib/hbc/cask_dependencies.rb @@ -11,7 +11,7 @@ class Hbc::CaskDependencies def graph_dependencies deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] } - walk = lambda do |acc, deps| + walk = lambda { |acc, deps| deps.each do |dep| next if acc.key?(dep) succs = deps_in.call Hbc.load(dep) @@ -19,7 +19,7 @@ class Hbc::CaskDependencies walk.call(acc, succs) end acc - end + } graphed = walk.call({}, @cask.depends_on.cask) Hbc::TopologicalHash[graphed] diff --git a/lib/hbc/cli/cleanup.rb b/lib/hbc/cli/cleanup.rb index bfba7564d3..b877b4c315 100644 --- a/lib/hbc/cli/cleanup.rb +++ b/lib/hbc/cli/cleanup.rb @@ -42,7 +42,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base end def cache_incompletes - cache_symlinks.collect do |symlink| + cache_symlinks.collect { |symlink| incomplete_file = Dir.chdir cache_location do f = symlink.readlink f = f.realpath if f.exist? @@ -51,11 +51,11 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base incomplete_file = nil unless incomplete_file.exist? incomplete_file = nil if outdated_only && incomplete_file && incomplete_file.stat.mtime > OUTDATED_TIMESTAMP incomplete_file - end.compact + }.compact end def cache_completes - completes = cache_symlinks.collect do |symlink| + completes = cache_symlinks.collect { |symlink| file = Dir.chdir cache_location do f = symlink.readlink f.exist? ? f.realpath : f @@ -66,7 +66,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base symlink = nil end [symlink, file] - end + } completes .flatten .compact diff --git a/lib/hbc/cli/internal_audit_modified_casks.rb b/lib/hbc/cli/internal_audit_modified_casks.rb index 66b0c06c88..2b48b30dfd 100644 --- a/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/lib/hbc/cli/internal_audit_modified_casks.rb @@ -45,7 +45,10 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase end def run - at_exit { cleanup } + at_exit do + cleanup + end + Dir.chdir git_root do modified_cask_files.zip(modified_casks).each do |cask_file, cask| audit(cask, cask_file) diff --git a/lib/hbc/container/dmg.rb b/lib/hbc/container/dmg.rb index 2b1fe9ad54..03f46e78b5 100644 --- a/lib/hbc/container/dmg.rb +++ b/lib/hbc/container/dmg.rb @@ -40,9 +40,9 @@ class Hbc::Container::Dmg < Hbc::Container::Base def mounts_from_plist(plist) return [] unless plist.respond_to?(:fetch) - plist.fetch("system-entities", []).map do |entity| + plist.fetch("system-entities", []).map { |entity| entity["mount-point"] - end.compact + }.compact end def assert_mounts_found diff --git a/lib/hbc/download_strategy.rb b/lib/hbc/download_strategy.rb index 7e90dfbe2b..0ff15545b7 100644 --- a/lib/hbc/download_strategy.rb +++ b/lib/hbc/download_strategy.rb @@ -39,9 +39,9 @@ class Hbc::HbVCSDownloadStrategy < Hbc::AbstractDownloadStrategy end def extract_ref - key = REF_TYPES.find do |type| + key = REF_TYPES.find { |type| uri_object.respond_to?(type) && uri_object.send(type) - end + } [key, key ? uri_object.send(key) : nil] end diff --git a/lib/hbc/dsl/depends_on.rb b/lib/hbc/dsl/depends_on.rb index 4b515ba77e..47cf89f100 100644 --- a/lib/hbc/dsl/depends_on.rb +++ b/lib/hbc/dsl/depends_on.rb @@ -92,19 +92,19 @@ class Hbc::DSL::DependsOn [[operator, release]] else raise "'depends_on :macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol) - Array(*arg).map do |elt| + Array(*arg).map { |elt| self.class.coerce_os_release(elt) - end.sort + }.sort end @macos.concat(macos) end def arch=(*arg) @arch ||= [] - arches = Array(*arg).map do |elt| + arches = Array(*arg).map { |elt| elt = elt.to_s.downcase.sub(%r{^:}, "").tr("-", "_").to_sym ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt - end + } invalid_arches = arches - VALID_ARCHES raise "invalid 'depends_on :arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty? @arch.concat(arches) diff --git a/lib/hbc/dsl/version.rb b/lib/hbc/dsl/version.rb index 967c8e8b83..e01e67ea29 100644 --- a/lib/hbc/dsl/version.rb +++ b/lib/hbc/dsl/version.rb @@ -47,7 +47,9 @@ class Hbc::DSL::Version < ::String end end - DIVIDERS.keys.each { |divider| define_divider_methods(divider) } + DIVIDERS.keys.each do |divider| + define_divider_methods(divider) + end attr_reader :raw_version diff --git a/lib/hbc/scopes.rb b/lib/hbc/scopes.rb index 4f9df274ce..9bfbbd1fa0 100644 --- a/lib/hbc/scopes.rb +++ b/lib/hbc/scopes.rb @@ -50,9 +50,9 @@ module Hbc::Scopes # TODO: ability to specify expected source when calling Hbc.load (minor perf benefit) installed_cask_dirs.map do |install_dir| cask_token = install_dir.basename.to_s - path_to_cask = all_tapped_cask_dirs.find do |tap_dir| + path_to_cask = all_tapped_cask_dirs.find { |tap_dir| tap_dir.join("#{cask_token}.rb").exist? - end + } @installed[cask_token] ||= if path_to_cask Hbc.load(path_to_cask.join("#{cask_token}.rb")) else diff --git a/lib/hbc/source.rb b/lib/hbc/source.rb index bf92ab2a04..af298108a7 100644 --- a/lib/hbc/source.rb +++ b/lib/hbc/source.rb @@ -24,10 +24,10 @@ module Hbc::Source def self.for_query(query) odebug "Translating '#{query}' into a valid Cask source" raise Hbc::CaskUnavailableError, query if query.to_s =~ %r{^\s*$} - source = sources.find do |s| + source = sources.find { |s| odebug "Testing source class #{s}" s.me?(query) - end + } raise Hbc::CaskUnavailableError, query unless source odebug "Success! Using source class #{source}" resolved_cask_source = source.new(query) diff --git a/lib/hbc/system_command.rb b/lib/hbc/system_command.rb index 94faf705db..1b915f033d 100644 --- a/lib/hbc/system_command.rb +++ b/lib/hbc/system_command.rb @@ -60,13 +60,13 @@ class Hbc::SystemCommand end def expanded_command - @expanded_command ||= command.map do |arg| + @expanded_command ||= command.map { |arg| if arg.respond_to?(:to_path) File.absolute_path(arg) else String(arg) end - end + } end def each_output_line(&b) diff --git a/spec/cask/artifact/binary_spec.rb b/spec/cask/artifact/binary_spec.rb index 144dae6985..81e5c9026b 100644 --- a/spec/cask/artifact/binary_spec.rb +++ b/spec/cask/artifact/binary_spec.rb @@ -1,24 +1,22 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::Artifact::Binary do let(:cask) { - Hbc.load('with-binary').tap do |cask| + Hbc.load("with-binary").tap do |cask| shutup do - InstallHelper::install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end end } let(:expected_path) { - Hbc.binarydir.join('binary') + Hbc.binarydir.join("binary") } - before(:each) { + before(:each) do Hbc.binarydir.mkpath - } - after(:each) { - if expected_path.exist? - FileUtils.rm expected_path - end - } + end + after(:each) do + FileUtils.rm expected_path if expected_path.exist? + end it "links the binary to the proper directory" do shutup do @@ -38,13 +36,13 @@ describe Hbc::Artifact::Binary do end it "clobbers an existing symlink" do - expected_path.make_symlink('/tmp') + expected_path.make_symlink("/tmp") shutup do Hbc::Artifact::Binary.new(cask).install_phase end - expect(File.readlink(expected_path)).not_to eq('/tmp') + expect(File.readlink(expected_path)).not_to eq("/tmp") end it "respects --no-binaries flag" do @@ -71,9 +69,9 @@ describe Hbc::Artifact::Binary do context "binary is inside an app package" do let(:cask) { - Hbc.load('with-embedded-binary').tap do |cask| + Hbc.load("with-embedded-binary").tap do |cask| shutup do - InstallHelper::install_without_artifacts(cask) + InstallHelper.install_without_artifacts(cask) end end } diff --git a/spec/cask/audit_spec.rb b/spec/cask/audit_spec.rb index 636e844213..9917303bc6 100644 --- a/spec/cask/audit_spec.rb +++ b/spec/cask/audit_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::Audit do include AuditMatchers @@ -12,27 +12,33 @@ describe Hbc::Audit do describe "#result" do subject { audit.result } - context 'when there are errors' do - before { audit.add_error 'bad' } - it { should match(/failed/) } - end - - context 'when there are warnings' do - before { audit.add_warning 'eh' } - it { should match(/warning/) } - end - - context 'when there are errors and warnings' do + context "when there are errors" do before do - audit.add_error 'bad' - audit.add_warning 'eh' + audit.add_error "bad" end - it { should match(/failed/) } + it { should match(%r{failed}) } end - context 'when there are no errors or warnings' do - it { should match(/passed/) } + context "when there are warnings" do + before do + audit.add_warning "eh" + end + + it { should match(%r{warning}) } + end + + context "when there are errors and warnings" do + before do + audit.add_error "bad" + audit.add_warning "eh" + end + + it { should match(%r{failed}) } + end + + context "when there are no errors or warnings" do + it { should match(%r{passed}) } end end @@ -44,7 +50,7 @@ describe Hbc::Audit do %w[version sha256 url name homepage license].each do |stanza| context "when missing #{stanza}" do let(:cask_token) { "missing-#{stanza}" } - it { should fail_with(/#{stanza} stanza is required/) } + it { should fail_with(%r{#{stanza} stanza is required}) } end end end @@ -53,59 +59,59 @@ describe Hbc::Audit do let(:error_msg) { "you should use version :latest instead of version 'latest'" } context "when version is 'latest'" do - let(:cask_token) { 'version-latest-string' } + let(:cask_token) { "version-latest-string" } it { should fail_with(error_msg) } end context "when version is :latest" do - let(:cask_token) { 'version-latest-with-checksum' } + let(:cask_token) { "version-latest-with-checksum" } it { should_not fail_with(error_msg) } end end describe "sha256 checks" do context "when version is :latest and sha256 is not :no_check" do - let(:cask_token) { 'version-latest-with-checksum' } - it { should fail_with('you should use sha256 :no_check when version is :latest') } + let(:cask_token) { "version-latest-with-checksum" } + it { should fail_with("you should use sha256 :no_check when version is :latest") } end context "when sha256 is not a legal SHA-256 digest" do - let(:cask_token) { 'invalid-sha256' } - it { should fail_with('sha256 string must be of 64 hexadecimal characters') } + let(:cask_token) { "invalid-sha256" } + it { should fail_with("sha256 string must be of 64 hexadecimal characters") } end context "when sha256 is sha256 for empty string" do - let(:cask_token) { 'sha256-for-empty-string' } - it { should fail_with(/cannot use the sha256 for an empty string/) } + let(:cask_token) { "sha256-for-empty-string" } + it { should fail_with(%r{cannot use the sha256 for an empty string}) } end end describe "appcast checks" do context "when appcast has no sha256" do - let(:cask_token) { 'appcast-missing-checkpoint' } - it { should fail_with(/checkpoint sha256 is required for appcast/) } + let(:cask_token) { "appcast-missing-checkpoint" } + it { should fail_with(%r{checkpoint sha256 is required for appcast}) } end context "when appcast checkpoint is not a string of 64 hexadecimal characters" do - let(:cask_token) { 'appcast-invalid-checkpoint' } - it { should fail_with(/string must be of 64 hexadecimal characters/) } + let(:cask_token) { "appcast-invalid-checkpoint" } + it { should fail_with(%r{string must be of 64 hexadecimal characters}) } end context "when appcast checkpoint is sha256 for empty string" do - let(:cask_token) { 'appcast-checkpoint-sha256-for-empty-string' } - it { should fail_with(/cannot use the sha256 for an empty string/) } + let(:cask_token) { "appcast-checkpoint-sha256-for-empty-string" } + it { should fail_with(%r{cannot use the sha256 for an empty string}) } end context "when appcast checkpoint is valid sha256" do - let(:cask_token) { 'appcast-valid-checkpoint' } - it { should_not fail_with(/appcast :checkpoint/) } + let(:cask_token) { "appcast-valid-checkpoint" } + it { should_not fail_with(%r{appcast :checkpoint}) } end context "when verifying appcast HTTP code" do - let(:cask_token) { 'appcast-valid-checkpoint' } + let(:cask_token) { "appcast-valid-checkpoint" } let(:download) { instance_double(Hbc::Download) } - let(:wrong_code_msg) { /unexpected HTTP response code/ } - let(:curl_error_msg) { /error retrieving appcast/ } + let(:wrong_code_msg) { %r{unexpected HTTP response code} } + let(:curl_error_msg) { %r{error retrieving appcast} } let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) } before do @@ -117,33 +123,39 @@ describe Hbc::Audit do context "when curl succeeds" do let(:success) { true } - before { allow(fake_curl_result).to receive(:stdout).and_return(stdout) } + before do + allow(fake_curl_result).to receive(:stdout).and_return(stdout) + end context "when HTTP code is 200" do - let(:stdout) { '200' } + let(:stdout) { "200" } it { should_not warn_with(wrong_code_msg) } end context "when HTTP code is not 200" do - let(:stdout) { '404' } + let(:stdout) { "404" } it { should warn_with(wrong_code_msg) } end end context "when curl fails" do let(:success) { false } - before { allow(fake_curl_result).to receive(:stderr).and_return('Some curl error') } + + before do + allow(fake_curl_result).to receive(:stderr).and_return("Some curl error") + end + it { should warn_with(curl_error_msg) } end end context "when verifying appcast checkpoint" do - let(:cask_token) { 'appcast-valid-checkpoint' } + let(:cask_token) { "appcast-valid-checkpoint" } let(:download) { instance_double(Hbc::Download) } - let(:mismatch_msg) { /appcast checkpoint mismatch/ } - let(:curl_error_msg) { /error retrieving appcast/ } + let(:mismatch_msg) { %r{appcast checkpoint mismatch} } + let(:curl_error_msg) { %r{error retrieving appcast} } let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) } - let(:expected_checkpoint) { 'd5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2' } + let(:expected_checkpoint) { "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2" } before do allow(audit).to receive(:check_appcast_http_code) @@ -177,7 +189,10 @@ describe Hbc::Audit do context "when appcast download fails" do let(:success) { false } - before { allow(fake_curl_result).to receive(:stderr).and_return('Some curl error') } + + before do + allow(fake_curl_result).to receive(:stderr).and_return("Some curl error") + end it { should warn_with(curl_error_msg) } end @@ -185,54 +200,54 @@ describe Hbc::Audit do end describe "preferred download URL formats" do - let(:warning_msg) { /URL format incorrect/ } + let(:warning_msg) { %r{URL format incorrect} } context "with incorrect SourceForge URL format" do - let(:cask_token) { 'sourceforge-incorrect-url-format' } + let(:cask_token) { "sourceforge-incorrect-url-format" } it { should warn_with(warning_msg) } end context "with correct SourceForge URL format" do - let(:cask_token) { 'sourceforge-correct-url-format' } + let(:cask_token) { "sourceforge-correct-url-format" } it { should_not warn_with(warning_msg) } end context "with correct SourceForge URL format for version :latest" do - let(:cask_token) { 'sourceforge-version-latest-correct-url-format' } + let(:cask_token) { "sourceforge-version-latest-correct-url-format" } it { should_not warn_with(warning_msg) } end context "with incorrect OSDN URL format" do - let(:cask_token) { 'osdn-incorrect-url-format' } + let(:cask_token) { "osdn-incorrect-url-format" } it { should warn_with(warning_msg) } end context "with correct OSDN URL format" do - let(:cask_token) { 'osdn-correct-url-format' } + let(:cask_token) { "osdn-correct-url-format" } it { should_not warn_with(warning_msg) } end end describe "generic artifact checks" do context "with no target" do - let(:cask_token) { 'generic-artifact-no-target' } - it { should fail_with(/target required for generic artifact/) } + let(:cask_token) { "generic-artifact-no-target" } + it { should fail_with(%r{target required for generic artifact}) } end context "with relative target" do - let(:cask_token) { 'generic-artifact-relative-target' } - it { should fail_with(/target must be absolute path for generic artifact/) } + let(:cask_token) { "generic-artifact-relative-target" } + it { should fail_with(%r{target must be absolute path for generic artifact}) } end context "with absolute target" do - let(:cask_token) { 'generic-artifact-absolute-target' } - it { should_not fail_with(/target required for generic artifact/) } + let(:cask_token) { "generic-artifact-absolute-target" } + it { should_not fail_with(%r{target required for generic artifact}) } end end describe "url checks" do context "given a block" do - let(:cask_token) { 'booby-trap' } + let(:cask_token) { "booby-trap" } context "when loading the cask" do it "does not evaluate the block" do @@ -249,7 +264,7 @@ describe Hbc::Audit do end describe "audit of downloads" do - let(:cask_token) { 'with-binary' } + let(:cask_token) { "with-binary" } let(:cask) { Hbc.load(cask_token) } let(:download) { instance_double(Hbc::Download) } let(:verify) { class_double(Hbc::Verify).as_stubbed_const } @@ -261,7 +276,7 @@ describe Hbc::Audit do verify.expects(:all) end - it { should_not fail_with(/#{error_msg}/) } + it { should_not fail_with(%r{#{error_msg}}) } end context "when download fails" do @@ -269,7 +284,7 @@ describe Hbc::Audit do download.expects(:perform).raises(StandardError.new(error_msg)) end - it { should fail_with(/#{error_msg}/) } + it { should fail_with(%r{#{error_msg}}) } end context "when verification fails" do @@ -278,7 +293,7 @@ describe Hbc::Audit do verify.expects(:all).raises(StandardError.new(error_msg)) end - it { should fail_with(/#{error_msg}/) } + it { should fail_with(%r{#{error_msg}}) } end end end diff --git a/spec/cask/cli/cleanup_spec.rb b/spec/cask/cli/cleanup_spec.rb index 2a8dddb8eb..0a6965a4de 100644 --- a/spec/cask/cli/cleanup_spec.rb +++ b/spec/cask/cli/cleanup_spec.rb @@ -1,17 +1,20 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::CLI::Cleanup do let(:homebrew_cache_location) { Pathname(Dir.mktmpdir).realpath } - let(:cache_location) { homebrew_cache_location.join('Casks').tap(&:mkdir) } + let(:cache_location) { homebrew_cache_location.join("Casks").tap(&:mkdir) } let(:cleanup_outdated) { false } subject { described_class.new(cache_location, cleanup_outdated) } - after { homebrew_cache_location.rmtree } - describe 'cleanup!' do - it 'removes dead symlinks' do - bad_symlink = cache_location.join('bad_symlink') - bad_symlink.make_symlink('../does_not_exist') + after do + homebrew_cache_location.rmtree + end + + describe "cleanup!" do + it "removes dead symlinks" do + bad_symlink = cache_location.join("bad_symlink") + bad_symlink.make_symlink("../does_not_exist") expect { subject.cleanup! @@ -25,11 +28,11 @@ describe Hbc::CLI::Cleanup do expect(bad_symlink.symlink?).to eq(false) end - it 'removes cached downloads' do - cached_download = homebrew_cache_location.join('SomeDownload.dmg') + it "removes cached downloads" do + cached_download = homebrew_cache_location.join("SomeDownload.dmg") FileUtils.touch(cached_download) - cached_download_symlink = cache_location.join('SomeDownload.dmg') + cached_download_symlink = cache_location.join("SomeDownload.dmg") cached_download_symlink.make_symlink(cached_download) expect { @@ -46,14 +49,14 @@ describe Hbc::CLI::Cleanup do expect(cached_download_symlink.symlink?).to eq(false) end - context 'when cleanup_outdated is specified' do + context "when cleanup_outdated is specified" do let(:cleanup_outdated) { true } - it 'does not remove cache files newer than 10 days old' do - cached_download = homebrew_cache_location.join('SomeNewDownload.dmg') + it "does not remove cache files newer than 10 days old" do + cached_download = homebrew_cache_location.join("SomeNewDownload.dmg") FileUtils.touch(cached_download) - cached_download_symlink = cache_location.join('SomeNewDownload.dmg') + cached_download_symlink = cache_location.join("SomeNewDownload.dmg") cached_download_symlink.make_symlink(cached_download) expect { @@ -71,4 +74,3 @@ describe Hbc::CLI::Cleanup do end end end - diff --git a/spec/cask/cli/doctor_spec.rb b/spec/cask/cli/doctor_spec.rb index dde6faaacd..3c9c661501 100644 --- a/spec/cask/cli/doctor_spec.rb +++ b/spec/cask/cli/doctor_spec.rb @@ -1,16 +1,16 @@ -require 'spec_helper' -require 'hbc/version' +require "spec_helper" +require "hbc/version" describe Hbc::CLI::Doctor do - it 'displays some nice info about the environment' do + it "displays some nice info about the environment" do expect { Hbc::CLI::Doctor.run - }.to output(/\A==> macOS Release:/).to_stdout + }.to output(%r{\A==> macOS Release:}).to_stdout end it "raises an exception when arguments are given" do expect { - Hbc::CLI::Doctor.run('argument') + Hbc::CLI::Doctor.run("argument") }.to raise_error(ArgumentError) end end diff --git a/spec/cask/cli/style_spec.rb b/spec/cask/cli/style_spec.rb index 917ccb1a14..9214c5b4e3 100644 --- a/spec/cask/cli/style_spec.rb +++ b/spec/cask/cli/style_spec.rb @@ -1,5 +1,5 @@ -require 'English' -require 'spec_helper' +require "English" +require "spec_helper" describe Hbc::CLI::Style do let(:args) { [] } @@ -9,7 +9,7 @@ describe Hbc::CLI::Style do shutup { example.run } end - describe '.run' do + describe ".run" do subject { described_class.run(args) } before do @@ -17,75 +17,77 @@ describe Hbc::CLI::Style do allow(cli).to receive(:run).and_return(retval) end - context 'when rubocop succeeds' do + context "when rubocop succeeds" do let(:retval) { true } - it 'exits successfully' do + it "exits successfully" do subject end end - context 'when rubocop fails' do + context "when rubocop fails" do let(:retval) { false } - it 'raises an exception' do + it "raises an exception" do expect { subject }.to raise_error(Hbc::CaskError) end end end - describe '#run' do + describe "#run" do subject { cli.run } before do allow(cli).to receive_messages(install_rubocop: nil, - system: nil, - rubocop_args: nil, - cask_paths: nil) + system: nil, + rubocop_args: nil, + cask_paths: nil) allow($CHILD_STATUS).to receive(:success?).and_return(success) end - context 'when rubocop succeeds' do + context "when rubocop succeeds" do let(:success) { true } it { is_expected.to be_truthy } end - context 'when rubocop fails' do + context "when rubocop fails" do let(:success) { false } it { is_expected.to be_falsey } end end - describe '#install_rubocop' do + describe "#install_rubocop" do subject { cli.install_rubocop } - shared_examples 'raises error with message' do |msg| - it 'raises an error with an informative message' do + shared_examples "raises error with message" do |msg| + it "raises an error with an informative message" do expect { subject }.to raise_error(Hbc::CaskError, msg) end end - shared_examples 'executable availability' do - before { allow(Hbc::Utils).to receive(:which).and_return(which_retval) } + shared_examples "executable availability" do + before do + allow(Hbc::Utils).to receive(:which).and_return(which_retval) + end - context 'when rubocop is available on the PATH' do + context "when rubocop is available on the PATH" do let(:which_retval) { true } - it 'exits successfully' do + it "exits successfully" do subject end end - context 'when rubocop is not available on the PATH' do + context "when rubocop is not available on the PATH" do let(:which_retval) { false } - include_examples 'raises error with message', /couldn't find 'rubocop'/ + include_examples "raises error with message", %r{couldn't find 'rubocop'} end end let(:fake_gem_specification_class) { Class.new } let(:fake_gem_install_cmd_class) { Class.new } let(:fake_system_exit_exception_class) { Class.new(StandardError) } - let(:fake_install_cmd) { double() } + let(:fake_install_cmd) { double } let(:fake_system_exit_exception) { fake_system_exit_exception_class.new } before do @@ -95,12 +97,12 @@ describe Hbc::CLI::Style do allow(fake_gem_specification_class).to receive(:find_all_by_name).and_return(*returned_specs) end - context 'when rubocop and rubocop-cask are already installed' do - let(:returned_specs) { [['rubocop'], ['rubocop-cask']] } - include_examples 'executable availability' + context "when rubocop and rubocop-cask are already installed" do + let(:returned_specs) { [["rubocop"], ["rubocop-cask"]] } + include_examples "executable availability" end - context 'when rubocop and rubocop-cask are not already installed' do + context "when rubocop and rubocop-cask are not already installed" do let(:returned_specs) { [[]] } before do @@ -111,144 +113,156 @@ describe Hbc::CLI::Style do allow(fake_system_exit_exception).to receive(:exit_code).and_return(install_exit_code) end - context 'when installation succeeds' do + context "when installation succeeds" do let(:install_exit_code) { 0 } - include_examples 'executable availability' + include_examples "executable availability" end - context 'when installation fails' do + context "when installation fails" do let(:install_exit_code) { 1 } - include_examples 'raises error with message', /Failed to install\/update/ + include_examples "raises error with message", %r{Failed to install/update} end end end - describe '#cask_paths' do + describe "#cask_paths" do subject { cli.cask_paths } - before { allow(cli).to receive(:cask_tokens).and_return(tokens) } - - context 'when no cask tokens are given' do - let(:tokens) { [] } - before { allow(Hbc).to receive(:all_tapped_cask_dirs).and_return(['Casks', 'MoreCasks']) } - it { is_expected.to eq(['Casks', 'MoreCasks']) } + before do + allow(cli).to receive(:cask_tokens).and_return(tokens) end - context 'when at least one cask token is a path that exists' do - let(:tokens) { ['adium', 'Casks/dropbox.rb'] } - before { allow(File).to receive(:exist?).and_return(false, true) } + context "when no cask tokens are given" do + let(:tokens) { [] } - it 'treats all tokens as paths' do + before do + allow(Hbc).to receive(:all_tapped_cask_dirs).and_return(%w[Casks MoreCasks]) + end + + it { is_expected.to eq(%w[Casks MoreCasks]) } + end + + context "when at least one cask token is a path that exists" do + let(:tokens) { ["adium", "Casks/dropbox.rb"] } + before do + allow(File).to receive(:exist?).and_return(false, true) + end + + it "treats all tokens as paths" do expect(subject).to eq(tokens) end end - context 'when no cask tokens are paths that exist' do - let(:tokens) { ['adium', 'dropbox'] } - before { allow(File).to receive(:exist?).and_return(false) } + context "when no cask tokens are paths that exist" do + let(:tokens) { %w[adium dropbox] } + before do + allow(File).to receive(:exist?).and_return(false) + end - it 'tries to find paths for all tokens' do + it "tries to find paths for all tokens" do expect(Hbc).to receive(:path).twice subject end end end - describe '#cask_tokens' do + describe "#cask_tokens" do subject { cli.cask_tokens } - context 'when no args are given' do + context "when no args are given" do let(:args) { [] } it { is_expected.to be_empty } end - context 'when only flags are given' do - let(:args) { ['--fix'] } + context "when only flags are given" do + let(:args) { ["--fix"] } it { is_expected.to be_empty } end - context 'when only empty args are given' do - let(:args) { ['', ''] } + context "when only empty args are given" do + let(:args) { ["", ""] } it { is_expected.to be_empty } end - context 'when a cask token is given' do - let(:args) { ['adium'] } - it { is_expected.to eq(['adium']) } + context "when a cask token is given" do + let(:args) { ["adium"] } + it { is_expected.to eq(["adium"]) } end - context 'when multiple cask tokens are given' do - let(:args) { ['adium', 'dropbox'] } - it { is_expected.to eq(['adium', 'dropbox']) } + context "when multiple cask tokens are given" do + let(:args) { %w[adium dropbox] } + it { is_expected.to eq(%w[adium dropbox]) } end - context 'when cask tokens are given with flags' do - let(:args) { ['adium', 'dropbox', '--fix'] } - it { is_expected.to eq(['adium', 'dropbox']) } + context "when cask tokens are given with flags" do + let(:args) { ["adium", "dropbox", "--fix"] } + it { is_expected.to eq(%w[adium dropbox]) } end end - describe '#rubocop_args' do + describe "#rubocop_args" do subject { cli.rubocop_args } before do allow(cli).to receive(:fix?).and_return(fix) end - context 'when fix? is true' do + context "when fix? is true" do let(:fix) { true } - it { is_expected.to include('--auto-correct') } + it { is_expected.to include("--auto-correct") } end - context 'when fix? is false' do + context "when fix? is false" do let(:fix) { false } - it { is_expected.not_to include('--auto-correct') } + it { is_expected.not_to include("--auto-correct") } end end - describe '#default_args' do + describe "#default_args" do subject { cli.default_args } - let(:rubocop_config) { '.rubocop.yml' } - before { allow(cli).to receive(:rubocop_config).and_return(rubocop_config) } + let(:rubocop_config) { ".rubocop.yml" } + before do + allow(cli).to receive(:rubocop_config).and_return(rubocop_config) + end - it { is_expected.to include('--format', 'simple', '--force-exclusion', '--config', rubocop_config) } + it { is_expected.to include("--format", "simple", "--force-exclusion", "--config", rubocop_config) } end - describe '#autocorrect_args' do + describe "#autocorrect_args" do subject { cli.autocorrect_args } - let(:default_args) { ['--format', 'simple'] } + let(:default_args) { ["--format", "simple"] } - it 'should add --auto-correct to default args' do + it "should add --auto-correct to default args" do allow(cli).to receive(:default_args).and_return(default_args) - expect(subject).to include('--auto-correct', *default_args) + expect(subject).to include("--auto-correct", *default_args) end end - describe '#fix?' do + describe "#fix?" do subject { cli.fix? } - context 'when --fix is passed as an argument' do - let(:args) { ['adium', '--fix'] } + context "when --fix is passed as an argument" do + let(:args) { ["adium", "--fix"] } it { should be_truthy } end - context 'when --correct is passed as an argument' do - let(:args) { ['adium', '--correct'] } + context "when --correct is passed as an argument" do + let(:args) { ["adium", "--correct"] } it { should be_truthy } end - context 'when --auto-correct is passed as an argument' do - let(:args) { ['adium', '--auto-correct'] } + context "when --auto-correct is passed as an argument" do + let(:args) { ["adium", "--auto-correct"] } it { should be_truthy } end - context 'when --auto-correct is misspelled as --autocorrect' do - let(:args) { ['adium', '--autocorrect'] } + context "when --auto-correct is misspelled as --autocorrect" do + let(:args) { ["adium", "--autocorrect"] } it { should be_truthy } end - context 'when no flag equivalent to --fix is passed as an argument' do - let(:args) { ['adium'] } + context "when no flag equivalent to --fix is passed as an argument" do + let(:args) { ["adium"] } it { should be_falsey } end end diff --git a/spec/cask/cli_spec.rb b/spec/cask/cli_spec.rb index c127f3d241..cb21dbd25c 100644 --- a/spec/cask/cli_spec.rb +++ b/spec/cask/cli_spec.rb @@ -1,26 +1,26 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::CLI do it "lists the taps for Casks that show up in two taps" do listing = Hbc::CLI.nice_listing(%w[ - caskroom/cask/adium - caskroom/cask/google-chrome - passcod/homebrew-cask/adium - ]) + caskroom/cask/adium + caskroom/cask/google-chrome + passcod/homebrew-cask/adium + ]) expect(listing).to eq(%w[ - caskroom/cask/adium - google-chrome - passcod/cask/adium - ]) + caskroom/cask/adium + google-chrome + passcod/cask/adium + ]) end context ".process" do - let(:noop_command) { double('CLI::Noop') } + let(:noop_command) { double("CLI::Noop") } before do allow(Hbc).to receive(:init) - allow(described_class).to receive(:lookup_command).with('noop').and_return(noop_command) + allow(described_class).to receive(:lookup_command).with("noop").and_return(noop_command) allow(noop_command).to receive(:run) end @@ -29,35 +29,35 @@ describe Hbc::CLI do end it "passes `--version` along to the subcommand" do - expect(described_class).to receive(:run_command).with(noop_command, '--version') + expect(described_class).to receive(:run_command).with(noop_command, "--version") described_class.process(%w[noop --version]) end it "prints help output when subcommand receives `--help` flag" do - expect(described_class).to receive(:run_command).with('help') + expect(described_class).to receive(:run_command).with("help") described_class.process(%w[noop --help]) expect(Hbc.help).to eq(true) Hbc.help = false end it "respects the env variable when choosing what appdir to create" do - EnvHelper.with_env_var('HOMEBREW_CASK_OPTS', "--appdir=/custom/appdir") do - expect(Hbc).to receive(:appdir=).with(Pathname('/custom/appdir')) - described_class.process('noop') + EnvHelper.with_env_var("HOMEBREW_CASK_OPTS", "--appdir=/custom/appdir") do + expect(Hbc).to receive(:appdir=).with(Pathname("/custom/appdir")) + described_class.process("noop") end end it "respects the env variable when choosing a non-default Caskroom location" do - EnvHelper.with_env_var 'HOMEBREW_CASK_OPTS', "--caskroom=/custom/caskdir" do - expect(Hbc).to receive(:caskroom=).with(Pathname('/custom/caskdir')) - described_class.process('noop') + EnvHelper.with_env_var "HOMEBREW_CASK_OPTS", "--caskroom=/custom/caskdir" do + expect(Hbc).to receive(:caskroom=).with(Pathname("/custom/caskdir")) + described_class.process("noop") end end it "exits with a status of 1 when something goes wrong" do allow(described_class).to receive(:lookup_command).and_raise(Hbc::CaskError) expect(described_class).to receive(:exit).with(1) - described_class.process('noop') + described_class.process("noop") end end end diff --git a/spec/cask/download_strategy_spec.rb b/spec/cask/download_strategy_spec.rb index 22a35d90ae..9b1c4d8e3c 100644 --- a/spec/cask/download_strategy_spec.rb +++ b/spec/cask/download_strategy_spec.rb @@ -1,14 +1,12 @@ -require 'spec_helper' +require "spec_helper" -describe 'download strategies' do - let(:url) { 'http://example.com/cask.dmg' } +describe "download strategies" do + let(:url) { "http://example.com/cask.dmg" } let(:url_options) { Hash.new } let(:cask) { - instance_double(Hbc::Cask, - :token => 'some-cask', - :url => Hbc::URL.new(url, url_options), - :version => '1.2.3.4' - ) + instance_double(Hbc::Cask, token: "some-cask", + url: Hbc::URL.new(url, url_options), + version: "1.2.3.4") } describe Hbc::CurlDownloadStrategy do @@ -18,13 +16,13 @@ describe 'download strategies' do allow(downloader.temporary_path).to receive(:rename) end - it 'properly assigns a name and uri based on the Cask' do - expect(downloader.name).to eq('some-cask') - expect(downloader.url).to eq('http://example.com/cask.dmg') - expect(downloader.version.to_s).to eq('1.2.3.4') + it "properly assigns a name and uri based on the Cask" do + expect(downloader.name).to eq("some-cask") + expect(downloader.url).to eq("http://example.com/cask.dmg") + expect(downloader.version.to_s).to eq("1.2.3.4") end - it 'calls curl with default arguments for a simple Cask' do + it "calls curl with default arguments for a simple Cask" do allow(downloader).to receive(:curl) shutup do @@ -33,71 +31,75 @@ describe 'download strategies' do expect(downloader).to have_received(:curl).with( cask.url.to_s, - '-C', 0, - '-o', kind_of(Pathname) + "-C", 0, + "-o", kind_of(Pathname) ) end - context 'with an explicit user agent' do - let(:url_options) {{ - :user_agent => 'Mozilla/25.0.1' - }} + context "with an explicit user agent" do + let(:url_options) { { user_agent: "Mozilla/25.0.1" } } - it 'adds the appropriate curl args' do + it "adds the appropriate curl args" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-A', 'Mozilla/25.0.1']) + expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/25.0.1"]) end end - context 'with a generalized fake user agent' do - let(:url_options) {{ - :user_agent => :fake - }} + context "with a generalized fake user agent" do + let(:url_options) { { user_agent: :fake } } - it 'adds the appropriate curl args' do + it "adds the appropriate curl args" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-A', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10) http://caskroom.io']) + expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) http://caskroom.io"]) end end - context 'with cookies set' do - let(:url_options) {{ - :cookies => { - :coo => 'kie', - :mon => 'ster' + context "with cookies set" do + let(:url_options) { + { + cookies: { + coo: "kie", + mon: "ster", + }, } - }} + } - it 'adds curl args for cookies' do + it "adds curl args for cookies" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-b', 'coo=kie;mon=ster']) + expect(curl_args.each_cons(2)).to include(["-b", "coo=kie;mon=ster"]) end end - context 'with referer set' do - let(:url_options) {{ - :referer => 'http://somehost/also' - }} + context "with referer set" do + let(:url_options) { { referer: "http://somehost/also" } } - it 'adds curl args for referer' do + it "adds curl args for referer" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-e', 'http://somehost/also']) + expect(curl_args.each_cons(2)).to include(["-e", "http://somehost/also"]) end end end @@ -109,52 +111,55 @@ describe 'download strategies' do allow(downloader.temporary_path).to receive(:rename) end - context 'with :using and :data specified' do - let(:url_options) {{ - :using => :post, - :data => { - :form => 'data', - :is => 'good' + context "with :using and :data specified" do + let(:url_options) { + { + using: :post, + data: { + form: "data", + is: "good", + }, } - }} - it 'adds curl args for post arguments' do + } + + it "adds curl args for post arguments" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-d', 'form=data']) - expect(curl_args.each_cons(2)).to include(['-d', 'is=good']) + expect(curl_args.each_cons(2)).to include(["-d", "form=data"]) + expect(curl_args.each_cons(2)).to include(["-d", "is=good"]) end end - context 'with :using but no :data' do - let(:url_options) {{ - :using => :post - }} + context "with :using but no :data" do + let(:url_options) { { using: :post } } - it 'adds curl args for a POST request' do + it "adds curl args for a POST request" do curl_args = [] allow(downloader).to receive(:curl) { |*args| curl_args = args } - shutup { downloader.fetch } + shutup do + downloader.fetch + end - expect(curl_args.each_cons(2)).to include(['-X', 'POST']) + expect(curl_args.each_cons(2)).to include(["-X", "POST"]) end end end describe Hbc::SubversionDownloadStrategy do - let(:url_options) {{ - :using => :svn - }} + let(:url_options) { { using: :svn } } let(:fake_system_command) { class_double(Hbc::SystemCommand) } let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, fake_system_command) } before do allow(fake_system_command).to receive(:run!) end - it 'returns a tarball path on fetch' do + it "returns a tarball path on fetch" do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) @@ -163,11 +168,13 @@ describe 'download strategies' do expect(retval).to equal(downloader.tarball_path) end - it 'calls fetch_repo with default arguments for a simple Cask' do + it "calls fetch_repo with default arguments for a simple Cask" do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) - shutup { downloader.fetch } + shutup do + downloader.fetch + end expect(downloader).to have_received(:fetch_repo).with( downloader.cached_location, @@ -175,96 +182,111 @@ describe 'download strategies' do ) end - it 'calls svn with default arguments for a simple Cask' do + it "calls svn with default arguments for a simple Cask" do allow(downloader).to receive(:compress) - shutup { downloader.fetch } + shutup do + downloader.fetch + end expect(fake_system_command).to have_received(:run!).with( - '/usr/bin/svn', - hash_including(:args => [ - 'checkout', - '--force', - '--config-option', - 'config:miscellany:use-commit-times=yes', - cask.url.to_s, - downloader.cached_location])) - + "/usr/bin/svn", + hash_including(args: [ + "checkout", + "--force", + "--config-option", + "config:miscellany:use-commit-times=yes", + cask.url.to_s, + downloader.cached_location, + ]) + ) end - context 'with trust_cert set on the URL' do - let(:url_options) {{ - :using => :svn, - :trust_cert => true - }} + context "with trust_cert set on the URL" do + let(:url_options) { + { + using: :svn, + trust_cert: true, + } + } - it 'adds svn arguments for :trust_cert' do + it "adds svn arguments for :trust_cert" do allow(downloader).to receive(:compress) - shutup { downloader.fetch } + shutup do + downloader.fetch + end expect(fake_system_command).to have_received(:run!).with( - '/usr/bin/svn', - hash_including(:args => [ - 'checkout', - '--force', - '--config-option', - 'config:miscellany:use-commit-times=yes', - '--trust-server-cert', - '--non-interactive', - cask.url.to_s, - downloader.cached_location, - ])) + "/usr/bin/svn", + hash_including(args: [ + "checkout", + "--force", + "--config-option", + "config:miscellany:use-commit-times=yes", + "--trust-server-cert", + "--non-interactive", + cask.url.to_s, + downloader.cached_location, + ]) + ) end end - context 'with :revision set on url' do - let(:url_options) {{ - :using => :svn, - :revision => '10' - }} + context "with :revision set on url" do + let(:url_options) { + { + using: :svn, + revision: "10", + } + } - it 'adds svn arguments for :revision' do + it "adds svn arguments for :revision" do allow(downloader).to receive(:compress) - shutup { downloader.fetch } + shutup do + downloader.fetch + end expect(fake_system_command).to have_received(:run!).with( - '/usr/bin/svn', - hash_including(:args => [ - 'checkout', - '--force', - '--config-option', - 'config:miscellany:use-commit-times=yes', - cask.url.to_s, - downloader.cached_location, - '-r', - '10', - ])) - + "/usr/bin/svn", + hash_including(args: [ + "checkout", + "--force", + "--config-option", + "config:miscellany:use-commit-times=yes", + cask.url.to_s, + downloader.cached_location, + "-r", + "10", + ]) + ) end end - it 'runs tar to serialize svn downloads' do + it "runs tar to serialize svn downloads" do # sneaky stub to remake the directory, since homebrew code removes it # before tar is called allow(downloader).to receive(:fetch_repo) { downloader.cached_location.mkdir } - shutup { downloader.fetch } + shutup do + downloader.fetch + end expect(fake_system_command).to have_received(:run!).with( - '/usr/bin/tar', - hash_including(:args => [ - '-s/^\\.//', - '--exclude', - '.svn', - '-cf', - downloader.tarball_path, - '--', - '.', - ])) + "/usr/bin/tar", + hash_including(args: [ + '-s/^\\.//', + "--exclude", + ".svn", + "-cf", + downloader.tarball_path, + "--", + ".", + ]) + ) end end diff --git a/spec/cask/dsl/stanza_proxy_spec.rb b/spec/cask/dsl/stanza_proxy_spec.rb index 4c1ee6aa29..8516f0d382 100644 --- a/spec/cask/dsl/stanza_proxy_spec.rb +++ b/spec/cask/dsl/stanza_proxy_spec.rb @@ -1,31 +1,31 @@ describe Hbc::DSL::StanzaProxy do - let(:stanza_proxy) do - described_class.new(Array) { %i[foo bar cake] } - end + let(:stanza_proxy) { + described_class.new(Array) { %i{foo bar cake} } + } subject { stanza_proxy } it { is_expected.to be_a_proxy } it { is_expected.to respond_to(:pop) } its(:pop) { is_expected.to eq(:cake) } its(:type) { is_expected.to eq(Array) } - its(:to_s) { is_expected.to eq('[:foo, :bar, :cake]') } + its(:to_s) { is_expected.to eq("[:foo, :bar, :cake]") } - describe 'when initialized' do - let(:initializing) do + describe "when initialized" do + let(:initializing) { proc { |b| described_class.new(Array, &b) } - end + } - it 'does not evaluate the block' do + it "does not evaluate the block" do expect(&initializing).not_to yield_control end end - describe 'when receiving a message' do - let(:receiving_a_message) do + describe "when receiving a message" do + let(:receiving_a_message) { proc { |b| described_class.new(Array, &b).to_s } - end + } - it 'evaluates the block' do + it "evaluates the block" do expect(&receiving_a_message).to yield_with_no_args end end diff --git a/spec/cask/dsl/version_spec.rb b/spec/cask/dsl/version_spec.rb index f8cd8792d9..04dcd06ca6 100644 --- a/spec/cask/dsl/version_spec.rb +++ b/spec/cask/dsl/version_spec.rb @@ -1,257 +1,227 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::DSL::Version do include ExpectationsHashHelper let(:version) { described_class.new(raw_version) } - shared_examples 'version equality' do - let(:raw_version) { '1.2.3' } + shared_examples "version equality" do + let(:raw_version) { "1.2.3" } - context 'when other is nil' do + context "when other is nil" do let(:other) { nil } it { should == false } end context "when other is a String" do context "when other == self.raw_version" do - let(:other) { '1.2.3' } + let(:other) { "1.2.3" } it { should == true } end context "when other != self.raw_version" do - let(:other) { '1.2.3.4' } + let(:other) { "1.2.3.4" } it { should == false } end end context "when other is a #{described_class}" do context "when other.raw_version == self.raw_version" do - let(:other) { described_class.new('1.2.3') } + let(:other) { described_class.new("1.2.3") } it { should == true } end context "when other.raw_version != self.raw_version" do - let(:other) { described_class.new('1.2.3.4') } + let(:other) { described_class.new("1.2.3.4") } it { should == false } end end end - describe '#==' do + describe "#==" do subject { version == other } - include_examples 'version equality' + include_examples "version equality" end - describe '#eql?' do + describe "#eql?" do subject { version.eql?(other) } - include_examples 'version equality' + include_examples "version equality" end - shared_examples 'version expectations hash' do |method, hash| + shared_examples "version expectations hash" do |method, hash| subject { version.send(method) } - include_examples 'expectations hash', :raw_version, - { :latest => 'latest', - 'latest' => 'latest', - '' => '', - nil => '' - }.merge(hash) + include_examples "expectations hash", :raw_version, + { :latest => "latest", + "latest" => "latest", + "" => "", + nil => "" }.merge(hash) end - - describe '#latest?' do - include_examples 'version expectations hash', :latest?, { - :latest => true, - 'latest' => true, - '' => false, - nil => false, - '1.2.3' => false - } + describe "#latest?" do + include_examples "version expectations hash", :latest?, + :latest => true, + "latest" => true, + "" => false, + nil => false, + "1.2.3" => false end - describe 'string manipulation helpers' do - describe '#major' do - include_examples 'version expectations hash', :major, { - '1' => '1', - '1.2' => '1', - '1.2.3' => '1', - '1.2.3_4-5' => '1' - } + describe "string manipulation helpers" do + describe "#major" do + include_examples "version expectations hash", :major, + "1" => "1", + "1.2" => "1", + "1.2.3" => "1", + "1.2.3_4-5" => "1" end - describe '#minor' do - include_examples 'version expectations hash', :minor, { - '1' => '', - '1.2' => '2', - '1.2.3' => '2', - '1.2.3_4-5' => '2' - } + describe "#minor" do + include_examples "version expectations hash", :minor, + "1" => "", + "1.2" => "2", + "1.2.3" => "2", + "1.2.3_4-5" => "2" end - describe '#patch' do - include_examples 'version expectations hash', :patch, { - '1' => '', - '1.2' => '', - '1.2.3' => '3', - '1.2.3_4-5' => '3' - } + describe "#patch" do + include_examples "version expectations hash", :patch, + "1" => "", + "1.2" => "", + "1.2.3" => "3", + "1.2.3_4-5" => "3" end - describe '#major_minor' do - include_examples 'version expectations hash', :major_minor, { - '1' => '1', - '1.2' => '1.2', - '1.2.3' => '1.2', - '1.2.3_4-5' => '1.2' - } + describe "#major_minor" do + include_examples "version expectations hash", :major_minor, + "1" => "1", + "1.2" => "1.2", + "1.2.3" => "1.2", + "1.2.3_4-5" => "1.2" end - describe '#major_minor_patch' do - include_examples 'version expectations hash', :major_minor_patch, { - '1' => '1', - '1.2' => '1.2', - '1.2.3' => '1.2.3', - '1.2.3_4-5' => '1.2.3' - } + describe "#major_minor_patch" do + include_examples "version expectations hash", :major_minor_patch, + "1" => "1", + "1.2" => "1.2", + "1.2.3" => "1.2.3", + "1.2.3_4-5" => "1.2.3" end - describe '#before_comma' do - include_examples 'version expectations hash', :before_comma, { - '1.2.3' => '1.2.3', - '1.2.3,' => '1.2.3', - ',abc' => '', - '1.2.3,abc' => '1.2.3' - } + describe "#before_comma" do + include_examples "version expectations hash", :before_comma, + "1.2.3" => "1.2.3", + "1.2.3," => "1.2.3", + ",abc" => "", + "1.2.3,abc" => "1.2.3" end - describe '#after_comma' do - include_examples 'version expectations hash', :after_comma, { - '1.2.3' => '', - '1.2.3,' => '', - ',abc' => 'abc', - '1.2.3,abc' => 'abc' - } + describe "#after_comma" do + include_examples "version expectations hash", :after_comma, + "1.2.3" => "", + "1.2.3," => "", + ",abc" => "abc", + "1.2.3,abc" => "abc" end - - describe '#before_colon' do - include_examples 'version expectations hash', :before_colon, { - '1.2.3' => '1.2.3', - '1.2.3:' => '1.2.3', - ':abc' => '', - '1.2.3:abc' => '1.2.3' - } + describe "#before_colon" do + include_examples "version expectations hash", :before_colon, + "1.2.3" => "1.2.3", + "1.2.3:" => "1.2.3", + ":abc" => "", + "1.2.3:abc" => "1.2.3" end - describe '#after_colon' do - include_examples 'version expectations hash', :after_colon, { - '1.2.3' => '', - '1.2.3:' => '', - ':abc' => 'abc', - '1.2.3:abc' => 'abc' - } + describe "#after_colon" do + include_examples "version expectations hash", :after_colon, + "1.2.3" => "", + "1.2.3:" => "", + ":abc" => "abc", + "1.2.3:abc" => "abc" end - describe '#dots_to_hyphens' do - include_examples 'version expectations hash', :dots_to_hyphens, { - '1.2.3_4-5' => '1-2-3_4-5' - } + describe "#dots_to_hyphens" do + include_examples "version expectations hash", :dots_to_hyphens, + "1.2.3_4-5" => "1-2-3_4-5" end - describe '#dots_to_underscores' do - include_examples 'version expectations hash', :dots_to_underscores, { - '1.2.3_4-5' => '1_2_3_4-5' - } + describe "#dots_to_underscores" do + include_examples "version expectations hash", :dots_to_underscores, + "1.2.3_4-5" => "1_2_3_4-5" end - describe '#dots_to_slashes' do - include_examples 'version expectations hash', :dots_to_slashes, { - '1.2.3_4-5' => '1/2/3_4-5' - } + describe "#dots_to_slashes" do + include_examples "version expectations hash", :dots_to_slashes, + "1.2.3_4-5" => "1/2/3_4-5" end - describe '#hyphens_to_dots' do - include_examples 'version expectations hash', :hyphens_to_dots, { - '1.2.3_4-5' => '1.2.3_4.5' - } + describe "#hyphens_to_dots" do + include_examples "version expectations hash", :hyphens_to_dots, + "1.2.3_4-5" => "1.2.3_4.5" end - describe '#hyphens_to_underscores' do - include_examples 'version expectations hash', :hyphens_to_underscores, { - '1.2.3_4-5' => '1.2.3_4_5' - } + describe "#hyphens_to_underscores" do + include_examples "version expectations hash", :hyphens_to_underscores, + "1.2.3_4-5" => "1.2.3_4_5" end - describe '#hyphens_to_slashes' do - include_examples 'version expectations hash', :hyphens_to_slashes, { - '1.2.3_4-5' => '1.2.3_4/5' - } + describe "#hyphens_to_slashes" do + include_examples "version expectations hash", :hyphens_to_slashes, + "1.2.3_4-5" => "1.2.3_4/5" end - describe '#underscores_to_dots' do - include_examples 'version expectations hash', :underscores_to_dots, { - '1.2.3_4-5' => '1.2.3.4-5' - } + describe "#underscores_to_dots" do + include_examples "version expectations hash", :underscores_to_dots, + "1.2.3_4-5" => "1.2.3.4-5" end - describe '#underscores_to_hyphens' do - include_examples 'version expectations hash', :underscores_to_hyphens, { - '1.2.3_4-5' => '1.2.3-4-5' - } + describe "#underscores_to_hyphens" do + include_examples "version expectations hash", :underscores_to_hyphens, + "1.2.3_4-5" => "1.2.3-4-5" end - describe '#underscores_to_slashes' do - include_examples 'version expectations hash', :underscores_to_slashes, { - '1.2.3_4-5' => '1.2.3/4-5' - } + describe "#underscores_to_slashes" do + include_examples "version expectations hash", :underscores_to_slashes, + "1.2.3_4-5" => "1.2.3/4-5" end - describe '#slashes_to_dots' do - include_examples 'version expectations hash', :slashes_to_dots, { - '1.2.3/abc' => '1.2.3.abc' - } + describe "#slashes_to_dots" do + include_examples "version expectations hash", :slashes_to_dots, + "1.2.3/abc" => "1.2.3.abc" end - describe '#slashes_to_hyphens' do - include_examples 'version expectations hash', :slashes_to_hyphens, { - '1.2.3/abc' => '1.2.3-abc' - } + describe "#slashes_to_hyphens" do + include_examples "version expectations hash", :slashes_to_hyphens, + "1.2.3/abc" => "1.2.3-abc" end - describe '#slashes_to_underscores' do - include_examples 'version expectations hash', :slashes_to_underscores, { - '1.2.3/abc' => '1.2.3_abc' - } + describe "#slashes_to_underscores" do + include_examples "version expectations hash", :slashes_to_underscores, + "1.2.3/abc" => "1.2.3_abc" end - describe '#no_dots' do - include_examples 'version expectations hash', :no_dots, { - '1.2.3_4-5' => '123_4-5' - } + describe "#no_dots" do + include_examples "version expectations hash", :no_dots, + "1.2.3_4-5" => "123_4-5" end - describe '#no_hyphens' do - include_examples 'version expectations hash', :no_hyphens, { - '1.2.3_4-5' => '1.2.3_45' - } + describe "#no_hyphens" do + include_examples "version expectations hash", :no_hyphens, + "1.2.3_4-5" => "1.2.3_45" end - describe '#no_underscores' do - include_examples 'version expectations hash', :no_underscores, { - '1.2.3_4-5' => '1.2.34-5' - } + describe "#no_underscores" do + include_examples "version expectations hash", :no_underscores, + "1.2.3_4-5" => "1.2.34-5" end - describe '#no_slashes' do - include_examples 'version expectations hash', :no_slashes, { - '1.2.3/abc' => '1.2.3abc' - } + describe "#no_slashes" do + include_examples "version expectations hash", :no_slashes, + "1.2.3/abc" => "1.2.3abc" end - describe '#no_dividers' do - include_examples 'version expectations hash', :no_dividers, { - '1.2.3_4-5' => '12345' - } + describe "#no_dividers" do + include_examples "version expectations hash", :no_dividers, + "1.2.3_4-5" => "12345" end end end diff --git a/spec/cask/macos_spec.rb b/spec/cask/macos_spec.rb index ec7c803ee4..d06bd2303a 100644 --- a/spec/cask/macos_spec.rb +++ b/spec/cask/macos_spec.rb @@ -1,53 +1,69 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::MacOS do it "says '/' is undeletable" do expect(Hbc::MacOS).to be_undeletable( - '/') + "/" + ) expect(Hbc::MacOS).to be_undeletable( - '/.') + "/." + ) expect(Hbc::MacOS).to be_undeletable( - '/usr/local/Library/Taps/../../../..') + "/usr/local/Library/Taps/../../../.." + ) end it "says '/Applications' is undeletable" do expect(Hbc::MacOS).to be_undeletable( - '/Applications') + "/Applications" + ) expect(Hbc::MacOS).to be_undeletable( - '/Applications/') + "/Applications/" + ) expect(Hbc::MacOS).to be_undeletable( - '/Applications/.') + "/Applications/." + ) expect(Hbc::MacOS).to be_undeletable( - '/Applications/Mail.app/..') + "/Applications/Mail.app/.." + ) end it "says the home directory is undeletable" do expect(Hbc::MacOS).to be_undeletable( - Dir.home) + Dir.home + ) expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/") + "#{Dir.home}/" + ) expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/Documents/..") + "#{Dir.home}/Documents/.." + ) end it "says the user library directory is undeletable" do expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/Library") + "#{Dir.home}/Library" + ) expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/Library/") + "#{Dir.home}/Library/" + ) expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/Library/.") + "#{Dir.home}/Library/." + ) expect(Hbc::MacOS).to be_undeletable( - "#{ Dir.home }/Library/Preferences/..") + "#{Dir.home}/Library/Preferences/.." + ) end it "says '/Applications/.app' is deletable" do expect(Hbc::MacOS).not_to be_undeletable( - '/Applications/.app') + "/Applications/.app" + ) end it "says '/Applications/SnakeOil Professional.app' is deletable" do expect(Hbc::MacOS).not_to be_undeletable( - '/Applications/SnakeOil Professional.app') + "/Applications/SnakeOil Professional.app" + ) end end diff --git a/spec/cask/scopes_spec.rb b/spec/cask/scopes_spec.rb index 602a6d79e5..0e592c9909 100644 --- a/spec/cask/scopes_spec.rb +++ b/spec/cask/scopes_spec.rb @@ -1,38 +1,41 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::Scopes do - describe 'installed' do + describe "installed" do let(:fake_caskroom) { Pathname(Dir.mktmpdir) } before do allow(Hbc).to receive(:caskroom) { fake_caskroom } end - after { fake_caskroom.rmtree } - it 'returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom' do + after do + fake_caskroom.rmtree + end + + it "returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom" do allow(Hbc).to receive(:load) { |token| "loaded-#{token}" } - fake_caskroom.join('cask-bar').mkdir - fake_caskroom.join('cask-foo').mkdir + fake_caskroom.join("cask-bar").mkdir + fake_caskroom.join("cask-foo").mkdir installed_casks = Hbc.installed - expect(Hbc).to have_received(:load).with('cask-bar') - expect(Hbc).to have_received(:load).with('cask-foo') + expect(Hbc).to have_received(:load).with("cask-bar") + expect(Hbc).to have_received(:load).with("cask-foo") expect(installed_casks).to eq(%w[ - loaded-cask-bar - loaded-cask-foo - ]) + loaded-cask-bar + loaded-cask-foo + ]) end - it 'optimizes performance by resolving to a fully qualified path before calling Hbc.load' do - fake_tapped_cask_dir = Pathname(Dir.mktmpdir).join('Casks') - absolute_path_to_cask = fake_tapped_cask_dir.join('some-cask.rb') + it "optimizes performance by resolving to a fully qualified path before calling Hbc.load" do + fake_tapped_cask_dir = Pathname(Dir.mktmpdir).join("Casks") + absolute_path_to_cask = fake_tapped_cask_dir.join("some-cask.rb") allow(Hbc).to receive(:load) allow(Hbc).to receive(:all_tapped_cask_dirs) { [fake_tapped_cask_dir] } - fake_caskroom.join('some-cask').mkdir + fake_caskroom.join("some-cask").mkdir fake_tapped_cask_dir.mkdir FileUtils.touch(absolute_path_to_cask) diff --git a/spec/cask/system_command_spec.rb b/spec/cask/system_command_spec.rb index 35cc48a2db..e85a1976a4 100644 --- a/spec/cask/system_command_spec.rb +++ b/spec/cask/system_command_spec.rb @@ -1,9 +1,9 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::SystemCommand do describe "when the exit code is 0" do describe "its result" do - subject { described_class.run('/usr/bin/true') } + subject { described_class.run("/usr/bin/true") } it { is_expected.to be_a_success } its(:exit_status) { is_expected.to eq(0) } @@ -11,7 +11,7 @@ describe Hbc::SystemCommand do end describe "when the exit code is 1" do - let(:command) { '/usr/bin/false' } + let(:command) { "/usr/bin/false" } describe "and the command must succeed" do it "throws an error" do @@ -32,10 +32,12 @@ describe Hbc::SystemCommand do end describe "given a pathname" do - let(:command) { '/bin/ls' } + let(:command) { "/bin/ls" } let(:path) { Pathname(Dir.mktmpdir) } - before { FileUtils.touch(path.join('somefile')) } + before do + FileUtils.touch(path.join("somefile")) + end describe "its result" do subject { described_class.run(command, args: [path]) } @@ -46,13 +48,13 @@ describe Hbc::SystemCommand do end describe "with both STDOUT and STDERR output from upstream" do - let(:command) { '/bin/bash' } - let(:options) do + let(:command) { "/bin/bash" } + let(:options) { { args: [ - '-c', - 'for i in $(seq 1 2 5); do echo $i; echo $(($i + 1)) >&2; done' - ] } - end + "-c", + "for i in $(seq 1 2 5); do echo $i; echo $(($i + 1)) >&2; done", + ] } + } shared_examples "it returns '1 2 3 4 5 6'" do describe "its result" do @@ -66,21 +68,25 @@ describe Hbc::SystemCommand do describe "with default options" do it "echoes only STDERR" do - expected = [2, 4, 6].map { |i| "==> #{ i }\n" }.join('') - expect { described_class.run(command, options) - }.to output(expected).to_stdout + expected = [2, 4, 6].map { |i| "==> #{i}\n" }.join("") + expect { + described_class.run(command, options) + }.to output(expected).to_stdout end include_examples("it returns '1 2 3 4 5 6'") end describe "with print_stdout" do - before { options.merge!(print_stdout: true) } + before do + options.merge!(print_stdout: true) + end it "echoes both STDOUT and STDERR" do (1..6).each do |i| - expect { described_class.run(command, options) - }.to output(/==> #{ i }/).to_stdout + expect { + described_class.run(command, options) + }.to output(%r{==> #{ i }}).to_stdout end end @@ -88,11 +94,14 @@ describe Hbc::SystemCommand do end describe "without print_stderr" do - before { options.merge!(print_stderr: false) } + before do + options.merge!(print_stderr: false) + end it "echoes nothing" do - expect { described_class.run(command, options) - }.to output('').to_stdout + expect { + described_class.run(command, options) + }.to output("").to_stdout end include_examples("it returns '1 2 3 4 5 6'") @@ -104,9 +113,10 @@ describe Hbc::SystemCommand do end it "echoes only STDOUT" do - expected = [1, 3, 5].map { |i| "==> #{ i }\n" }.join('') - expect { described_class.run(command, options) - }.to output(expected).to_stdout + expected = [1, 3, 5].map { |i| "==> #{i}\n" }.join("") + expect { + described_class.run(command, options) + }.to output(expected).to_stdout end include_examples("it returns '1 2 3 4 5 6'") @@ -114,13 +124,13 @@ describe Hbc::SystemCommand do end describe "with a very long STDERR output" do - let(:command) { '/bin/bash' } - let(:options) do + let(:command) { "/bin/bash" } + let(:options) { { args: [ - '-c', - 'for i in $(seq 1 2 100000); do echo $i; echo $(($i + 1)) >&2; done' - ] } - end + "-c", + "for i in $(seq 1 2 100000); do echo $i; echo $(($i + 1)) >&2; done", + ] } + } it "returns without deadlocking" do wait(10).for { diff --git a/spec/cask/underscore_supporting_uri_spec.rb b/spec/cask/underscore_supporting_uri_spec.rb index 10c1f8c68b..a8756fde0c 100644 --- a/spec/cask/underscore_supporting_uri_spec.rb +++ b/spec/cask/underscore_supporting_uri_spec.rb @@ -1,16 +1,16 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::UnderscoreSupportingURI do - describe 'parse' do - it 'works like normal on normal URLs' do - uri = Hbc::UnderscoreSupportingURI.parse('http://example.com/TestCask.dmg') - expect(uri).to eq(URI('http://example.com/TestCask.dmg')) + describe "parse" do + it "works like normal on normal URLs" do + uri = Hbc::UnderscoreSupportingURI.parse("http://example.com/TestCask.dmg") + expect(uri).to eq(URI("http://example.com/TestCask.dmg")) end - it 'works just fine on URIs with underscores' do - uri = Hbc::UnderscoreSupportingURI.parse('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg') - expect(uri.host).to include('_') - expect(uri.to_s).to eq('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg') + it "works just fine on URIs with underscores" do + uri = Hbc::UnderscoreSupportingURI.parse("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") + expect(uri.host).to include("_") + expect(uri.to_s).to eq("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") end end end diff --git a/spec/cask/verify/checksum_spec.rb b/spec/cask/verify/checksum_spec.rb index d42074d988..7209556c9e 100644 --- a/spec/cask/verify/checksum_spec.rb +++ b/spec/cask/verify/checksum_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::Verify::Checksum do include Sha256Helper - let(:cask) { double('cask') } - let(:downloaded_path) { double('downloaded_path') } + let(:cask) { double("cask") } + let(:downloaded_path) { double("downloaded_path") } let(:verification) { described_class.new(cask, downloaded_path) } before do @@ -15,35 +15,35 @@ describe Hbc::Verify::Checksum do shutup { example.run } end - describe '.me?' do + describe ".me?" do subject { described_class.me?(cask) } - context 'sha256 is :no_check' do + context "sha256 is :no_check" do let(:sha256) { :no_check } it { should == false } end - context 'sha256 is nil' do + context "sha256 is nil" do let(:sha256) { nil } it { should == true } end - context 'sha256 is empty' do - let(:sha256) { '' } + context "sha256 is empty" do + let(:sha256) { "" } it { should == true } end - context 'sha256 is a valid shasum' do + context "sha256 is a valid shasum" do let(:sha256) { random_sha256 } it { should == true } end end - describe '#verify' do + describe "#verify" do subject { verification.verify } let(:computed) { random_sha256 } @@ -52,42 +52,42 @@ describe Hbc::Verify::Checksum do allow(verification).to receive(:computed).and_return(computed) end - context 'sha256 matches computed' do + context "sha256 matches computed" do let(:sha256) { computed } - it 'does not raise an error' do + it "does not raise an error" do expect { subject }.to_not raise_error end end - context 'sha256 is :no_check' do + context "sha256 is :no_check" do let(:sha256) { :no_check } - it 'does not raise an error' do + it "does not raise an error" do expect { subject }.to_not raise_error end end - context 'sha256 does not match computed' do + context "sha256 does not match computed" do let(:sha256) { random_sha256 } - it 'raises an error' do + it "raises an error" do expect { subject }.to raise_error(Hbc::CaskSha256MismatchError) end end - context 'sha256 is nil' do + context "sha256 is nil" do let(:sha256) { nil } - it 'raises an error' do + it "raises an error" do expect { subject }.to raise_error(Hbc::CaskSha256MissingError) end end - context 'sha256 is empty' do - let(:sha256) { '' } + context "sha256 is empty" do + let(:sha256) { "" } - it 'raises an error' do + it "raises an error" do expect { subject }.to raise_error(Hbc::CaskSha256MissingError) end end diff --git a/spec/cask/verify_spec.rb b/spec/cask/verify_spec.rb index 446308129e..7df77fea1d 100644 --- a/spec/cask/verify_spec.rb +++ b/spec/cask/verify_spec.rb @@ -1,62 +1,62 @@ -require 'spec_helper' +require "spec_helper" describe Hbc::Verify do - let(:cask) { double('cask') } + let(:cask) { double("cask") } - let(:verification_classes) do + let(:verification_classes) { [ applicable_verification_class, - inapplicable_verification_class + inapplicable_verification_class, ] - end + } - let(:applicable_verification_class) do - double('applicable_verification_class', :me? => true) - end + let(:applicable_verification_class) { + double("applicable_verification_class", me?: true) + } - let(:inapplicable_verification_class) do - double('inapplicable_verification_class', :me? => false) - end + let(:inapplicable_verification_class) { + double("inapplicable_verification_class", me?: false) + } before do - allow(described_class).to receive(:verifications). - and_return(verification_classes) + allow(described_class).to receive(:verifications) + .and_return(verification_classes) end - describe '.for_cask' do + describe ".for_cask" do subject { described_class.for_cask(cask) } - it 'checks applicability of each verification' do + it "checks applicability of each verification" do verification_classes.each do |verify_class| expect(verify_class).to receive(:me?).with(cask) end subject end - it 'includes applicable verifications' do + it "includes applicable verifications" do expect(subject).to include(applicable_verification_class) end - it 'excludes inapplicable verifications' do + it "excludes inapplicable verifications" do expect(subject).to_not include(inapplicable_verification_class) end end - describe '.all' do - let(:downloaded_path) { double('downloaded_path') } - let(:applicable_verification) { double('applicable_verification') } - let(:inapplicable_verification) { double('inapplicable_verification') } + describe ".all" do + let(:downloaded_path) { double("downloaded_path") } + let(:applicable_verification) { double("applicable_verification") } + let(:inapplicable_verification) { double("inapplicable_verification") } subject { described_class.all(cask, downloaded_path) } before do - allow(applicable_verification_class).to receive(:new). - and_return(applicable_verification) - allow(inapplicable_verification_class).to receive(:new). - and_return(inapplicable_verification) + allow(applicable_verification_class).to receive(:new) + .and_return(applicable_verification) + allow(inapplicable_verification_class).to receive(:new) + .and_return(inapplicable_verification) end - it 'runs only applicable verifications' do + it "runs only applicable verifications" do expect(applicable_verification).to receive(:verify) expect(inapplicable_verification).to_not receive(:verify) subject diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fac7b6d3b3..533fb5b470 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,56 +1,52 @@ -require 'pathname' -require 'rspec/its' -require 'rspec/wait' +require "pathname" +require "rspec/its" +require "rspec/wait" -if ENV['COVERAGE'] - require 'coveralls' +if ENV["COVERAGE"] + require "coveralls" Coveralls.wear_merged! end # just in case -if RUBY_VERSION.to_i < 2 - raise 'brew-cask: Ruby 2.0 or greater is required.' -end +raise "brew-cask: Ruby 2.0 or greater is required." if RUBY_VERSION.to_i < 2 project_root = Pathname(File.expand_path("../..", __FILE__)) -Dir["#{project_root}/spec/support/*.rb"].each { |f| require f } +Dir["#{project_root}/spec/support/*.rb"].each(&method(:require)) # TODO: removeme, this is transitional include HomebrewTestingEnvironment # force some environment variables -ENV['HOMEBREW_CASK_OPTS'] = nil +ENV["HOMEBREW_CASK_OPTS"] = nil # from Homebrew. Provides expects method. -require 'mocha/api' +require "mocha/api" # add homebrew-cask lib to load path -$:.push(project_root.join('lib').to_s) +$LOAD_PATH.push(project_root.join("lib").to_s) -require 'hbc' +require "hbc" -module Hbc - class TestCask < Cask; end -end +class Hbc::TestCask < Hbc::Cask; end # override Homebrew locations -Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join('prefix') +Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix") Hbc.homebrew_repository = Hbc.homebrew_prefix Hbc.homebrew_tapspath = nil -Hbc.binarydir = Hbc.homebrew_prefix.join('binarydir').join('bin') -Hbc.appdir = Pathname.new(TEST_TMPDIR).join('appdir') +Hbc.binarydir = Hbc.homebrew_prefix.join("binarydir").join("bin") +Hbc.appdir = Pathname.new(TEST_TMPDIR).join("appdir") # making homebrew's cache dir allows us to actually download Casks in tests HOMEBREW_CACHE.mkpath -HOMEBREW_CACHE.join('Casks').mkpath +HOMEBREW_CACHE.join("Casks").mkpath # Look for Casks in testcasks by default. It is elsewhere required that # the string "test" appear in the directory name. -Hbc.default_tap = project_root.join('spec', 'support') +Hbc.default_tap = project_root.join("spec", "support") # our own testy caskroom -Hbc.caskroom = Hbc.homebrew_prefix.join('TestCaskroom') +Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom") RSpec.configure do |config| config.order = :random diff --git a/spec/support/audit_matchers.rb b/spec/support/audit_matchers.rb index 4c7d6be477..fc1e0e876c 100644 --- a/spec/support/audit_matchers.rb +++ b/spec/support/audit_matchers.rb @@ -8,9 +8,7 @@ module AuditMatchers end matcher :fail do - match do |audit| - audit.errors? - end + match(&:errors?) end matcher :warn do diff --git a/spec/support/env_helper.rb b/spec/support/env_helper.rb index d38b6e92a5..0a302ef45f 100644 --- a/spec/support/env_helper.rb +++ b/spec/support/env_helper.rb @@ -1,10 +1,10 @@ module EnvHelper class << self - def with_env_var(key, val, &block) - was_defined = ENV.key? 'key' - old_value = ENV['key'] + def with_env_var(key, val) + was_defined = ENV.key? "key" + old_value = ENV["key"] ENV[key] = val - block.call + yield ensure if was_defined ENV[key] = old_value diff --git a/spec/support/expectations_hash_helper.rb b/spec/support/expectations_hash_helper.rb index 71b747a36b..8d386767da 100644 --- a/spec/support/expectations_hash_helper.rb +++ b/spec/support/expectations_hash_helper.rb @@ -1,5 +1,5 @@ module ExpectationsHashHelper - shared_examples 'expectations hash' do |input_name, expectations| + shared_examples "expectations hash" do |input_name, expectations| expectations.each do |input_value, expected_output| context "when #{input_name} is #{input_value.inspect}" do let(input_name.to_sym) { input_value } diff --git a/spec/support/file_helper.rb b/spec/support/file_helper.rb index 8445d6fb1c..8eb78f759f 100644 --- a/spec/support/file_helper.rb +++ b/spec/support/file_helper.rb @@ -1,11 +1,11 @@ module FileHelper class << self def local_binary_path(name) - File.expand_path(File.join(File.dirname(__FILE__), 'binaries', name)) + File.expand_path(File.join(File.dirname(__FILE__), "binaries", name)) end def local_binary_url(name) - 'file://' + local_binary_path(name) + "file://" + local_binary_path(name) end def valid_alias?(candidate) diff --git a/spec/support/homebrew_testing_environment.rb b/spec/support/homebrew_testing_environment.rb index 7c454f41f8..5389ff960d 100644 --- a/spec/support/homebrew_testing_environment.rb +++ b/spec/support/homebrew_testing_environment.rb @@ -1,12 +1,12 @@ module HomebrewTestingEnvironment - def self.included(base) + def self.included(*) # force some environment variables - ENV['HOMEBREW_NO_EMOJI']='1' + ENV["HOMEBREW_NO_EMOJI"] = "1" # require homebrew testing env with_disabled_at_exit do # TODO: removeme, this is transitional - require 'vendor/homebrew-fork/testing_env' + require "vendor/homebrew-fork/testing_env" end end end diff --git a/spec/support/kernel_at_exit_hacks.rb b/spec/support/kernel_at_exit_hacks.rb index 624270e247..b5c84869b3 100644 --- a/spec/support/kernel_at_exit_hacks.rb +++ b/spec/support/kernel_at_exit_hacks.rb @@ -1,15 +1,13 @@ module Kernel - alias_method :real_at_exit, :at_exit + alias real_at_exit at_exit def at_exit(&block) - unless ENV['DISABLE_AT_EXIT'] - real_at_exit(&block) - end + real_at_exit(&block) unless ENV["DISABLE_AT_EXIT"] end - def with_disabled_at_exit(&block) - ENV['DISABLE_AT_EXIT'] = '1' + def with_disabled_at_exit + ENV["DISABLE_AT_EXIT"] = "1" yield - ENV.delete('DISABLE_AT_EXIT') + ENV.delete("DISABLE_AT_EXIT") end end diff --git a/spec/support/sha256_helper.rb b/spec/support/sha256_helper.rb index 97c6d1dd3e..14f2a2519f 100644 --- a/spec/support/sha256_helper.rb +++ b/spec/support/sha256_helper.rb @@ -1,8 +1,8 @@ -require'digest' +require"digest" module Sha256Helper def random_sha256 - seed = "--#{rand(10000)}--#{Time.now}--" + seed = "--#{rand(10_000)}--#{Time.now}--" Digest::SHA2.hexdigest(seed) end end diff --git a/spec/support/shutup_helper.rb b/spec/support/shutup_helper.rb index 1dbc6d239d..98dde01a65 100644 --- a/spec/support/shutup_helper.rb +++ b/spec/support/shutup_helper.rb @@ -1,13 +1,13 @@ module ShutupHelper def shutup - if ENV.has_key?('VERBOSE_TESTS') + if ENV.key?("VERBOSE_TESTS") yield else begin tmperr = $stderr.clone tmpout = $stdout.clone - $stderr.reopen '/dev/null', 'w' - $stdout.reopen '/dev/null', 'w' + $stderr.reopen "/dev/null", "w" + $stdout.reopen "/dev/null", "w" yield ensure $stderr.reopen tmperr diff --git a/test/cask/accessibility_test.rb b/test/cask/accessibility_test.rb index f20f355049..150bf53012 100644 --- a/test/cask/accessibility_test.rb +++ b/test/cask/accessibility_test.rb @@ -1,22 +1,22 @@ -require 'test_helper' +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 before do - cask = Hbc.load('with-accessibility-access') + cask = Hbc.load("with-accessibility-access") with_fake_command = { command: Hbc::FakeSystemCommand } @installer = Hbc::Installer.new(cask, with_fake_command) end describe "install" do it "can enable accessibility access" do - MacOS.stubs(:release => MacOS::Release.new('10.9')) + MacOS.stubs(release: MacOS::Release.new("10.9")) - @installer.stubs(:bundle_identifier => 'com.example.BasicCask') + @installer.stubs(bundle_identifier: "com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/bin/sqlite3', Hbc.tcc_db, %q{INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);}] + ["/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 @@ -24,10 +24,10 @@ describe "Accessibility Access" do end it "can enable accessibility access in OS X releases prior to Mavericks" do - MacOS.stubs(:release => MacOS::Release.new('10.8')) + MacOS.stubs(release: MacOS::Release.new("10.8")) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/bin/touch', Hbc.pre_mavericks_accessibility_dotfile] + ["/usr/bin/sudo", "-E", "--", "/usr/bin/touch", Hbc.pre_mavericks_accessibility_dotfile] ) shutup do @installer.enable_accessibility_access @@ -37,26 +37,24 @@ describe "Accessibility Access" do describe "uninstall" do it "can disable accessibility access" do - MacOS.stubs(:release => MacOS::Release.new('10.9')) + MacOS.stubs(release: MacOS::Release.new("10.9")) - @installer.stubs(:bundle_identifier => 'com.example.BasicCask') + @installer.stubs(bundle_identifier: "com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/bin/sqlite3', Hbc.tcc_db, %q{DELETE FROM access WHERE client='com.example.BasicCask';}] + ["/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 it "warns about disabling accessibility access on old OS X releases" do - MacOS.stubs(:release => MacOS::Release.new('10.8')) + MacOS.stubs(release: MacOS::Release.new("10.8")) - @installer.stubs(:bundle_identifier => 'com.example.BasicCask') + @installer.stubs(bundle_identifier: "com.example.BasicCask") - out, err = capture_io do - @installer.disable_accessibility_access - end - err.must_match('Warning: Accessibility access was enabled for with-accessibility-access, but it is not safe to disable') + capture_io { @installer.disable_accessibility_access }[1] + .must_match("Warning: Accessibility access was enabled for with-accessibility-access, but it is not safe to disable") end end end diff --git a/test/cask/artifact/alt_target_test.rb b/test/cask/artifact/alt_target_test.rb index 34328c1135..1d1dba254c 100644 --- a/test/cask/artifact/alt_target_test.rb +++ b/test/cask/artifact/alt_target_test.rb @@ -1,13 +1,13 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::App do let(:local_alt_caffeine) { - Hbc.load('with-alt-target').tap do |cask| + Hbc.load("with-alt-target").tap do |cask| TestHelper.install_without_artifacts(cask) end } - describe 'activate to alternate target' do + describe "activate to alternate target" do it "installs the given apps using the proper target directory" do cask = local_alt_caffeine @@ -15,31 +15,31 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('AnotherName.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('AnotherName.app')).must_equal false + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" + File.exist?(cask.staged_path.join("AnotherName.app")).must_equal false end it "works with an application in a subdir" do - subdir_cask = Hbc::Cask.new('subdir') do - url TestHelper.local_binary_url('caffeine.zip') - homepage 'http://example.com/local-caffeine' - version '1.2.3' - sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' - app 'subdir/Caffeine.app', :target => 'AnotherName.app' + subdir_cask = Hbc::Cask.new("subdir") do + url TestHelper.local_binary_url("caffeine.zip") + homepage "http://example.com/local-caffeine" + version "1.2.3" + sha256 "9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853" + app "subdir/Caffeine.app", target: "AnotherName.app" end begin TestHelper.install_without_artifacts(subdir_cask) - appsubdir = subdir_cask.staged_path.join('subdir').tap(&:mkpath) - FileUtils.mv(subdir_cask.staged_path.join('Caffeine.app'), appsubdir) + appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath) + FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir) shutup do Hbc::Artifact::App.new(subdir_cask).install_phase end - File.ftype(Hbc.appdir.join('AnotherName.app')).must_equal 'directory' - File.exist?(appsubdir.join('AnotherName.app')).must_equal false + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" + File.exist?(appsubdir.join("AnotherName.app")).must_equal false ensure if defined?(subdir_cask) shutup do @@ -52,32 +52,32 @@ describe Hbc::Artifact::App do it "only uses apps when they are specified" do cask = local_alt_caffeine - staged_app_path = cask.staged_path.join('Caffeine.app') - staged_app_copy = staged_app_path.sub('Caffeine.app', 'CaffeineAgain.app') + staged_app_path = cask.staged_path.join("Caffeine.app") + staged_app_copy = staged_app_path.sub("Caffeine.app", "CaffeineAgain.app") FileUtils.cp_r staged_app_path, staged_app_copy shutup do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('AnotherName.app')).must_equal 'directory' + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" File.exist?(staged_app_path).must_equal false - File.exist?(Hbc.appdir.join('AnotherNameAgain.app')).must_equal false - File.exist?(cask.staged_path.join('CaffeineAgain.app')).must_equal true + File.exist?(Hbc.appdir.join("AnotherNameAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true end it "avoids clobbering an existing app by moving over it" do cask = local_alt_caffeine - existing_app_path = Hbc.appdir.join('AnotherName.app') + existing_app_path = Hbc.appdir.join("AnotherName.app") existing_app_path.mkpath TestHelper.must_output(self, lambda { Hbc::Artifact::App.new(cask).install_phase }, "==> It seems there is already an App at '#{existing_app_path}'; not moving.") - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.identical?(source_path, existing_app_path).must_equal false end diff --git a/test/cask/artifact/app_test.rb b/test/cask/artifact/app_test.rb index 0f6d96b0b1..76308b1572 100644 --- a/test/cask/artifact/app_test.rb +++ b/test/cask/artifact/app_test.rb @@ -1,13 +1,13 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::App do let(:local_caffeine) { - Hbc.load('local-caffeine').tap do |cask| + Hbc.load("local-caffeine").tap do |cask| TestHelper.install_without_artifacts(cask) end } - describe 'install_phase' do + describe "install_phase" do it "installs the given apps using the proper target directory" do cask = local_caffeine @@ -15,31 +15,31 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false end it "works with an application in a subdir" do - subdir_cask = Hbc::Cask.new('subdir') do - url TestHelper.local_binary_url('caffeine.zip') - homepage 'http://example.com/local-caffeine' - version '1.2.3' - sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' - app 'subdir/Caffeine.app' + subdir_cask = Hbc::Cask.new("subdir") do + url TestHelper.local_binary_url("caffeine.zip") + homepage "http://example.com/local-caffeine" + version "1.2.3" + sha256 "9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853" + app "subdir/Caffeine.app" end begin TestHelper.install_without_artifacts(subdir_cask) - appsubdir = subdir_cask.staged_path.join('subdir').tap(&:mkpath) - FileUtils.mv(subdir_cask.staged_path.join('Caffeine.app'), appsubdir) + appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath) + FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir) shutup do Hbc::Artifact::App.new(subdir_cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(appsubdir.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(appsubdir.join("Caffeine.app")).must_equal false ensure if defined?(subdir_cask) shutup do @@ -52,24 +52,24 @@ describe Hbc::Artifact::App do it "only uses apps when they are specified" do cask = local_caffeine - staged_app_path = cask.staged_path.join('Caffeine.app') - staged_app_copy = staged_app_path.sub('Caffeine.app', 'CaffeineAgain.app') + staged_app_path = cask.staged_path.join("Caffeine.app") + staged_app_copy = staged_app_path.sub("Caffeine.app", "CaffeineAgain.app") FileUtils.cp_r staged_app_path, staged_app_copy shutup do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" File.exist?(staged_app_path).must_equal false - File.exist?(Hbc.appdir.join('CaffeineAgain.app')).must_equal false - File.exist?(cask.staged_path.join('CaffeineAgain.app')).must_equal true + File.exist?(Hbc.appdir.join("CaffeineAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true end describe "when the target already exists" do let(:target_path) { - target_path = Hbc.appdir.join('Caffeine.app') + target_path = Hbc.appdir.join("Caffeine.app") target_path.mkpath target_path } @@ -81,36 +81,36 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).install_phase }, "==> It seems there is already an App at '#{target_path}'; not moving.") - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.identical?(source_path, target_path).must_equal false - contents_path = target_path.join('Contents/Info.plist') + contents_path = target_path.join("Contents/Info.plist") File.exist?(contents_path).must_equal false end describe "given the force option" do let(:install_phase) { - lambda { |given_options = {}| + lambda do |given_options = {}| options = { force: true }.merge(given_options) Hbc::Artifact::App.new(local_caffeine, options).install_phase - } + end } let(:chmod_cmd) { - ['/bin/chmod', '-R', '--', 'u+rwx', target_path] + ["/bin/chmod", "-R", "--", "u+rwx", target_path] } let(:chmod_n_cmd) { - ['/bin/chmod', '-R', '-N', target_path] + ["/bin/chmod", "-R", "-N", target_path] } let(:chflags_cmd) { - ['/usr/bin/chflags', '-R', '--', '000', target_path] + ["/usr/bin/chflags", "-R", "--", "000", target_path] } before do - Hbc::Utils.stubs(current_user: 'fake_user') + Hbc::Utils.stubs(current_user: "fake_user") end describe "target is both writable and user-owned" do @@ -118,33 +118,34 @@ describe Hbc::Artifact::App do cask = local_caffeine expected = [ - "==> It seems there is already an App at '#{target_path}'; overwriting.", - "==> Removing App: '#{target_path}'", - "==> Moving App 'Caffeine.app' to '#{target_path}'" - ] + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] TestHelper.must_output(self, install_phase, - expected.join("\n")) + expected.join("\n")) - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.exist?(source_path).must_equal false - File.ftype(target_path).must_equal 'directory' + File.ftype(target_path).must_equal "directory" - contents_path = target_path.join('Contents/Info.plist') + contents_path = target_path.join("Contents/Info.plist") File.exist?(contents_path).must_equal true end end describe "target is user-owned but contains read-only files" do before do - system '/usr/bin/touch', '--', "#{ target_path }/foo" - system '/bin/chmod', '--', '0555', target_path + system "/usr/bin/touch", "--", "#{target_path}/foo" + system "/bin/chmod", "--", "0555", target_path end it "tries to make the target world-writable" do Hbc::FakeSystemCommand.expect_and_pass_through(chflags_cmd) Hbc::FakeSystemCommand.expect_and_pass_through(chmod_cmd) Hbc::FakeSystemCommand.expect_and_pass_through(chmod_n_cmd) + shutup do install_phase.call(command: Hbc::FakeSystemCommand) end @@ -154,24 +155,24 @@ describe Hbc::Artifact::App do cask = local_caffeine expected = [ - "==> It seems there is already an App at '#{target_path}'; overwriting.", - "==> Removing App: '#{target_path}'", - "==> Moving App 'Caffeine.app' to '#{target_path}'" - ] + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] TestHelper.must_output(self, install_phase, - expected.join("\n")) + expected.join("\n")) - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.exist?(source_path).must_equal false - File.ftype(target_path).must_equal 'directory' + File.ftype(target_path).must_equal "directory" - contents_path = target_path.join('Contents/Info.plist') + contents_path = target_path.join("Contents/Info.plist") File.exist?(contents_path).must_equal true end after do - system '/bin/chmod', '--', '0755', target_path + system "/bin/chmod", "--", "0755", target_path end end end @@ -179,12 +180,13 @@ describe Hbc::Artifact::App do describe "when the target is a broken symlink" do let(:target_path) { - Hbc.appdir.join('Caffeine.app') + Hbc.appdir.join("Caffeine.app") } let(:deleted_path) { local_caffeine.staged_path.join( - 'Deleted.app') + "Deleted.app" + ) } before do @@ -204,29 +206,30 @@ describe Hbc::Artifact::App do describe "given the force option" do let(:install_phase) { - lambda { + lambda do Hbc::Artifact::App.new( - local_caffeine, force: true).install_phase - } + local_caffeine, force: true + ).install_phase + end } it "overwrites the existing app" do cask = local_caffeine expected = [ - "==> It seems there is already an App at '#{target_path}'; overwriting.", - "==> Removing App: '#{target_path}'", - "==> Moving App 'Caffeine.app' to '#{target_path}'" - ] + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] TestHelper.must_output(self, install_phase, - expected.join("\n")) + expected.join("\n")) - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.exist?(source_path).must_equal false - File.ftype(target_path).must_equal 'directory' + File.ftype(target_path).must_equal "directory" - contents_path = target_path.join('Contents/Info.plist') + contents_path = target_path.join("Contents/Info.plist") File.exist?(contents_path).must_equal true end end @@ -234,7 +237,7 @@ describe Hbc::Artifact::App do it "gives a warning if the source doesn't exist" do cask = local_caffeine - staged_app_path = cask.staged_path.join('Caffeine.app') + staged_app_path = cask.staged_path.join("Caffeine.app") staged_app_path.rmtree installation = -> { Hbc::Artifact::App.new(cask).install_phase } @@ -254,7 +257,7 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).uninstall_phase end - app_path = Hbc.appdir.join('Caffeine.app') + app_path = Hbc.appdir.join("Caffeine.app") File.exist?(app_path).must_equal false end end @@ -265,16 +268,19 @@ describe Hbc::Artifact::App do description = Hbc::Artifact::App.new(cask).summary[:english_description] - description.must_equal 'Apps managed by brew-cask:' + description.must_equal "Apps managed by brew-cask:" end describe "app is correctly installed" do it "returns the path to the app" do cask = local_caffeine - shutup { Hbc::Artifact::App.new(cask).install_phase } + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end contents = Hbc::Artifact::App.new(cask).summary[:contents] - app_path = Hbc.appdir.join('Caffeine.app') + app_path = Hbc.appdir.join("Caffeine.app") contents.must_equal ["'#{app_path}'"] end @@ -285,10 +291,10 @@ describe Hbc::Artifact::App do cask = local_caffeine contents = Hbc::Artifact::App.new(cask).summary[:contents] - app_path = Hbc.appdir.join('Caffeine.app') + app_path = Hbc.appdir.join("Caffeine.app") contents.size.must_equal 1 - contents[0].must_match(/.*Missing App.*: '#{app_path}'/) + contents[0].must_match(%r{.*Missing App.*: '#{app_path}'}) end end end diff --git a/test/cask/artifact/generic_artifact_test.rb b/test/cask/artifact/generic_artifact_test.rb index ad4349447a..d4a1733bab 100644 --- a/test/cask/artifact/generic_artifact_test.rb +++ b/test/cask/artifact/generic_artifact_test.rb @@ -1,17 +1,17 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::Artifact do let(:cask) { - Hbc.load('with-generic-artifact').tap do |cask| + Hbc.load("with-generic-artifact").tap do |cask| TestHelper.install_without_artifacts(cask) end } let(:expected_path) { - Hbc.appdir.join('Caffeine.app') + Hbc.appdir.join("Caffeine.app") } it "fails to install with no target" do - no_target = Hbc.load('with-generic-artifact-no-target') + no_target = Hbc.load("with-generic-artifact-no-target") TestHelper.install_without_artifacts(no_target) lambda { @@ -26,8 +26,8 @@ describe Hbc::Artifact::Artifact do Hbc::Artifact::Artifact.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false end it "avoids clobbering an existing artifact" do @@ -37,7 +37,7 @@ describe Hbc::Artifact::Artifact do Hbc::Artifact::Artifact.new(cask).install_phase end - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") File.identical?(source_path, expected_path).must_equal false end diff --git a/test/cask/artifact/nested_container_test.rb b/test/cask/artifact/nested_container_test.rb index c872c6130d..b771ba3452 100644 --- a/test/cask/artifact/nested_container_test.rb +++ b/test/cask/artifact/nested_container_test.rb @@ -1,9 +1,9 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::NestedContainer do - describe 'install' do - it 'extracts the specified paths as containers' do - cask = Hbc.load('nested-app').tap do |c| + describe "install" do + it "extracts the specified paths as containers" do + cask = Hbc.load("nested-app").tap do |c| TestHelper.install_without_artifacts(c) end @@ -11,7 +11,7 @@ describe Hbc::Artifact::NestedContainer do Hbc::Artifact::NestedContainer.new(cask).install_phase end - cask.staged_path.join('MyNestedApp.app').must_be :directory? + cask.staged_path.join("MyNestedApp.app").must_be :directory? end end end diff --git a/test/cask/artifact/pkg_test.rb b/test/cask/artifact/pkg_test.rb index 7776444ffc..e87db7a7ab 100644 --- a/test/cask/artifact/pkg_test.rb +++ b/test/cask/artifact/pkg_test.rb @@ -1,19 +1,19 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::Pkg do - before { - @cask = Hbc.load('with-installable') + before do + @cask = Hbc.load("with-installable") shutup do TestHelper.install_without_artifacts(@cask) end - } + end - describe 'install_phase' do - it 'runs the system installer on the specified pkgs' do + describe "install_phase" do + it "runs the system installer on the specified pkgs" do pkg = Hbc::Artifact::Pkg.new(@cask, - command: Hbc::FakeSystemCommand) + command: Hbc::FakeSystemCommand) - Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/usr/sbin/installer', '-pkg', @cask.staged_path.join('MyFancyPkg','Fancy.pkg'), '-target', '/']) + Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"]) shutup do pkg.install_phase @@ -21,10 +21,10 @@ describe Hbc::Artifact::Pkg do end end - describe 'uninstall_phase' do - it 'does nothing, because the uninstall_phase method is a no-op' do + describe "uninstall_phase" do + it "does nothing, because the uninstall_phase method is a no-op" do pkg = Hbc::Artifact::Pkg.new(@cask, - command: Hbc::FakeSystemCommand) + command: Hbc::FakeSystemCommand) shutup do pkg.uninstall_phase end diff --git a/test/cask/artifact/postflight_block_test.rb b/test/cask/artifact/postflight_block_test.rb index 341fc2e3a1..47dcdd905b 100644 --- a/test/cask/artifact/postflight_block_test.rb +++ b/test/cask/artifact/postflight_block_test.rb @@ -1,12 +1,12 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::PostflightBlock do - describe 'install_phase' do - it 'calls the specified block after installing, passing a Cask mini-dsl' do + describe "install_phase" do + it "calls the specified block after installing, passing a Cask mini-dsl" do called = false yielded_arg = nil - cask = Hbc::Cask.new('with-postflight') do + cask = Hbc::Cask.new("with-postflight") do postflight do |c| called = true yielded_arg = c @@ -20,12 +20,12 @@ describe Hbc::Artifact::PostflightBlock do end end - describe 'uninstall_phase' do - it 'calls the specified block after uninstalling, passing a Cask mini-dsl' do + describe "uninstall_phase" do + it "calls the specified block after uninstalling, passing a Cask mini-dsl" do called = false yielded_arg = nil - cask = Hbc::Cask.new('with-uninstall-postflight') do + cask = Hbc::Cask.new("with-uninstall-postflight") do uninstall_postflight do |c| called = true yielded_arg = c diff --git a/test/cask/artifact/preflight_block_test.rb b/test/cask/artifact/preflight_block_test.rb index 9d1c89310f..440b1db3a4 100644 --- a/test/cask/artifact/preflight_block_test.rb +++ b/test/cask/artifact/preflight_block_test.rb @@ -1,12 +1,12 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::PreflightBlock do - describe 'install_phase' do - it 'calls the specified block before installing, passing a Cask mini-dsl' do + describe "install_phase" do + it "calls the specified block before installing, passing a Cask mini-dsl" do called = false yielded_arg = nil - cask = Hbc::Cask.new('with-preflight') do + cask = Hbc::Cask.new("with-preflight") do preflight do |c| called = true yielded_arg = c @@ -20,12 +20,12 @@ describe Hbc::Artifact::PreflightBlock do end end - describe 'uninstall_phase' do - it 'calls the specified block before uninstalling, passing a Cask mini-dsl' do + describe "uninstall_phase" do + it "calls the specified block before uninstalling, passing a Cask mini-dsl" do called = false yielded_arg = nil - cask = Hbc::Cask.new('with-uninstall-preflight') do + cask = Hbc::Cask.new("with-uninstall-preflight") do uninstall_preflight do |c| called = true yielded_arg = c diff --git a/test/cask/artifact/suite_test.rb b/test/cask/artifact/suite_test.rb index 40fe26acc6..5f72c45659 100644 --- a/test/cask/artifact/suite_test.rb +++ b/test/cask/artifact/suite_test.rb @@ -1,15 +1,15 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::Suite do let(:cask) { - Hbc.load('with-suite').tap do |cask| + Hbc.load("with-suite").tap do |cask| TestHelper.install_without_artifacts(cask) end } let(:expected_path) { - Hbc.appdir.join('caffeine_suite') + Hbc.appdir.join("caffeine_suite") } - let(:source_path) { cask.staged_path.join('caffeine_suite') } + let(:source_path) { cask.staged_path.join("caffeine_suite") } it "moves the suite to the proper directory" do shutup do @@ -26,7 +26,7 @@ describe Hbc::Artifact::Suite do Hbc::Artifact::Suite.new(cask).install_phase end - expected_path.join('Caffeine.app').must_be :exist? + expected_path.join("Caffeine.app").must_be :exist? end it "avoids clobbering an existing suite by moving over it" do diff --git a/test/cask/artifact/two_apps_correct_test.rb b/test/cask/artifact/two_apps_correct_test.rb index 7bd2ef0b06..3432597e05 100644 --- a/test/cask/artifact/two_apps_correct_test.rb +++ b/test/cask/artifact/two_apps_correct_test.rb @@ -1,19 +1,19 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::App do let(:local_two_apps_caffeine) { - Hbc.load('with-two-apps-correct').tap do |cask| + Hbc.load("with-two-apps-correct").tap do |cask| TestHelper.install_without_artifacts(cask) end } let(:local_two_apps_subdir) { - Hbc.load('with-two-apps-subdir').tap do |cask| + Hbc.load("with-two-apps-subdir").tap do |cask| TestHelper.install_without_artifacts(cask) end } - describe 'multiple apps' do + describe "multiple apps" do it "installs both apps using the proper target directory" do cask = local_two_apps_caffeine @@ -21,11 +21,11 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false - File.ftype(Hbc.appdir.join('Caffeine-2.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine-2.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine-2.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine-2.app")).must_equal false end it "works with an application in a subdir" do @@ -36,34 +36,34 @@ describe Hbc::Artifact::App do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false - File.ftype(Hbc.appdir.join('Caffeine-2.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine-2.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine-2.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine-2.app")).must_equal false end it "only uses apps when they are specified" do cask = local_two_apps_caffeine - app_path = cask.staged_path.join('Caffeine.app') - FileUtils.cp_r app_path, app_path.sub('Caffeine.app', 'CaffeineAgain.app') + app_path = cask.staged_path.join("Caffeine.app") + FileUtils.cp_r app_path, app_path.sub("Caffeine.app", "CaffeineAgain.app") shutup do Hbc::Artifact::App.new(cask).install_phase end - File.ftype(Hbc.appdir.join('Caffeine.app')).must_equal 'directory' - File.exist?(cask.staged_path.join('Caffeine.app')).must_equal false + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false - File.exist?(Hbc.appdir.join('CaffeineAgain.app')).must_equal false - File.exist?(cask.staged_path.join('CaffeineAgain.app')).must_equal true + File.exist?(Hbc.appdir.join("CaffeineAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true end it "avoids clobbering an existing app (app 1)" do cask = local_two_apps_caffeine - Hbc.appdir.join('Caffeine.app').mkpath + Hbc.appdir.join("Caffeine.app").mkpath TestHelper.must_output(self, lambda { Hbc::Artifact::App.new(cask).install_phase @@ -72,15 +72,15 @@ describe Hbc::Artifact::App do ==> It seems there is already an App at '#{Hbc.appdir.join('Caffeine.app')}'; not moving. MESSAGE - source_path = cask.staged_path.join('Caffeine.app') + source_path = cask.staged_path.join("Caffeine.app") - File.identical?(source_path, Hbc.appdir.join('Caffeine.app')).must_equal false + File.identical?(source_path, Hbc.appdir.join("Caffeine.app")).must_equal false end it "avoids clobbering an existing app (app 2)" do cask = local_two_apps_caffeine - Hbc.appdir.join('Caffeine-2.app').mkpath + Hbc.appdir.join("Caffeine-2.app").mkpath TestHelper.must_output(self, lambda { Hbc::Artifact::App.new(cask).install_phase @@ -89,9 +89,9 @@ describe Hbc::Artifact::App do ==> Moving App 'Caffeine.app' to '#{Hbc.appdir.join('Caffeine.app')}' MESSAGE - source_path = cask.staged_path.join('Caffeine-2.app') + source_path = cask.staged_path.join("Caffeine-2.app") - File.identical?(source_path, Hbc.appdir.join('Caffeine-2.app')).must_equal false + File.identical?(source_path, Hbc.appdir.join("Caffeine-2.app")).must_equal false end end end diff --git a/test/cask/artifact/two_apps_incorrect_test.rb b/test/cask/artifact/two_apps_incorrect_test.rb index 5e7210b8b3..a89a94fbab 100644 --- a/test/cask/artifact/two_apps_incorrect_test.rb +++ b/test/cask/artifact/two_apps_incorrect_test.rb @@ -1,12 +1,14 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::App do - it 'must raise' do - begin - Hbc.load('two-apps-incorrect') - rescue => e - end + it "must raise" do + exception_raised = begin + Hbc.load("two-apps-incorrect") + false + rescue + true + end # TODO: later give the user a nice exception for this case and check for it here - e.must_be_kind_of Exception + assert exception_raised end end diff --git a/test/cask/artifact/uninstall_test.rb b/test/cask/artifact/uninstall_test.rb index 2df6cc2dc8..4d6c5df1b5 100644 --- a/test/cask/artifact/uninstall_test.rb +++ b/test/cask/artifact/uninstall_test.rb @@ -1,45 +1,45 @@ -require 'test_helper' +require "test_helper" describe Hbc::Artifact::Uninstall do - let(:cask) { Hbc.load('with-installable') } + let(:cask) { Hbc.load("with-installable") } - let(:uninstall_artifact) do + let(:uninstall_artifact) { Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand) - end + } - before { + before do shutup do TestHelper.install_without_artifacts(cask) end - } + end - describe 'install_phase' do - it 'does nothing, because the install_phase method is a no-op' do + describe "install_phase" do + it "does nothing, because the install_phase method is a no-op" do shutup do uninstall_artifact.install_phase end end end - describe 'zap_phase' do - it 'does nothing, because the zap_phase method is a no-op' do + describe "zap_phase" do + it "does nothing, because the zap_phase method is a no-op" do shutup do uninstall_artifact.zap_phase end end end - describe 'uninstall_phase' do - subject { + describe "uninstall_phase" do + subject do shutup do uninstall_artifact.uninstall_phase end - } + end - describe 'when using launchctl' do - let(:cask) { Hbc.load('with-uninstall-launchctl') } + describe "when using launchctl" do + let(:cask) { Hbc.load("with-uninstall-launchctl") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } - let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service]} + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } let(:service_info) { <<-PLIST.undent @@ -56,15 +56,17 @@ describe Hbc::Artifact::Uninstall do PLIST } - describe 'when launchctl job is owned by user' do - it 'can uninstall' do + describe "when launchctl job is owned by user" do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, - service_info) + service_info + ) Hbc::FakeSystemCommand.stubs_command( sudo(launchctl_list_cmd), - unknown_response) + unknown_response + ) Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) @@ -72,15 +74,17 @@ describe Hbc::Artifact::Uninstall do end end - describe 'when launchctl job is owned by system' do - it 'can uninstall' do + describe "when launchctl job is owned by system" do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, - unknown_response) + unknown_response + ) Hbc::FakeSystemCommand.stubs_command( sudo(launchctl_list_cmd), - service_info) + service_info + ) Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) @@ -89,10 +93,10 @@ describe Hbc::Artifact::Uninstall do end end - describe 'when using pkgutil' do - let(:cask) { Hbc.load('with-uninstall-pkgutil') } - let(:main_pkg_id) { 'my.fancy.package.main' } - let(:agent_pkg_id) { 'my.fancy.package.agent' } + describe "when using pkgutil" do + let(:cask) { Hbc.load("with-uninstall-pkgutil") } + let(:main_pkg_id) { "my.fancy.package.main" } + let(:agent_pkg_id) { "my.fancy.package.agent" } let(:main_files) { %w[ fancy/bin/fancy.exe @@ -134,91 +138,102 @@ describe Hbc::Artifact::Uninstall do PLIST } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], - "#{main_pkg_id}\n#{agent_pkg_id}") + "#{main_pkg_id}\n#{agent_pkg_id}" + ) [ [main_pkg_id, main_files, main_dirs], - [agent_pkg_id, agent_files, agent_dirs] + [agent_pkg_id, agent_files, agent_dirs], ].each do |pkg_id, pkg_files, pkg_dirs| Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], - pkg_files.join("\n")) + pkg_files.join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], - pkg_dirs.join("\n")) + pkg_dirs.join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --files #{pkg_id}], - (pkg_files + pkg_dirs).join("\n")) + (pkg_files + pkg_dirs).join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], - pkg_info_plist) + pkg_info_plist + ) Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}")})) + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}") }) + ) end subject end end - describe 'when using kext' do - let(:cask) { Hbc.load('with-uninstall-kext') } - let(:kext_id) { 'my.fancy.package.kernelextension' } + describe "when using kext" do + let(:cask) { Hbc.load("with-uninstall-kext") } + let(:kext_id) { "my.fancy.package.kernelextension" } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), 'loaded') + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), "loaded" + ) Hbc::FakeSystemCommand.expects_command( - sudo(%W[/sbin/kextunload -b #{kext_id}])) + sudo(%W[/sbin/kextunload -b #{kext_id}]) + ) subject end end - describe 'when using quit' do - let(:cask) { Hbc.load('with-uninstall-quit') } - let(:bundle_id) { 'my.fancy.package.app' } + describe "when using quit" do + let(:cask) { Hbc.load("with-uninstall-quit") } + let(:bundle_id) { "my.fancy.package.app" } let(:count_processes_script) { 'tell application "System Events" to count processes ' + - %Q{whose bundle identifier is "#{bundle_id}"} + %Q{whose bundle identifier is "#{bundle_id}"} } let(:quit_application_script) { %Q{tell application id "#{bundle_id}" to quit} } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), '1') + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), "1" + ) Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{quit_application_script}])) + sudo(%W[/usr/bin/osascript -e #{quit_application_script}]) + ) subject end end - describe 'when using signal' do - let(:cask) { Hbc.load('with-uninstall-signal') } - let(:bundle_id) { 'my.fancy.package.app' } + describe "when using signal" do + let(:cask) { Hbc.load("with-uninstall-signal") } + let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } - let(:unix_pids) { [12345, 67890] } + let(:unix_pids) { [12_345, 67_890] } let(:get_unix_pids_script) { 'tell application "System Events" to get the unix id of every process ' + - %Q{whose bundle identifier is "#{bundle_id}"} + %Q{whose bundle identifier is "#{bundle_id}"} } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(', ')) + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(", ") + ) signals.each do |signal| Process.expects(:kill).with(signal, *unix_pids) @@ -228,82 +243,89 @@ describe Hbc::Artifact::Uninstall do end end - describe 'when using delete' do - let(:cask) { Hbc.load('with-uninstall-delete') } + describe "when using delete" do + let(:cask) { Hbc.load("with-uninstall-delete") } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new('/permissible/absolute/path'), - Pathname.new('~/permissible/path/with/tilde').expand_path)) + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) subject end end - describe 'when using trash' do - let(:cask) { Hbc.load('with-uninstall-trash') } + describe "when using trash" do + let(:cask) { Hbc.load("with-uninstall-trash") } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new('/permissible/absolute/path'), - Pathname.new('~/permissible/path/with/tilde').expand_path)) + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) subject end end - describe 'when using rmdir' do - let(:cask) { Hbc.load('with-uninstall-rmdir') } - let(:dir_pathname) { Pathname(TestHelper.local_binary_path('empty_directory')) } + describe "when using rmdir" do + let(:cask) { Hbc.load("with-uninstall-rmdir") } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path("empty_directory")) } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rm -f --], dir_pathname.join('.DS_Store'))) + sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")) + ) Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rmdir --], dir_pathname)) + sudo(%w[/bin/rmdir --], dir_pathname) + ) subject end end - describe 'when using script' do - let(:cask) { Hbc.load('with-uninstall-script') } - let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + describe "when using script" do + let(:cask) { Hbc.load("with-uninstall-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) Hbc::FakeSystemCommand.expects_command( - sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) subject end end - describe 'when using early_script' do - let(:cask) { Hbc.load('with-uninstall-early-script') } - let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + describe "when using early_script" do + let(:cask) { Hbc.load("with-uninstall-early-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) Hbc::FakeSystemCommand.expects_command( - sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) subject end end - describe 'when using login_item' do - let(:cask) { Hbc.load('with-uninstall-login-item') } + describe "when using login_item" do + let(:cask) { Hbc.load("with-uninstall-login-item") } - it 'can uninstall' do + it "can uninstall" do Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login ' \ - 'item whose name is "Fancy"']) + ["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"'] + ) subject end diff --git a/test/cask/artifact/zap_test.rb b/test/cask/artifact/zap_test.rb index 57fbba7fcd..8ffa1c5e30 100644 --- a/test/cask/artifact/zap_test.rb +++ b/test/cask/artifact/zap_test.rb @@ -1,46 +1,46 @@ -require 'test_helper' +require "test_helper" # TODO: test that zap removes an alternate version of the same Cask describe Hbc::Artifact::Zap do - let(:cask) { Hbc.load('with-installable') } + let(:cask) { Hbc.load("with-installable") } - let(:zap_artifact) do + let(:zap_artifact) { Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand) - end + } - before { + before do shutup do TestHelper.install_without_artifacts(cask) end - } + end - describe 'install_phase' do - it 'does nothing, because the install_phase method is a no-op' do + describe "install_phase" do + it "does nothing, because the install_phase method is a no-op" do shutup do zap_artifact.install_phase end end end - describe 'uninstall_phase' do - it 'does nothing, because the uninstall_phase method is a no-op' do + describe "uninstall_phase" do + it "does nothing, because the uninstall_phase method is a no-op" do shutup do zap_artifact.uninstall_phase end end end - describe 'zap_phase' do - subject { + describe "zap_phase" do + subject do shutup do zap_artifact.zap_phase end - } + end - describe 'when using launchctl' do - let(:cask) { Hbc.load('with-zap-launchctl') } + describe "when using launchctl" do + let(:cask) { Hbc.load("with-zap-launchctl") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } - let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service]} + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } let(:service_info) { <<-PLIST.undent @@ -57,15 +57,17 @@ describe Hbc::Artifact::Zap do PLIST } - describe 'when launchctl job is owned by user' do - it 'can zap' do + describe "when launchctl job is owned by user" do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, - service_info) + service_info + ) Hbc::FakeSystemCommand.stubs_command( sudo(launchctl_list_cmd), - unknown_response) + unknown_response + ) Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) @@ -73,15 +75,17 @@ describe Hbc::Artifact::Zap do end end - describe 'when launchctl job is owned by system' do - it 'can zap' do + describe "when launchctl job is owned by system" do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( launchctl_list_cmd, - unknown_response) + unknown_response + ) Hbc::FakeSystemCommand.stubs_command( sudo(launchctl_list_cmd), - service_info) + service_info + ) Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) @@ -90,10 +94,10 @@ describe Hbc::Artifact::Zap do end end - describe 'when using pkgutil' do - let(:cask) { Hbc.load('with-zap-pkgutil') } - let(:main_pkg_id) { 'my.fancy.package.main' } - let(:agent_pkg_id) { 'my.fancy.package.agent' } + describe "when using pkgutil" do + let(:cask) { Hbc.load("with-zap-pkgutil") } + let(:main_pkg_id) { "my.fancy.package.main" } + let(:agent_pkg_id) { "my.fancy.package.agent" } let(:main_files) { %w[ fancy/bin/fancy.exe @@ -135,91 +139,102 @@ describe Hbc::Artifact::Zap do PLIST } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], - "#{main_pkg_id}\n#{agent_pkg_id}") + "#{main_pkg_id}\n#{agent_pkg_id}" + ) [ [main_pkg_id, main_files, main_dirs], - [agent_pkg_id, agent_files, agent_dirs] + [agent_pkg_id, agent_files, agent_dirs], ].each do |pkg_id, pkg_files, pkg_dirs| Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], - pkg_files.join("\n")) + pkg_files.join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], - pkg_dirs.join("\n")) + pkg_dirs.join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --files #{pkg_id}], - (pkg_files + pkg_dirs).join("\n")) + (pkg_files + pkg_dirs).join("\n") + ) Hbc::FakeSystemCommand.stubs_command( %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], - pkg_info_plist) + pkg_info_plist + ) Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}")})) + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}") }) + ) end subject end end - describe 'when using kext' do - let(:cask) { Hbc.load('with-zap-kext') } - let(:kext_id) { 'my.fancy.package.kernelextension' } + describe "when using kext" do + let(:cask) { Hbc.load("with-zap-kext") } + let(:kext_id) { "my.fancy.package.kernelextension" } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), 'loaded') + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), "loaded" + ) Hbc::FakeSystemCommand.expects_command( - sudo(%W[/sbin/kextunload -b #{kext_id}])) + sudo(%W[/sbin/kextunload -b #{kext_id}]) + ) subject end end - describe 'when using quit' do - let(:cask) { Hbc.load('with-zap-quit') } - let(:bundle_id) { 'my.fancy.package.app' } + describe "when using quit" do + let(:cask) { Hbc.load("with-zap-quit") } + let(:bundle_id) { "my.fancy.package.app" } let(:count_processes_script) { 'tell application "System Events" to count processes ' + - %Q{whose bundle identifier is "#{bundle_id}"} + %Q{whose bundle identifier is "#{bundle_id}"} } let(:quit_application_script) { %Q{tell application id "#{bundle_id}" to quit} } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), '1') + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), "1" + ) Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{quit_application_script}])) + sudo(%W[/usr/bin/osascript -e #{quit_application_script}]) + ) subject end end - describe 'when using signal' do - let(:cask) { Hbc.load('with-zap-signal') } - let(:bundle_id) { 'my.fancy.package.app' } + describe "when using signal" do + let(:cask) { Hbc.load("with-zap-signal") } + let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } - let(:unix_pids) { [12345, 67890] } + let(:unix_pids) { [12_345, 67_890] } let(:get_unix_pids_script) { 'tell application "System Events" to get the unix id of every process ' + - %Q{whose bundle identifier is "#{bundle_id}"} + %Q{whose bundle identifier is "#{bundle_id}"} } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.stubs_command( - sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(', ')) + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(", ") + ) signals.each do |signal| Process.expects(:kill).with(signal, *unix_pids) @@ -229,82 +244,89 @@ describe Hbc::Artifact::Zap do end end - describe 'when using delete' do - let(:cask) { Hbc.load('with-zap-delete') } + describe "when using delete" do + let(:cask) { Hbc.load("with-zap-delete") } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new('/permissible/absolute/path'), - Pathname.new('~/permissible/path/with/tilde').expand_path)) + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) subject end end - describe 'when using trash' do - let(:cask) { Hbc.load('with-zap-trash') } + describe "when using trash" do + let(:cask) { Hbc.load("with-zap-trash") } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command( sudo(%w[/bin/rm -rf --], - Pathname.new('/permissible/absolute/path'), - Pathname.new('~/permissible/path/with/tilde').expand_path)) + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) subject end end - describe 'when using rmdir' do - let(:cask) { Hbc.load('with-zap-rmdir') } - let(:dir_pathname) { Pathname(TestHelper.local_binary_path('empty_directory')) } + describe "when using rmdir" do + let(:cask) { Hbc.load("with-zap-rmdir") } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path("empty_directory")) } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rm -f --], dir_pathname.join('.DS_Store'))) + sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")) + ) Hbc::FakeSystemCommand.expects_command( - sudo(%w[/bin/rmdir --], dir_pathname)) + sudo(%w[/bin/rmdir --], dir_pathname) + ) subject end end - describe 'when using script' do - let(:cask) { Hbc.load('with-zap-script') } - let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + describe "when using script" do + let(:cask) { Hbc.load("with-zap-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) Hbc::FakeSystemCommand.expects_command( - sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) subject end end - describe 'when using early_script' do - let(:cask) { Hbc.load('with-zap-early-script') } - let(:script_pathname) { cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool') } + describe "when using early_script" do + let(:cask) { Hbc.load("with-zap-early-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) Hbc::FakeSystemCommand.expects_command( - sudo(cask.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please')) + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) subject end end - describe 'when using login_item' do - let(:cask) { Hbc.load('with-zap-login-item') } + describe "when using login_item" do + let(:cask) { Hbc.load("with-zap-login-item") } - it 'can zap' do + it "can zap" do Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/osascript', '-e', 'tell application "System Events" to delete every login ' \ - 'item whose name is "Fancy"']) + ["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"'] + ) subject end diff --git a/test/cask/cli/audit_test.rb b/test/cask/cli/audit_test.rb index 15b9432238..ccc0be4ad8 100644 --- a/test/cask/cli/audit_test.rb +++ b/test/cask/cli/audit_test.rb @@ -1,41 +1,41 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Audit do - let(:auditor) { mock() } - let(:cask) { mock() } + let(:auditor) { mock } + let(:cask) { mock } - describe 'selection of Casks to audit' do - it 'audits all Casks if no tokens are given' do - Hbc.stubs(:all => [cask, cask]) + describe "selection of Casks to audit" do + it "audits all Casks if no tokens are given" do + Hbc.stubs(all: [cask, cask]) auditor.expects(:audit).times(2) run_audit([], auditor) end - it 'audits specified Casks if tokens are given' do - cask_token = 'nice-app' + it "audits specified Casks if tokens are given" do + cask_token = "nice-app" Hbc.expects(:load).with(cask_token).returns(cask) - auditor.expects(:audit).with(cask, :audit_download => false) + auditor.expects(:audit).with(cask, audit_download: false) run_audit([cask_token], auditor) end end - describe 'rules for downloading a Cask' do - it 'does not download the Cask per default' do - Hbc.stubs(:load => cask) + describe "rules for downloading a Cask" do + it "does not download the Cask per default" do + Hbc.stubs(load: cask) - auditor.expects(:audit).with(cask, :audit_download => false) + auditor.expects(:audit).with(cask, audit_download: false) - run_audit(['casktoken'], auditor) + run_audit(["casktoken"], auditor) end - it 'download a Cask if --download flag is set' do - Hbc.stubs(:load => cask) + it "download a Cask if --download flag is set" do + Hbc.stubs(load: cask) - auditor.expects(:audit).with(cask, :audit_download => true) + auditor.expects(:audit).with(cask, audit_download: true) - run_audit(['casktoken', '--download'], auditor) + run_audit(["casktoken", "--download"], auditor) end end diff --git a/test/cask/cli/cat_test.rb b/test/cask/cli/cat_test.rb index 4bf12b6818..f51fe4be09 100644 --- a/test/cask/cli/cat_test.rb +++ b/test/cask/cli/cat_test.rb @@ -1,7 +1,7 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Cat do - describe 'given a basic Cask' do + describe "given a basic Cask" do before do @expected_output = <<-CLIOUTPUT.undent test_cask 'basic-cask' do @@ -16,43 +16,43 @@ describe Hbc::CLI::Cat do CLIOUTPUT end - it 'displays the Cask file content about the specified Cask' do + it "displays the Cask file content about the specified Cask" do lambda { - Hbc::CLI::Cat.run('basic-cask') + Hbc::CLI::Cat.run("basic-cask") }.must_output(@expected_output) end - it 'throws away additional Cask arguments and uses the first' do + it "throws away additional Cask arguments and uses the first" do lambda { - Hbc::CLI::Cat.run('basic-cask', 'local-caffeine') + Hbc::CLI::Cat.run("basic-cask", "local-caffeine") }.must_output(@expected_output) end - it 'throws away stray options' do + it "throws away stray options" do lambda { - Hbc::CLI::Cat.run('--notavalidoption', 'basic-cask') + Hbc::CLI::Cat.run("--notavalidoption", "basic-cask") }.must_output(@expected_output) end end - it 'raises an exception when the Cask does not exist' do + it "raises an exception when the Cask does not exist" do lambda { - Hbc::CLI::Cat.run('notacask') + Hbc::CLI::Cat.run("notacask") }.must_raise Hbc::CaskUnavailableError end - describe 'when no Cask is specified' do - it 'raises an exception' do + describe "when no Cask is specified" do + it "raises an exception" do lambda { - Hbc::CLI::Cat.run() + Hbc::CLI::Cat.run }.must_raise Hbc::CaskUnspecifiedError end end - describe 'when no Cask is specified, but an invalid option' do - it 'raises an exception' do + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do lambda { - Hbc::CLI::Cat.run('--notavalidoption') + Hbc::CLI::Cat.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/create_test.rb b/test/cask/cli/create_test.rb index 3366c9857a..85d888cfae 100644 --- a/test/cask/cli/create_test.rb +++ b/test/cask/cli/create_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" # monkeypatch for testing class Hbc::CLI::Create @@ -16,25 +16,27 @@ class Hbc::CLI::Create end describe Hbc::CLI::Create do - before { Hbc::CLI::Create.reset! } + before do + Hbc::CLI::Create.reset! + end - after { - %w[ new-cask additional-cask another-cask yet-another-cask feine ].each do |cask| + after do + %w[new-cask additional-cask another-cask yet-another-cask feine].each do |cask| path = Hbc.path(cask) path.delete if path.exist? end - } - - it 'opens the editor for the specified Cask' do - Hbc::CLI::Create.run('new-cask') - Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path('new-cask')] - ] end - it 'drops a template down for the specified Cask' do - Hbc::CLI::Create.run('new-cask') - template = File.read(Hbc.path('new-cask')) + it "opens the editor for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + Hbc::CLI::Create.editor_commands.must_equal [ + [Hbc.path("new-cask")], + ] + end + + it "drops a template down for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + template = File.read(Hbc.path("new-cask")) template.must_equal <<-TEMPLATE.undent cask 'new-cask' do version '' @@ -50,37 +52,37 @@ describe Hbc::CLI::Create do TEMPLATE end - it 'throws away additional Cask arguments and uses the first' do - Hbc::CLI::Create.run('additional-cask', 'another-cask') + it "throws away additional Cask arguments and uses the first" do + Hbc::CLI::Create.run("additional-cask", "another-cask") Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path('additional-cask')] - ] + [Hbc.path("additional-cask")], + ] end - it 'throws away stray options' do - Hbc::CLI::Create.run('--notavalidoption', 'yet-another-cask') + it "throws away stray options" do + Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path('yet-another-cask')] - ] + [Hbc.path("yet-another-cask")], + ] end - it 'raises an exception when the Cask already exists' do + it "raises an exception when the Cask already exists" do lambda { - Hbc::CLI::Create.run('caffeine') + Hbc::CLI::Create.run("caffeine") }.must_raise Hbc::CaskAlreadyCreatedError end - it 'allows creating Casks that are substrings of existing Casks' do - Hbc::CLI::Create.run('feine') + it "allows creating Casks that are substrings of existing Casks" do + Hbc::CLI::Create.run("feine") Hbc::CLI::Create.editor_commands.must_equal [ - [Hbc.path('feine')] - ] + [Hbc.path("feine")], + ] end describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Create.run() + Hbc::CLI::Create.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -88,7 +90,7 @@ describe Hbc::CLI::Create do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Create.run('--notavalidoption') + Hbc::CLI::Create.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/edit_test.rb b/test/cask/cli/edit_test.rb index 308bb1460f..ebec5f414d 100644 --- a/test/cask/cli/edit_test.rb +++ b/test/cask/cli/edit_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" # monkeypatch for testing class Hbc::CLI::Edit @@ -20,30 +20,30 @@ describe Hbc::CLI::Edit do Hbc::CLI::Edit.reset! end - it 'opens the editor for the specified Cask' do - Hbc::CLI::Edit.run('alfred') + it "opens the editor for the specified Cask" do + Hbc::CLI::Edit.run("alfred") Hbc::CLI::Edit.editor_commands.must_equal [ - [Hbc.path('alfred')] - ] + [Hbc.path("alfred")], + ] end - it 'throws away additional arguments and uses the first' do - Hbc::CLI::Edit.run('adium', 'alfred') + it "throws away additional arguments and uses the first" do + Hbc::CLI::Edit.run("adium", "alfred") Hbc::CLI::Edit.editor_commands.must_equal [ - [Hbc.path('adium')] - ] + [Hbc.path("adium")], + ] end - it 'raises an exception when the Cask doesnt exist' do + it "raises an exception when the Cask doesnt exist" do lambda { - Hbc::CLI::Edit.run('notacask') + Hbc::CLI::Edit.run("notacask") }.must_raise Hbc::CaskUnavailableError end describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Edit.run() + Hbc::CLI::Edit.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -51,7 +51,7 @@ describe Hbc::CLI::Edit do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Edit.run('--notavalidoption') + Hbc::CLI::Edit.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/fetch_test.rb b/test/cask/cli/fetch_test.rb index e813401c27..70c25646d6 100644 --- a/test/cask/cli/fetch_test.rb +++ b/test/cask/cli/fetch_test.rb @@ -1,17 +1,17 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Fetch do - let(:local_transmission) do - Hbc.load('local-transmission') - end + let(:local_transmission) { + Hbc.load("local-transmission") + } - let(:local_caffeine) do - Hbc.load('local-caffeine') - end + let(:local_caffeine) { + Hbc.load("local-caffeine") + } it "allows download the installer of a Cask" do shutup do - Hbc::CLI::Fetch.run('local-transmission', 'local-caffeine') + Hbc::CLI::Fetch.run("local-transmission", "local-caffeine") end Hbc::CurlDownloadStrategy.new(local_transmission).cached_location.must_be :exist? Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location.must_be :exist? @@ -26,12 +26,11 @@ describe Hbc::CLI::Fetch do old_ctime = File.stat(download_stategy.cached_location).ctime shutup do - Hbc::CLI::Fetch.run('local-transmission') + Hbc::CLI::Fetch.run("local-transmission") end new_ctime = File.stat(download_stategy.cached_location).ctime old_ctime.to_i.must_equal new_ctime.to_i - end it "allows double fetch with --force" do @@ -44,7 +43,7 @@ describe Hbc::CLI::Fetch do sleep(1) shutup do - Hbc::CLI::Fetch.run('local-transmission','--force') + Hbc::CLI::Fetch.run("local-transmission", "--force") end download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) new_ctime = File.stat(download_stategy.cached_location).ctime @@ -56,7 +55,7 @@ describe Hbc::CLI::Fetch do it "properly handles Casks that are not present" do lambda { shutup do - Hbc::CLI::Fetch.run('notacask') + Hbc::CLI::Fetch.run("notacask") end }.must_raise Hbc::CaskUnavailableError end @@ -64,7 +63,7 @@ describe Hbc::CLI::Fetch do describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Fetch.run() + Hbc::CLI::Fetch.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -72,7 +71,7 @@ describe Hbc::CLI::Fetch do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Fetch.run('--notavalidoption') + Hbc::CLI::Fetch.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/home_test.rb b/test/cask/cli/home_test.rb index 131bddf422..28fd2a391c 100644 --- a/test/cask/cli/home_test.rb +++ b/test/cask/cli/home_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" # monkeypatch for testing class Hbc::CLI::Home @@ -20,25 +20,25 @@ describe Hbc::CLI::Home do Hbc::CLI::Home.reset! end - it 'opens the homepage for the specified Cask' do - Hbc::CLI::Home.run('alfred') + it "opens the homepage for the specified Cask" do + Hbc::CLI::Home.run("alfred") Hbc::CLI::Home.system_commands.must_equal [ - ['/usr/bin/open', '--', 'https://www.alfredapp.com/'] - ] + ["/usr/bin/open", "--", "https://www.alfredapp.com/"], + ] end - it 'works for multiple Casks' do - Hbc::CLI::Home.run('alfred', 'adium') + it "works for multiple Casks" do + Hbc::CLI::Home.run("alfred", "adium") Hbc::CLI::Home.system_commands.must_equal [ - ['/usr/bin/open', '--', 'https://www.alfredapp.com/'], - ['/usr/bin/open', '--', 'https://www.adium.im/'] - ] + ["/usr/bin/open", "--", "https://www.alfredapp.com/"], + ["/usr/bin/open", "--", "https://www.adium.im/"], + ] end it "opens the project page when no Cask is specified" do Hbc::CLI::Home.run Hbc::CLI::Home.system_commands.must_equal [ - ['/usr/bin/open', '--', 'http://caskroom.io/'], - ] + ["/usr/bin/open", "--", "http://caskroom.io/"], + ] end end diff --git a/test/cask/cli/info_test.rb b/test/cask/cli/info_test.rb index e567f1db07..3e21910712 100644 --- a/test/cask/cli/info_test.rb +++ b/test/cask/cli/info_test.rb @@ -1,9 +1,9 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Info do - it 'displays some nice info about the specified Cask' do + it "displays some nice info about the specified Cask" do lambda { - Hbc::CLI::Info.run('local-caffeine') + Hbc::CLI::Info.run("local-caffeine") }.must_output <<-CLIOUTPUT.undent local-caffeine: 1.2.3 local-caffeine @@ -15,7 +15,7 @@ describe Hbc::CLI::Info do CLIOUTPUT end - describe 'given multiple Casks' do + describe "given multiple Casks" do before do @expected_output = <<-CLIOUTPUT.undent local-caffeine: 1.2.3 @@ -35,22 +35,22 @@ describe Hbc::CLI::Info do CLIOUTPUT end - it 'displays the info' do + it "displays the info" do lambda { - Hbc::CLI::Info.run('local-caffeine', 'local-transmission') + Hbc::CLI::Info.run("local-caffeine", "local-transmission") }.must_output(@expected_output) end - it 'throws away stray options' do + it "throws away stray options" do lambda { - Hbc::CLI::Info.run('--notavalidoption', 'local-caffeine', 'local-transmission') + Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission") }.must_output(@expected_output) end end - it 'should print caveats if the Cask provided one' do + it "should print caveats if the Cask provided one" do lambda { - Hbc::CLI::Info.run('with-caveats') + Hbc::CLI::Info.run("with-caveats") }.must_output <<-CLIOUTPUT.undent with-caveats: 1.2.3 with-caveats @@ -75,7 +75,7 @@ describe Hbc::CLI::Info do it 'should not print "Caveats" section divider if the caveats block has no output' do lambda { - Hbc::CLI::Info.run('with-conditional-caveats') + Hbc::CLI::Info.run("with-conditional-caveats") }.must_output <<-CLIOUTPUT.undent with-conditional-caveats: 1.2.3 with-conditional-caveats @@ -90,7 +90,7 @@ describe Hbc::CLI::Info do describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Info.run() + Hbc::CLI::Info.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -98,7 +98,7 @@ describe Hbc::CLI::Info do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Info.run('--notavalidoption') + Hbc::CLI::Info.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/install_test.rb b/test/cask/cli/install_test.rb index bc94bcd55f..2d09846b7f 100644 --- a/test/cask/cli/install_test.rb +++ b/test/cask/cli/install_test.rb @@ -1,79 +1,82 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Install do it "allows staging and activation of multiple Casks at once" do shutup do - Hbc::CLI::Install.run('local-transmission', 'local-caffeine') + Hbc::CLI::Install.run("local-transmission", "local-caffeine") end - Hbc.load('local-transmission').must_be :installed? - Hbc.appdir.join('Transmission.app').must_be :directory? - Hbc.load('local-caffeine').must_be :installed? - Hbc.appdir.join('Caffeine.app').must_be :directory? + Hbc.load("local-transmission").must_be :installed? + Hbc.appdir.join("Transmission.app").must_be :directory? + Hbc.load("local-caffeine").must_be :installed? + Hbc.appdir.join("Caffeine.app").must_be :directory? end it "skips double install (without nuking existing installation)" do shutup do - Hbc::CLI::Install.run('local-transmission') + Hbc::CLI::Install.run("local-transmission") end shutup do - Hbc::CLI::Install.run('local-transmission') + Hbc::CLI::Install.run("local-transmission") end - Hbc.load('local-transmission').must_be :installed? + Hbc.load("local-transmission").must_be :installed? end it "prints a warning message on double install" do shutup do - Hbc::CLI::Install.run('local-transmission') + Hbc::CLI::Install.run("local-transmission") end TestHelper.must_output(self, lambda { - Hbc::CLI::Install.run('local-transmission', '') + Hbc::CLI::Install.run("local-transmission", "") }, %r{Warning: A Cask for local-transmission is already installed. Add the "--force" option to force re-install.}) end it "allows double install with --force" do shutup do - Hbc::CLI::Install.run('local-transmission') + Hbc::CLI::Install.run("local-transmission") end TestHelper.must_output(self, lambda { - Hbc::CLI::Install.run('local-transmission', '--force') + Hbc::CLI::Install.run("local-transmission", "--force") }, %r{==> Success! local-transmission was successfully installed!}) end it "skips dependencies with --skip-cask-deps" do shutup do - Hbc::CLI::Install.run('with-depends-on-cask-multiple', '--skip-cask-deps') + Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") end - Hbc.load('with-depends-on-cask-multiple').must_be :installed? - Hbc.load('local-caffeine').wont_be :installed? - Hbc.load('local-transmission').wont_be :installed? + Hbc.load("with-depends-on-cask-multiple").must_be :installed? + Hbc.load("local-caffeine").wont_be :installed? + Hbc.load("local-transmission").wont_be :installed? end - it "properly handles Casks that are not present" do lambda { shutup do - Hbc::CLI::Install.run('notacask') + Hbc::CLI::Install.run("notacask") end }.must_raise Hbc::CaskError end it "returns a suggestion for a misspelled Cask" do - out, err = capture_io do + _, err = capture_io do begin - Hbc::CLI::Install.run('googlechrome') - rescue Hbc::CaskError; end + Hbc::CLI::Install.run("googlechrome") + rescue Hbc::CaskError + return + end end err.must_match %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome} end it "returns multiple suggestions for a Cask fragment" do - out, err = capture_io do + _, err = capture_io do begin - Hbc::CLI::Install.run('google') - rescue Hbc::CaskError; end + Hbc::CLI::Install.run("google") + rescue Hbc::CaskError + return + end end err.must_match %r{No available Cask for google\. Did you mean one of:\ngoogle} end @@ -92,15 +95,15 @@ describe Hbc::CLI::Install do end describe "with --force" do - with_options.call(['--force']) + with_options.call(["--force"]) end describe "with --skip-cask-deps" do - with_options.call(['--skip-cask-deps']) + with_options.call(["--skip-cask-deps"]) end describe "with an invalid option" do - with_options.call(['--notavalidoption']) + with_options.call(["--notavalidoption"]) end end end diff --git a/test/cask/cli/list_test.rb b/test/cask/cli/list_test.rb index 22957e835a..1a866e07cf 100644 --- a/test/cask/cli/list_test.rb +++ b/test/cask/cli/list_test.rb @@ -1,63 +1,71 @@ -require 'test_helper' +require "test_helper" 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.each { |c| TestHelper.install_without_artifacts(c) } + casks.each do |c| + TestHelper.install_without_artifacts(c) + end lambda { Hbc::CLI::List.run - }.must_output <<-OUTPUT.gsub(/^ */, '') + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") local-caffeine local-transmission OUTPUT end - it 'lists the installed Casks and all their installed versions' do + it "lists the installed Casks and all their installed versions" do casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } - casks.each { |c| TestHelper.install_with_caskfile(c) } + casks.each do |c| + TestHelper.install_with_caskfile(c) + end lambda { - Hbc::CLI::List.run('--versions') - }.must_output <<-OUTPUT.gsub(/^ */, '') + Hbc::CLI::List.run("--versions") + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") local-caffeine 1.2.3 local-transmission 2.61 OUTPUT end - describe 'when Casks have been renamed' do + describe "when Casks have been renamed" do before do - @renamed_path = Hbc.caskroom.join('ive-been-renamed','latest','Renamed.app').tap(&:mkpath) - @renamed_path.join('Info.plist').open('w') { |f| f.puts "Oh plist" } + @renamed_path = Hbc.caskroom.join("ive-been-renamed", "latest", "Renamed.app").tap(&:mkpath) + @renamed_path.join("Info.plist").open("w") { |f| f.puts "Oh plist" } end after do @renamed_path.rmtree if @renamed_path.exist? 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 { Hbc::CLI::List.run - }.must_output <<-OUTPUT.gsub(/^ */, '') + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") ive-been-renamed (!) OUTPUT end end - it 'given a set of installed Casks, lists the installed files for those Casks' do + it "given a set of installed Casks, lists the installed files for those Casks" do casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } - casks.each { |c| TestHelper.install_without_artifacts(c) } + casks.each do |c| + TestHelper.install_without_artifacts(c) + end caffeine, transmission = casks - shutup { Hbc::Artifact::App.new(transmission).install_phase } + shutup do + Hbc::Artifact::App.new(transmission).install_phase + end lambda { - Hbc::CLI::List.run('local-transmission', 'local-caffeine') - }.must_output <<-OUTPUT.gsub(/^ */, '') + Hbc::CLI::List.run("local-transmission", "local-caffeine") + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") ==> Apps managed by brew-cask: '#{Hbc.appdir.join('Transmission.app')}' ==> Staged content: diff --git a/test/cask/cli/options_test.rb b/test/cask/cli/options_test.rb index 7e48898093..32bd2e2d71 100644 --- a/test/cask/cli/options_test.rb +++ b/test/cask/cli/options_test.rb @@ -1,94 +1,94 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI do it "supports setting the appdir" do Hbc::CLI.process_options %w[help --appdir=/some/path/foo] - Hbc.appdir.must_equal Pathname('/some/path/foo') + Hbc.appdir.must_equal Pathname("/some/path/foo") end it "supports setting the appdir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--appdir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.appdir.must_equal Pathname('/some/path/bar') + Hbc.appdir.must_equal Pathname("/some/path/bar") end it "supports setting the prefpanedir" do Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo] - Hbc.prefpanedir.must_equal Pathname('/some/path/foo') + Hbc.prefpanedir.must_equal Pathname("/some/path/foo") end it "supports setting the prefpanedir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--prefpanedir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.prefpanedir.must_equal Pathname('/some/path/bar') + Hbc.prefpanedir.must_equal Pathname("/some/path/bar") end it "supports setting the qlplugindir" do Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo] - Hbc.qlplugindir.must_equal Pathname('/some/path/foo') + Hbc.qlplugindir.must_equal Pathname("/some/path/foo") end it "supports setting the qlplugindir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--qlplugindir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.qlplugindir.must_equal Pathname('/some/path/bar') + Hbc.qlplugindir.must_equal Pathname("/some/path/bar") end it "supports setting the colorpickerdir" do Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo] - Hbc.colorpickerdir.must_equal Pathname('/some/path/foo') + Hbc.colorpickerdir.must_equal Pathname("/some/path/foo") end it "supports setting the colorpickerdir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--colorpickerdir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.colorpickerdir.must_equal Pathname('/some/path/bar') + Hbc.colorpickerdir.must_equal Pathname("/some/path/bar") end it "supports setting the fontdir" do Hbc::CLI.process_options %w[help --fontdir=/some/path/foo] - Hbc.fontdir.must_equal Pathname('/some/path/foo') + Hbc.fontdir.must_equal Pathname("/some/path/foo") end it "supports setting the fontdir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--fontdir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.fontdir.must_equal Pathname('/some/path/bar') + Hbc.fontdir.must_equal Pathname("/some/path/bar") end it "supports setting the servicedir" do Hbc::CLI.process_options %w[help --servicedir=/some/path/foo] - Hbc.servicedir.must_equal Pathname('/some/path/foo') + Hbc.servicedir.must_equal Pathname("/some/path/foo") end it "supports setting the servicedir from ENV" do - ENV['HOMEBREW_CASK_OPTS'] = "--servicedir=/some/path/bar" + ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" Hbc::CLI.process_options %w[help] - Hbc.servicedir.must_equal Pathname('/some/path/bar') + Hbc.servicedir.must_equal Pathname("/some/path/bar") end it "allows additional options to be passed through" do rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux] - Hbc.appdir.must_equal Pathname('/some/path/qux') + Hbc.appdir.must_equal Pathname("/some/path/qux") rest.must_equal %w[edit foo --create] end @@ -125,6 +125,6 @@ describe Hbc::CLI do end after do - ENV['HOMEBREW_CASK_OPTS'] = nil + ENV["HOMEBREW_CASK_OPTS"] = nil end end diff --git a/test/cask/cli/search_test.rb b/test/cask/cli/search_test.rb index 210e5aeb58..a0365862ed 100644 --- a/test/cask/cli/search_test.rb +++ b/test/cask/cli/search_test.rb @@ -1,10 +1,10 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Search do it "lists the available Casks that match the search term" do lambda { - Hbc::CLI::Search.run('photoshop') - }.must_output <<-OUTPUT.gsub(/^ */, '') + Hbc::CLI::Search.run("photoshop") + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") ==> Partial matches adobe-photoshop-cc adobe-photoshop-lightroom @@ -13,59 +13,47 @@ describe Hbc::CLI::Search do it "shows that there are no Casks matching a search term that did not result in anything" do lambda { - Hbc::CLI::Search.run('foo-bar-baz') + Hbc::CLI::Search.run("foo-bar-baz") }.must_output("No Cask found for \"foo-bar-baz\".\n") end it "lists all available Casks with no search term" do - out, err = capture_io do - Hbc::CLI::Search.run - end - out.must_match(/google-chrome/) + out = capture_io { Hbc::CLI::Search.run }[0] + out.must_match(%r{google-chrome}) out.length.must_be :>, 1000 end it "ignores hyphens in search terms" do - out, err = capture_io do - Hbc::CLI::Search.run('goo-gle-chrome') - end - out.must_match(/google-chrome/) + out = capture_io { Hbc::CLI::Search.run("goo-gle-chrome") }[0] + out.must_match(%r{google-chrome}) out.length.must_be :<, 100 end it "ignores hyphens in Cask tokens" do - out, err = capture_io do - Hbc::CLI::Search.run('googlechrome') - end - out.must_match(/google-chrome/) + out = capture_io { Hbc::CLI::Search.run("googlechrome") }[0] + out.must_match(%r{google-chrome}) out.length.must_be :<, 100 end it "accepts multiple arguments" do - out, err = capture_io do - Hbc::CLI::Search.run('google chrome') - end - out.must_match(/google-chrome/) + out = capture_io { Hbc::CLI::Search.run("google chrome") }[0] + out.must_match(%r{google-chrome}) out.length.must_be :<, 100 end it "accepts a regexp argument" do lambda { - Hbc::CLI::Search.run('/^google-c[a-z]rome$/') + Hbc::CLI::Search.run("/^google-c[a-z]rome$/") }.must_output "==> Regexp matches\ngoogle-chrome\n" end it "Returns both exact and partial matches" do - out, err = capture_io do - Hbc::CLI::Search.run('mnemosyne') - end - out.must_match(/^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne/) + out = capture_io { Hbc::CLI::Search.run("mnemosyne") }[0] + out.must_match(%r{^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne}) end it "does not search the Tap name" do - out, err = capture_io do - Hbc::CLI::Search.run('caskroom') - end - out.must_match(/^No Cask found for "caskroom"\.\n/) + out = capture_io { Hbc::CLI::Search.run("caskroom") }[0] + out.must_match(%r{^No Cask found for "caskroom"\.\n}) end end diff --git a/test/cask/cli/uninstall_test.rb b/test/cask/cli/uninstall_test.rb index 4fae3f63de..9ded581372 100644 --- a/test/cask/cli/uninstall_test.rb +++ b/test/cask/cli/uninstall_test.rb @@ -1,27 +1,27 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Uninstall do it "shows an error when a bad Cask is provided" do lambda { - Hbc::CLI::Uninstall.run('notacask') + Hbc::CLI::Uninstall.run("notacask") }.must_raise Hbc::CaskUnavailableError end it "shows an error when a Cask is provided that's not installed" do lambda { - Hbc::CLI::Uninstall.run('anvil') + Hbc::CLI::Uninstall.run("anvil") }.must_raise Hbc::CaskNotInstalledError end it "tries anyway on a non-present Cask when --force is given" do - lambda { - Hbc::CLI::Uninstall.run('anvil', '--force') - } # wont_raise + lambda do + Hbc::CLI::Uninstall.run("anvil", "--force") + end # wont_raise end it "can uninstall and unlink multiple Casks at once" do - caffeine = Hbc.load('local-caffeine') - transmission = Hbc.load('local-transmission') + caffeine = Hbc.load("local-caffeine") + transmission = Hbc.load("local-transmission") shutup do Hbc::Installer.new(caffeine).install @@ -32,19 +32,19 @@ describe Hbc::CLI::Uninstall do transmission.must_be :installed? shutup do - Hbc::CLI::Uninstall.run('local-caffeine', 'local-transmission') + Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission") end caffeine.wont_be :installed? - File.exist?(Hbc.appdir.join('Transmission.app')).must_equal false + File.exist?(Hbc.appdir.join("Transmission.app")).must_equal false transmission.wont_be :installed? - File.exist?(Hbc.appdir.join('Caffeine.app')).must_equal false + File.exist?(Hbc.appdir.join("Caffeine.app")).must_equal false end describe "when Casks have been renamed" do before do - @renamed_path = Hbc.caskroom.join('ive-been-renamed','latest','Renamed.app').tap(&:mkpath) - @renamed_path.join('Info.plist').open('w') { |f| f.puts "Oh plist" } + @renamed_path = Hbc.caskroom.join("ive-been-renamed", "latest", "Renamed.app").tap(&:mkpath) + @renamed_path.join("Info.plist").open("w") { |f| f.puts "Oh plist" } end after do @@ -53,7 +53,7 @@ describe Hbc::CLI::Uninstall do it "can uninstall non-ruby-backed Casks" do shutup do - Hbc::CLI::Uninstall.run('ive-been-renamed') + Hbc::CLI::Uninstall.run("ive-been-renamed") end @renamed_path.wont_be :exist? @@ -63,7 +63,7 @@ describe Hbc::CLI::Uninstall do describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Uninstall.run() + Hbc::CLI::Uninstall.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -71,7 +71,7 @@ describe Hbc::CLI::Uninstall do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Uninstall.run('--notavalidoption') + Hbc::CLI::Uninstall.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/cli/version_test.rb b/test/cask/cli/version_test.rb index f94c6d7583..b451780c18 100644 --- a/test/cask/cli/version_test.rb +++ b/test/cask/cli/version_test.rb @@ -1,9 +1,9 @@ -require 'test_helper' +require "test_helper" -describe 'brew cask --version' do - it 'respects the --version argument' do +describe "brew cask --version" do + it "respects the --version argument" do lambda { - Hbc::CLI::NullCommand.new('--version').run + Hbc::CLI::NullCommand.new("--version").run }.must_output "#{Hbc.full_version}\n" end end diff --git a/test/cask/cli/zap_test.rb b/test/cask/cli/zap_test.rb index 87b4cbdd30..a9e862b119 100644 --- a/test/cask/cli/zap_test.rb +++ b/test/cask/cli/zap_test.rb @@ -1,15 +1,15 @@ -require 'test_helper' +require "test_helper" describe Hbc::CLI::Zap do it "shows an error when a bad Cask is provided" do lambda { - Hbc::CLI::Zap.run('notacask') + Hbc::CLI::Zap.run("notacask") }.must_raise Hbc::CaskUnavailableError end it "can zap and unlink multiple Casks at once" do - caffeine = Hbc.load('local-caffeine') - transmission = Hbc.load('local-transmission') + caffeine = Hbc.load("local-caffeine") + transmission = Hbc.load("local-transmission") shutup do Hbc::Installer.new(caffeine).install @@ -20,14 +20,14 @@ describe Hbc::CLI::Zap do transmission.must_be :installed? shutup do - Hbc::CLI::Zap.run('--notavalidoption', - 'local-caffeine', 'local-transmission') + Hbc::CLI::Zap.run("--notavalidoption", + "local-caffeine", "local-transmission") end caffeine.wont_be :installed? - Hbc.appdir.join('Transmission.app').wont_be :symlink? + Hbc.appdir.join("Transmission.app").wont_be :symlink? transmission.wont_be :installed? - Hbc.appdir.join('Caffeine.app').wont_be :symlink? + Hbc.appdir.join("Caffeine.app").wont_be :symlink? end # TODO: Explicit test that both zap and uninstall directives get dispatched. @@ -60,7 +60,7 @@ describe Hbc::CLI::Zap do describe "when no Cask is specified" do it "raises an exception" do lambda { - Hbc::CLI::Zap.run() + Hbc::CLI::Zap.run }.must_raise Hbc::CaskUnspecifiedError end end @@ -68,7 +68,7 @@ describe Hbc::CLI::Zap do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do lambda { - Hbc::CLI::Zap.run('--notavalidoption') + Hbc::CLI::Zap.run("--notavalidoption") }.must_raise Hbc::CaskUnspecifiedError end end diff --git a/test/cask/container/dmg_test.rb b/test/cask/container/dmg_test.rb index c3bb32f32c..2c33b88b65 100644 --- a/test/cask/container/dmg_test.rb +++ b/test/cask/container/dmg_test.rb @@ -1,9 +1,9 @@ -require 'test_helper' +require "test_helper" describe Hbc::Container::Dmg do describe "mount!" do it "does not store nil mounts for dmgs with extra data" do - transmission = Hbc.load('local-transmission') + transmission = Hbc.load("local-transmission") dmg = Hbc::Container::Dmg.new( transmission, diff --git a/test/cask/container/naked_test.rb b/test/cask/container/naked_test.rb index ef3addba4b..d40c16de5f 100644 --- a/test/cask/container/naked_test.rb +++ b/test/cask/container/naked_test.rb @@ -1,15 +1,15 @@ -require 'test_helper' +require "test_helper" describe Hbc::Container::Naked do it "saves files with spaces in them from uris with encoded spaces" do - cask = Hbc::Cask.new('spacey') do - url 'http://example.com/kevin%20spacey.pkg' - version '1.2' + cask = Hbc::Cask.new("spacey") do + url "http://example.com/kevin%20spacey.pkg" + version "1.2" end - path = '/tmp/downloads/kevin-spacey-1.2.pkg' - expected_destination = cask.staged_path.join('kevin spacey.pkg') - expected_command = ['/usr/bin/ditto', '--', path, expected_destination] + path = "/tmp/downloads/kevin-spacey-1.2.pkg" + expected_destination = cask.staged_path.join("kevin spacey.pkg") + expected_command = ["/usr/bin/ditto", "--", path, expected_destination] Hbc::FakeSystemCommand.stubs_command(expected_command) container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand) diff --git a/test/cask/depends_on_test.rb b/test/cask/depends_on_test.rb index 8120a2bad0..a00a766265 100644 --- a/test/cask/depends_on_test.rb +++ b/test/cask/depends_on_test.rb @@ -1,9 +1,8 @@ -require 'test_helper' +require "test_helper" # TODO: this test should be named after the corresponding class, once # that class is abstracted from installer.rb describe "Satisfy Dependencies and Requirements" do - # TODO: test that depends_on :formula invokes Homebrew # # describe "depends_on :formula" do @@ -14,7 +13,7 @@ describe "Satisfy Dependencies and Requirements" do describe "depends_on :cask" do it "raises an exception when depends_on :cask is cyclic" do - dep_cask = Hbc.load('with-depends-on-cask-cyclic') + dep_cask = Hbc.load("with-depends-on-cask-cyclic") lambda { shutup do Hbc::Installer.new(dep_cask).install @@ -23,7 +22,7 @@ describe "Satisfy Dependencies and Requirements" do end it "installs the dependency of a Cask and the Cask itself" do - csk = Hbc.load('with-depends-on-cask') + csk = Hbc.load("with-depends-on-cask") dependency = Hbc.load(csk.depends_on.cask.first) shutup do Hbc::Installer.new(csk).install @@ -36,35 +35,35 @@ describe "Satisfy Dependencies and Requirements" do describe "depends_on :macos" do it "understands depends_on :macos => " do - macos_cask = Hbc.load('with-depends-on-macos-array') + macos_cask = Hbc.load("with-depends-on-macos-array") shutup do Hbc::Installer.new(macos_cask).install end end it "understands depends_on :macos => " do - macos_cask = Hbc.load('with-depends-on-macos-comparison') + macos_cask = Hbc.load("with-depends-on-macos-comparison") shutup do Hbc::Installer.new(macos_cask).install end end it "understands depends_on :macos => " do - macos_cask = Hbc.load('with-depends-on-macos-string') + macos_cask = Hbc.load("with-depends-on-macos-string") shutup do Hbc::Installer.new(macos_cask).install end end it "understands depends_on :macos => " do - macos_cask = Hbc.load('with-depends-on-macos-symbol') + macos_cask = Hbc.load("with-depends-on-macos-symbol") shutup do Hbc::Installer.new(macos_cask).install end end it "raises an exception when depends_on :macos is not satisfied" do - macos_cask = Hbc.load('with-depends-on-macos-failure') + macos_cask = Hbc.load("with-depends-on-macos-failure") lambda { shutup do Hbc::Installer.new(macos_cask).install @@ -75,14 +74,14 @@ describe "Satisfy Dependencies and Requirements" do describe "depends_on :arch" do it "succeeds when depends_on :arch is satisfied" do - arch_cask = Hbc.load('with-depends-on-arch') + arch_cask = Hbc.load("with-depends-on-arch") shutup do Hbc::Installer.new(arch_cask).install end end it "raises an exception when depends_on :arch is not satisfied" do - arch_cask = Hbc.load('with-depends-on-arch-failure') + arch_cask = Hbc.load("with-depends-on-arch-failure") lambda { shutup do Hbc::Installer.new(arch_cask).install @@ -93,15 +92,15 @@ describe "Satisfy Dependencies and Requirements" do describe "depends_on :x11" do it "succeeds when depends_on :x11 is satisfied" do - x11_cask = Hbc.load('with-depends-on-x11') + x11_cask = Hbc.load("with-depends-on-x11") shutup do Hbc::Installer.new(x11_cask).install end end it "raises an exception when depends_on :x11 is not satisfied" do - x11_cask = Hbc.load('with-depends-on-x11') - Hbc.stubs(:x11_libpng).returns([Pathname.new('/usr/path/does/not/exist')]) + x11_cask = Hbc.load("with-depends-on-x11") + Hbc.stubs(:x11_libpng).returns([Pathname.new("/usr/path/does/not/exist")]) lambda { shutup do Hbc::Installer.new(x11_cask).install @@ -110,13 +109,13 @@ describe "Satisfy Dependencies and Requirements" do end it "never raises when depends_on :x11 => false" do - x11_cask = Hbc.load('with-depends-on-x11-false') - Hbc.stubs(:x11_executable).returns(Pathname.new('/usr/path/does/not/exist')) - lambda { + x11_cask = Hbc.load("with-depends-on-x11-false") + Hbc.stubs(:x11_executable).returns(Pathname.new("/usr/path/does/not/exist")) + lambda do shutup do Hbc::Installer.new(x11_cask).install end - } # won't raise + end # won't raise end end end diff --git a/test/cask/dsl/postflight_test.rb b/test/cask/dsl/postflight_test.rb index 190221f002..7bcd009334 100644 --- a/test/cask/dsl/postflight_test.rb +++ b/test/cask/dsl/postflight_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe Hbc::DSL::Postflight do - let(:cask) { Hbc.load('basic-cask') } + let(:cask) { Hbc.load("basic-cask") } let(:dsl) { Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::Staged do diff --git a/test/cask/dsl/preflight_test.rb b/test/cask/dsl/preflight_test.rb index 90030dbadb..3db7bff6eb 100644 --- a/test/cask/dsl/preflight_test.rb +++ b/test/cask/dsl/preflight_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe Hbc::DSL::Preflight do - let(:cask) { Hbc.load('basic-cask') } + let(:cask) { Hbc.load("basic-cask") } let(:dsl) { Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::Staged do diff --git a/test/cask/dsl/uninstall_postflight_test.rb b/test/cask/dsl/uninstall_postflight_test.rb index f25533488d..fb05daf5a2 100644 --- a/test/cask/dsl/uninstall_postflight_test.rb +++ b/test/cask/dsl/uninstall_postflight_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe Hbc::DSL::UninstallPostflight do - let(:cask) { Hbc.load('basic-cask') } + let(:cask) { Hbc.load("basic-cask") } let(:dsl) { Hbc::DSL::UninstallPostflight.new(cask, Hbc::FakeSystemCommand) } it "supports the appdir method" do diff --git a/test/cask/dsl/uninstall_preflight_test.rb b/test/cask/dsl/uninstall_preflight_test.rb index 4742d5eddf..0e894f61ef 100644 --- a/test/cask/dsl/uninstall_preflight_test.rb +++ b/test/cask/dsl/uninstall_preflight_test.rb @@ -1,7 +1,7 @@ require "test_helper" describe Hbc::DSL::UninstallPreflight do - let(:cask) { Hbc.load('basic-cask') } + let(:cask) { Hbc.load("basic-cask") } let(:dsl) { Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::Staged do diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 0661beb9c7..fea97a9bf8 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -1,26 +1,26 @@ -require 'test_helper' +require "test_helper" describe Hbc::DSL do it "lets you set url, homepage, and version" do - test_cask = Hbc.load('basic-cask') - test_cask.url.to_s.must_equal 'http://example.com/TestCask.dmg' - test_cask.homepage.must_equal 'http://example.com/' - test_cask.version.to_s.must_equal '1.2.3' + test_cask = Hbc.load("basic-cask") + test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" + test_cask.homepage.must_equal "http://example.com/" + test_cask.version.to_s.must_equal "1.2.3" end describe "when a Cask includes an unknown method" do attempt_unknown_method = nil before do - attempt_unknown_method = lambda { - Hbc::Cask.new('unexpected-method-cask') do + attempt_unknown_method = lambda do + Hbc::Cask.new("unexpected-method-cask") do future_feature :not_yet_on_your_machine end - } + end end it "prints a warning that it has encountered an unexpected method" do - expected = r = Regexp.compile(<<-EOREGEX.undent.lines.map(&:chomp).join('')) + expected = Regexp.compile(<<-EOREGEX.undent.lines.map(&:chomp).join("")) (?m) Warning: .* @@ -36,8 +36,10 @@ describe Hbc::DSL do it "will simply warn, not throw an exception" do begin - capture_subprocess_io { attempt_unknown_method.call } - rescue Exception => e + capture_subprocess_io do + attempt_unknown_method.call + end + rescue StandardError => e flunk("Wanted unexpected method to simply warn, but got exception #{e}") end end @@ -45,121 +47,120 @@ describe Hbc::DSL do describe "header line" do it "requires a valid header format" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-header-format') + lambda { + Hbc.load("invalid/invalid-header-format") }.must_raise(SyntaxError) end it "requires the header token to match the file name" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-header-token-mismatch') + Hbc.load("invalid/invalid-header-token-mismatch") }.must_raise(Hbc::CaskTokenDoesNotMatchError) - err.message.must_include 'Bad header line:' - err.message.must_include 'does not match file name' + err.message.must_include "Bad header line:" + err.message.must_include "does not match file name" end it "does not require a DSL version in the header" do - test_cask = Hbc.load('no-dsl-version') - test_cask.url.to_s.must_equal 'http://example.com/TestCask.dmg' - test_cask.homepage.must_equal 'http://example.com/' - test_cask.version.to_s.must_equal '1.2.3' + test_cask = Hbc.load("no-dsl-version") + test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" + test_cask.homepage.must_equal "http://example.com/" + test_cask.version.to_s.must_equal "1.2.3" end end describe "name stanza" do it "lets you set the full name via a name stanza" do - cask = Hbc::Cask.new('name-cask') do - name 'Proper Name' + cask = Hbc::Cask.new("name-cask") do + name "Proper Name" end cask.name.must_equal [ - 'Proper Name', + "Proper Name", ] end it "Accepts an array value to the name stanza" do - cask = Hbc::Cask.new('array-name-cask') do - name ['Proper Name', 'Alternate Name'] + cask = Hbc::Cask.new("array-name-cask") do + name ["Proper Name", "Alternate Name"] end cask.name.must_equal [ - 'Proper Name', - 'Alternate Name', + "Proper Name", + "Alternate Name", ] end it "Accepts multiple name stanzas" do - cask = Hbc::Cask.new('multi-name-cask') do - name 'Proper Name' - name 'Alternate Name' + cask = Hbc::Cask.new("multi-name-cask") do + name "Proper Name" + name "Alternate Name" end cask.name.must_equal [ - 'Proper Name', - 'Alternate Name', + "Proper Name", + "Alternate Name", ] end end describe "sha256 stanza" do it "lets you set checksum via sha256" do - cask = Hbc::Cask.new('checksum-cask') do - sha256 'imasha2' + cask = Hbc::Cask.new("checksum-cask") do + sha256 "imasha2" end - cask.sha256.must_equal 'imasha2' + cask.sha256.must_equal "imasha2" end end describe "app stanza" do it "allows you to specify app stanzas" do - cask = Hbc::Cask.new('cask-with-apps') do - app 'Foo.app' - app 'Bar.app' + cask = Hbc::Cask.new("cask-with-apps") do + app "Foo.app" + app "Bar.app" end - Array(cask.artifacts[:app]).must_equal [['Foo.app'], ['Bar.app']] + Array(cask.artifacts[:app]).must_equal [["Foo.app"], ["Bar.app"]] end it "allow app stanzas to be empty" do - cask = Hbc::Cask.new('cask-with-no-apps') + cask = Hbc::Cask.new("cask-with-no-apps") Array(cask.artifacts[:app]).must_equal %w[] end end describe "caveats stanza" do it "allows caveats to be specified via a method define" do - cask = Hbc::Cask.new('plain-cask') + cask = Hbc::Cask.new("plain-cask") cask.caveats.must_be :empty? - cask = Hbc::Cask.new('cask-with-caveats') do + cask = Hbc::Cask.new("cask-with-caveats") do def caveats; <<-EOS.undent When you install this Cask, you probably want to know this. EOS end end - cask.caveats.must_equal "When you install this Cask, you probably want to know this.\n" end end describe "pkg stanza" do it "allows installable pkgs to be specified" do - cask = Hbc::Cask.new('cask-with-pkgs') do - pkg 'Foo.pkg' - pkg 'Bar.pkg' + cask = Hbc::Cask.new("cask-with-pkgs") do + pkg "Foo.pkg" + pkg "Bar.pkg" end - Array(cask.artifacts[:pkg]).must_equal [['Foo.pkg'], ['Bar.pkg']] + Array(cask.artifacts[:pkg]).must_equal [["Foo.pkg"], ["Bar.pkg"]] end end describe "url stanza" do it "prevents defining multiple urls" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-two-url') + Hbc.load("invalid/invalid-two-url") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'url' stanza may only appear once" end @@ -168,7 +169,7 @@ describe Hbc::DSL do describe "homepage stanza" do it "prevents defining multiple homepages" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-two-homepage') + Hbc.load("invalid/invalid-two-homepage") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'homepage' stanza may only appear once" end @@ -177,7 +178,7 @@ describe Hbc::DSL do describe "version stanza" do it "prevents defining multiple versions" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-two-version') + Hbc.load("invalid/invalid-two-version") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'version' stanza may only appear once" end @@ -185,215 +186,215 @@ describe Hbc::DSL do describe "appcast stanza" do it "allows appcasts to be specified" do - cask = Hbc.load('with-appcast') + cask = Hbc.load("with-appcast") cask.appcast.to_s.must_match %r{^http} end it "prevents defining multiple appcasts" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-appcast-multiple') + Hbc.load("invalid/invalid-appcast-multiple") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'appcast' stanza may only appear once" end it "refuses to load invalid appcast URLs" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-appcast-url') + lambda { + Hbc.load("invalid/invalid-appcast-url") }.must_raise(Hbc::CaskInvalidError) end end describe "gpg stanza" do it "allows gpg stanza to be specified" do - cask = Hbc.load('with-gpg') + cask = Hbc.load("with-gpg") cask.gpg.to_s.must_match %r{\S} end it "allows gpg stanza to be specified with :key_url" do - cask = Hbc.load('with-gpg-key-url') + cask = Hbc.load("with-gpg-key-url") cask.gpg.to_s.must_match %r{\S} end it "prevents specifying gpg stanza multiple times" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-multiple-stanzas') + Hbc.load("invalid/invalid-gpg-multiple-stanzas") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'gpg' stanza may only appear once" end it "prevents missing gpg key parameters" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-missing-key') + Hbc.load("invalid/invalid-gpg-missing-key") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'gpg' stanza must include exactly one" end it "prevents conflicting gpg key parameters" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-conflicting-keys') + Hbc.load("invalid/invalid-gpg-conflicting-keys") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'gpg' stanza must include exactly one" end it "refuses to load invalid gpg signature URLs" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-signature-url') + lambda { + Hbc.load("invalid/invalid-gpg-signature-url") }.must_raise(Hbc::CaskInvalidError) end it "refuses to load invalid gpg key URLs" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-key-url') + lambda { + Hbc.load("invalid/invalid-gpg-key-url") }.must_raise(Hbc::CaskInvalidError) end it "refuses to load invalid gpg key IDs" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-key-id') + lambda { + Hbc.load("invalid/invalid-gpg-key-id") }.must_raise(Hbc::CaskInvalidError) end it "refuses to load if gpg parameter is unknown" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-gpg-parameter') + lambda { + Hbc.load("invalid/invalid-gpg-parameter") }.must_raise(Hbc::CaskInvalidError) end end describe "depends_on stanza" do it "refuses to load with an invalid depends_on key" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-depends-on-key') + lambda { + Hbc.load("invalid/invalid-depends-on-key") }.must_raise(Hbc::CaskInvalidError) end end describe "depends_on :formula" do it "allows depends_on :formula to be specified" do - cask = Hbc.load('with-depends-on-formula') + cask = Hbc.load("with-depends-on-formula") cask.depends_on.formula.wont_be_nil end it "allows multiple depends_on :formula to be specified" do - cask = Hbc.load('with-depends-on-formula-multiple') + cask = Hbc.load("with-depends-on-formula-multiple") cask.depends_on.formula.wont_be_nil end end describe "depends_on :cask" do it "allows depends_on :cask to be specified" do - cask = Hbc.load('with-depends-on-cask') + cask = Hbc.load("with-depends-on-cask") cask.depends_on.cask.wont_be_nil end it "allows multiple depends_on :cask to be specified" do - cask = Hbc.load('with-depends-on-cask-multiple') + cask = Hbc.load("with-depends-on-cask-multiple") cask.depends_on.cask.wont_be_nil end end describe "depends_on :macos" do it "allows depends_on :macos to be specified" do - cask = Hbc.load('with-depends-on-macos-string') + cask = Hbc.load("with-depends-on-macos-string") cask.depends_on.macos.wont_be_nil end it "refuses to load with an invalid depends_on :macos value" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-depends-on-macos-bad-release') + lambda { + Hbc.load("invalid/invalid-depends-on-macos-bad-release") }.must_raise(Hbc::CaskInvalidError) end it "refuses to load with conflicting depends_on :macos forms" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-depends-on-macos-conflicting-forms') + lambda { + Hbc.load("invalid/invalid-depends-on-macos-conflicting-forms") }.must_raise(Hbc::CaskInvalidError) end end describe "depends_on :arch" do it "allows depends_on :arch to be specified" do - cask = Hbc.load('with-depends-on-arch') + cask = Hbc.load("with-depends-on-arch") cask.depends_on.arch.wont_be_nil end it "refuses to load with an invalid depends_on :arch value" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-depends-on-arch-value') + lambda { + Hbc.load("invalid/invalid-depends-on-arch-value") }.must_raise(Hbc::CaskInvalidError) end end describe "depends_on :x11" do it "allows depends_on :x11 to be specified" do - cask = Hbc.load('with-depends-on-x11') + cask = Hbc.load("with-depends-on-x11") cask.depends_on.x11.wont_be_nil end it "refuses to load with an invalid depends_on :x11 value" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-depends-on-x11-value') + lambda { + Hbc.load("invalid/invalid-depends-on-x11-value") }.must_raise(Hbc::CaskInvalidError) end end describe "conflicts_with stanza" do it "allows conflicts_with stanza to be specified" do - cask = Hbc.load('with-conflicts-with') + cask = Hbc.load("with-conflicts-with") cask.conflicts_with.formula.wont_be_nil end it "refuses to load invalid conflicts_with key" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-conflicts-with-key') + lambda { + Hbc.load("invalid/invalid-conflicts-with-key") }.must_raise(Hbc::CaskInvalidError) end end describe "license stanza" do it "allows the license to be specified" do - cask = Hbc.load('with-license') + cask = Hbc.load("with-license") cask.license.value.must_equal :gpl end it "the license has a category" do - cask = Hbc.load('with-license') + cask = Hbc.load("with-license") cask.license.category.must_equal :oss end it "prevents defining multiple license stanzas" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-license-multiple') + Hbc.load("invalid/invalid-license-multiple") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'license' stanza may only appear once" end it "refuses to load on invalid license value" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-license-value') + lambda { + Hbc.load("invalid/invalid-license-value") }.must_raise(Hbc::CaskInvalidError) end end describe "installer stanza" do it "allows installer :script to be specified" do - cask = Hbc.load('with-installer-script') - cask.artifacts[:installer].first.script[:executable].must_equal '/usr/bin/true' - cask.artifacts[:installer].first.script[:args].must_equal ['--flag'] - cask.artifacts[:installer].to_a[1].script[:executable].must_equal '/usr/bin/false' - cask.artifacts[:installer].to_a[1].script[:args].must_equal ['--flag'] + cask = Hbc.load("with-installer-script") + cask.artifacts[:installer].first.script[:executable].must_equal "/usr/bin/true" + cask.artifacts[:installer].first.script[:args].must_equal ["--flag"] + cask.artifacts[:installer].to_a[1].script[:executable].must_equal "/usr/bin/false" + cask.artifacts[:installer].to_a[1].script[:args].must_equal ["--flag"] end it "allows installer :manual to be specified" do - cask = Hbc.load('with-installer-manual') - cask.artifacts[:installer].first.manual.must_equal 'Caffeine.app' + cask = Hbc.load("with-installer-manual") + cask.artifacts[:installer].first.manual.must_equal "Caffeine.app" end end describe "stage_only stanza" do it "allows stage_only stanza to be specified" do - cask = Hbc.load('stage-only') + cask = Hbc.load("stage-only") cask.artifacts[:stage_only].first.must_equal [true] end it "prevents specifying stage_only with other activatables" do err = lambda { - invalid_cask = Hbc.load('invalid/invalid-stage-only-conflict') + Hbc.load("invalid/invalid-stage-only-conflict") }.must_raise(Hbc::CaskInvalidError) err.message.must_include "'stage_only' must be the only activatable artifact" end @@ -401,14 +402,14 @@ describe Hbc::DSL do describe "auto_updates stanza" do it "allows auto_updates stanza to be specified" do - cask = Hbc.load('auto-updates') + cask = Hbc.load("auto-updates") cask.auto_updates.must_equal true end end describe "appdir" do it "allows interpolation of the appdir value in stanzas" do - cask = Hbc.load('appdir-interpolation') + cask = Hbc.load("appdir-interpolation") cask.artifacts[:binary].first.must_equal ["#{Hbc.appdir}/some/path"] end @@ -417,7 +418,7 @@ describe Hbc::DSL do Hbc.appdir = "#{original_appdir}/" begin - cask = Hbc::Cask.new('appdir-trailing-slash') do + cask = Hbc::Cask.new("appdir-trailing-slash") do binary "#{appdir}/some/path" end diff --git a/test/cask/installer_test.rb b/test/cask/installer_test.rb index 3b4873c9a8..3dbbfe6e6a 100644 --- a/test/cask/installer_test.rb +++ b/test/cask/installer_test.rb @@ -1,163 +1,165 @@ -require 'test_helper' +require "test_helper" describe Hbc::Installer do describe "install" do it "downloads and installs a nice fresh Cask" do - caffeine = Hbc.load('local-caffeine') + caffeine = Hbc.load("local-caffeine") shutup do Hbc::Installer.new(caffeine).install end - dest_path = Hbc.caskroom.join('local-caffeine',caffeine.version) + dest_path = Hbc.caskroom.join("local-caffeine", caffeine.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Caffeine.app') + application = Hbc.appdir.join("Caffeine.app") application.must_be :directory? end it "works with dmg-based Casks" do - transmission = Hbc.load('local-transmission') + transmission = Hbc.load("local-transmission") shutup do Hbc::Installer.new(transmission).install end - dest_path = Hbc.caskroom.join('local-transmission',transmission.version) + dest_path = Hbc.caskroom.join("local-transmission", transmission.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Transmission.app') + application = Hbc.appdir.join("Transmission.app") application.must_be :directory? end it "works with tar-based Casks" do - tarball = Hbc.load('tarball') + tarball = Hbc.load("tarball") shutup do Hbc::Installer.new(tarball).install end - dest_path = Hbc.caskroom.join('tarball',tarball.version) + dest_path = Hbc.caskroom.join("tarball", tarball.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Tarball.app') + application = Hbc.appdir.join("Tarball.app") application.must_be :directory? end it "works with cab-based Casks" do - skip('cabextract not installed') unless Hbc.homebrew_prefix.join('bin','cabextract').exist? - cab_container = Hbc.load('cab-container') - empty = stub(:formula => [], :cask => [], :macos => nil, :arch => nil, :x11 => nil) + skip("cabextract not installed") unless Hbc.homebrew_prefix.join("bin", "cabextract").exist? + cab_container = Hbc.load("cab-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) cab_container.stubs(:depends_on).returns(empty) shutup do Hbc::Installer.new(cab_container).install end - dest_path = Hbc.caskroom.join('cab-container',cab_container.version) + dest_path = Hbc.caskroom.join("cab-container", cab_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Application.app') + application = Hbc.appdir.join("Application.app") application.must_be :directory? end it "works with Adobe AIR-based Casks" do - skip('Adobe AIR not installed') unless Hbc::Container::Air.installer_exist? - air_container = Hbc.load('adobe-air-container') + skip("Adobe AIR not installed") unless Hbc::Container::Air.installer_exist? + air_container = Hbc.load("adobe-air-container") + shutup do Hbc::Installer.new(air_container).install end - dest_path = Hbc.caskroom.join('adobe-air-container',air_container.version) + + dest_path = Hbc.caskroom.join("adobe-air-container", air_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('GMDesk.app') + application = Hbc.appdir.join("GMDesk.app") application.must_be :directory? end it "works with 7z-based Casks" do - skip('unar not installed') unless Hbc.homebrew_prefix.join('bin','unar').exist? - sevenzip_container = Hbc.load('sevenzip-container') - empty = stub(:formula => [], :cask => [], :macos => nil, :arch => nil, :x11 => nil) + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + sevenzip_container = Hbc.load("sevenzip-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) sevenzip_container.stubs(:depends_on).returns(empty) shutup do Hbc::Installer.new(sevenzip_container).install end - dest_path = Hbc.caskroom.join('sevenzip-container',sevenzip_container.version) + dest_path = Hbc.caskroom.join("sevenzip-container", sevenzip_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Application.app') + application = Hbc.appdir.join("Application.app") application.must_be :directory? end it "works with xar-based Casks" do - xar_container = Hbc.load('xar-container') + xar_container = Hbc.load("xar-container") shutup do Hbc::Installer.new(xar_container).install end - dest_path = Hbc.caskroom.join('xar-container',xar_container.version) + dest_path = Hbc.caskroom.join("xar-container", xar_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Application.app') + application = Hbc.appdir.join("Application.app") application.must_be :directory? end it "works with Stuffit-based Casks" do - skip('unar not installed') unless Hbc.homebrew_prefix.join('bin','unar').exist? - stuffit_container = Hbc.load('stuffit-container') - empty = stub(:formula => [], :cask => [], :macos => nil, :arch => nil, :x11 => nil) + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + stuffit_container = Hbc.load("stuffit-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) stuffit_container.stubs(:depends_on).returns(empty) shutup do Hbc::Installer.new(stuffit_container).install end - dest_path = Hbc.caskroom.join('stuffit-container',stuffit_container.version) + dest_path = Hbc.caskroom.join("stuffit-container", stuffit_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('sheldonmac','v1.0') + application = Hbc.appdir.join("sheldonmac", "v1.0") application.must_be :directory? end it "works with RAR-based Casks" do - skip('unar not installed') unless Hbc.homebrew_prefix.join('bin','unar').exist? - rar_container = Hbc.load('rar-container') - empty = stub(:formula => [], :cask => [], :macos => nil, :arch => nil, :x11 => nil) + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + rar_container = Hbc.load("rar-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) rar_container.stubs(:depends_on).returns(empty) shutup do Hbc::Installer.new(rar_container).install end - dest_path = Hbc.caskroom.join('rar-container',rar_container.version) + dest_path = Hbc.caskroom.join("rar-container", rar_container.version) dest_path.must_be :directory? - application = Hbc.appdir.join('Application.app') + application = Hbc.appdir.join("Application.app") application.must_be :directory? end it "works with bz2-based Casks" do - asset = Hbc.load('bzipped-asset') + asset = Hbc.load("bzipped-asset") shutup do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join('bzipped-asset',asset.version) + dest_path = Hbc.caskroom.join("bzipped-asset", asset.version) dest_path.must_be :directory? file = Hbc.appdir.join("bzipped-asset-#{asset.version}") file.must_be :file? end it "works with pure gz-based Casks" do - asset = Hbc.load('gzipped-asset') + asset = Hbc.load("gzipped-asset") shutup do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join('gzipped-asset',asset.version) + dest_path = Hbc.caskroom.join("gzipped-asset", asset.version) dest_path.must_be :directory? file = Hbc.appdir.join("gzipped-asset-#{asset.version}") file.must_be :file? end it "blows up on a bad checksum" do - bad_checksum = Hbc.load('bad-checksum') + bad_checksum = Hbc.load("bad-checksum") lambda { shutup do Hbc::Installer.new(bad_checksum).install @@ -166,7 +168,7 @@ describe Hbc::Installer do end it "blows up on a missing checksum" do - missing_checksum = Hbc.load('missing-checksum') + missing_checksum = Hbc.load("missing-checksum") lambda { shutup do Hbc::Installer.new(missing_checksum).install @@ -175,134 +177,150 @@ describe Hbc::Installer do end it "installs fine if sha256 :no_check is used" do - no_checksum = Hbc.load('no-checksum') + no_checksum = Hbc.load("no-checksum") + shutup do Hbc::Installer.new(no_checksum).install end + no_checksum.must_be :installed? end it "fails to install if sha256 :no_check is used with --require-sha" do - no_checksum = Hbc.load('no-checksum') + no_checksum = Hbc.load("no-checksum") lambda { Hbc::Installer.new(no_checksum, require_sha: true).install }.must_raise(Hbc::CaskNoShasumError) end it "installs fine if sha256 :no_check is used with --require-sha and --force" do - no_checksum = Hbc.load('no-checksum') + no_checksum = Hbc.load("no-checksum") + shutup do Hbc::Installer.new(no_checksum, require_sha: true, force: true).install end + no_checksum.must_be :installed? end it "prints caveats if they're present" do - with_caveats = Hbc.load('with-caveats') + with_caveats = Hbc.load("with-caveats") TestHelper.must_output(self, lambda { Hbc::Installer.new(with_caveats).install - }, /Here are some things you might want to know/) + }, %r{Here are some things you might want to know}) with_caveats.must_be :installed? end it "prints installer :manual instructions when present" do - with_installer_manual = Hbc.load('with-installer-manual') + with_installer_manual = Hbc.load("with-installer-manual") TestHelper.must_output(self, lambda { Hbc::Installer.new(with_installer_manual).install - }, /To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join(%Q{Caffeine.app})}'/) + }, %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'}) with_installer_manual.must_be :installed? end it "does not extract __MACOSX directories from zips" do - with_macosx_dir = Hbc.load('with-macosx-dir') + with_macosx_dir = Hbc.load("with-macosx-dir") + shutup do Hbc::Installer.new(with_macosx_dir).install end - with_macosx_dir.staged_path.join('__MACOSX').wont_be :directory? + + with_macosx_dir.staged_path.join("__MACOSX").wont_be :directory? end it "installer method raises an exception when already-installed Casks which auto-update are attempted" do - auto_updates = Hbc.load('auto-updates') + auto_updates = Hbc.load("auto-updates") auto_updates.installed?.must_equal false installer = Hbc::Installer.new(auto_updates) - shutup { installer.install } + shutup do + installer.install + end + lambda { installer.install }.must_raise(Hbc::CaskAutoUpdatesError) end it "allows already-installed Casks which auto-update to be installed if force is provided" do - auto_updates = Hbc.load('auto-updates') + auto_updates = Hbc.load("auto-updates") auto_updates.installed?.must_equal false - shutup { Hbc::Installer.new(auto_updates).install } + shutup do + Hbc::Installer.new(auto_updates).install + end - shutup { + shutup do Hbc::Installer.new(auto_updates, force: true).install - } # wont_raise + end # wont_raise end # unlike the CLI, the internal interface throws exception on double-install it "installer method raises an exception when already-installed Casks are attempted" do - transmission = Hbc.load('local-transmission') + transmission = Hbc.load("local-transmission") transmission.installed?.must_equal false installer = Hbc::Installer.new(transmission) - shutup { installer.install } + shutup do + installer.install + end + lambda { installer.install }.must_raise(Hbc::CaskAlreadyInstalledError) end it "allows already-installed Casks to be installed if force is provided" do - transmission = Hbc.load('local-transmission') + transmission = Hbc.load("local-transmission") transmission.installed?.must_equal false - shutup { Hbc::Installer.new(transmission).install } + shutup do + Hbc::Installer.new(transmission).install + end - shutup { + shutup do Hbc::Installer.new(transmission, force: true).install - } # wont_raise + end # wont_raise end it "works properly with a direct URL to a pkg" do - naked_pkg = Hbc.load('naked-pkg') + naked_pkg = Hbc.load("naked-pkg") shutup do Hbc::Installer.new(naked_pkg).install end - dest_path = Hbc.caskroom.join('naked-pkg',naked_pkg.version) - pkg = dest_path.join('Naked.pkg') + dest_path = Hbc.caskroom.join("naked-pkg", naked_pkg.version) + pkg = dest_path.join("Naked.pkg") pkg.must_be :file? end it "works properly with an overridden container :type" do - naked_executable = Hbc.load('naked-executable') + naked_executable = Hbc.load("naked-executable") shutup do Hbc::Installer.new(naked_executable).install end - dest_path = Hbc.caskroom.join('naked-executable',naked_executable.version) - executable = dest_path.join('naked_executable') + dest_path = Hbc.caskroom.join("naked-executable", naked_executable.version) + executable = dest_path.join("naked_executable") executable.must_be :file? end it "works fine with a nested container" do - nested_app = Hbc.load('nested-app') + nested_app = Hbc.load("nested-app") shutup do Hbc::Installer.new(nested_app).install end - dest_path = Hbc.appdir.join('MyNestedApp.app') - File.ftype(dest_path).must_equal 'directory' + dest_path = Hbc.appdir.join("MyNestedApp.app") + File.ftype(dest_path).must_equal "directory" end it "generates and finds a timestamped metadata directory for an installed Cask" do - caffeine = Hbc.load('local-caffeine') + caffeine = Hbc.load("local-caffeine") shutup do Hbc::Installer.new(caffeine).install @@ -314,13 +332,13 @@ describe Hbc::Installer do end it "generates and finds a metadata subdirectory for an installed Cask" do - caffeine = Hbc.load('local-caffeine') + caffeine = Hbc.load("local-caffeine") shutup do Hbc::Installer.new(caffeine).install end - subdir_name = 'Casks' + subdir_name = "Casks" m_subdir = caffeine.metadata_subdir(subdir_name, :now, true) caffeine.metadata_subdir(subdir_name, :now, false).must_equal(m_subdir) caffeine.metadata_subdir(subdir_name, :latest).must_equal(m_subdir) @@ -329,7 +347,7 @@ describe Hbc::Installer do describe "uninstall" do it "fully uninstalls a Cask" do - caffeine = Hbc.load('local-caffeine') + caffeine = Hbc.load("local-caffeine") installer = Hbc::Installer.new(caffeine) shutup do @@ -337,32 +355,32 @@ describe Hbc::Installer do installer.uninstall end - Hbc.caskroom.join('local-caffeine',caffeine.version,'Caffeine.app').wont_be :directory? - Hbc.caskroom.join('local-caffeine',caffeine.version).wont_be :directory? - Hbc.caskroom.join('local-caffeine').wont_be :directory? + Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app").wont_be :directory? + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine").wont_be :directory? end it "uninstalls all versions if force is set" do - caffeine = Hbc.load('local-caffeine') - mutated_version = caffeine.version + '.1' + caffeine = Hbc.load("local-caffeine") + mutated_version = caffeine.version + ".1" shutup do Hbc::Installer.new(caffeine).install end - Hbc.caskroom.join('local-caffeine',caffeine.version).must_be :directory? - Hbc.caskroom.join('local-caffeine',mutated_version).wont_be :directory? - FileUtils.mv(Hbc.caskroom.join('local-caffeine',caffeine.version), Hbc.caskroom.join('local-caffeine',mutated_version)) - Hbc.caskroom.join('local-caffeine',caffeine.version).wont_be :directory? - Hbc.caskroom.join('local-caffeine',mutated_version).must_be :directory? + Hbc.caskroom.join("local-caffeine", caffeine.version).must_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? + FileUtils.mv(Hbc.caskroom.join("local-caffeine", caffeine.version), Hbc.caskroom.join("local-caffeine", mutated_version)) + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).must_be :directory? shutup do Hbc::Installer.new(caffeine, force: true).uninstall end - Hbc.caskroom.join('local-caffeine',caffeine.version).wont_be :directory? - Hbc.caskroom.join('local-caffeine',mutated_version).wont_be :directory? - Hbc.caskroom.join('local-caffeine').wont_be :directory? + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? + Hbc.caskroom.join("local-caffeine").wont_be :directory? end end end diff --git a/test/cask/pkg_test.rb b/test/cask/pkg_test.rb index 66dfd492ab..5734a58f6a 100644 --- a/test/cask/pkg_test.rb +++ b/test/cask/pkg_test.rb @@ -1,14 +1,14 @@ -require 'test_helper' +require "test_helper" describe Hbc::Pkg do - describe 'uninstall' do - it 'removes files and dirs referenced by the pkg' do - pkg = Hbc::Pkg.new('my.fake.pkg', Hbc::NeverSudoSystemCommand) + describe "uninstall" do + it "removes files and dirs referenced by the pkg" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) - some_files = Array.new(3) { Pathname(Tempfile.new('testfile').path) } + some_files = Array.new(3) { Pathname(Tempfile.new("testfile").path) } pkg.stubs(:pkgutil_bom_files).returns some_files - some_specials = Array.new(3) { Pathname(Tempfile.new('testfile').path) } + some_specials = Array.new(3) { Pathname(Tempfile.new("testfile").path) } pkg.stubs(:pkgutil_bom_specials).returns some_specials some_dirs = Array.new(3) { Pathname(Dir.mktmpdir) } @@ -18,38 +18,43 @@ describe Hbc::Pkg do pkg.uninstall - some_files.each { |file| file.wont_be :exist? } - some_dirs.each { |dir| dir.wont_be :exist? } + some_files.each do |file| + file.wont_be :exist? + end + + some_dirs.each do |dir| + dir.wont_be :exist? + end end - it 'forgets the pkg' do - pkg = Hbc::Pkg.new('my.fake.pkg', Hbc::FakeSystemCommand) + it "forgets the pkg" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::FakeSystemCommand) Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-files', '--files', 'my.fake.pkg'] + ["/usr/sbin/pkgutil", "--only-files", "--files", "my.fake.pkg"] ) Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--only-dirs', '--files', 'my.fake.pkg'] - ) + ["/usr/sbin/pkgutil", "--only-dirs", "--files", "my.fake.pkg"] + ) Hbc::FakeSystemCommand.stubs_command( - ['/usr/sbin/pkgutil', '--files', 'my.fake.pkg'] + ["/usr/sbin/pkgutil", "--files", "my.fake.pkg"] ) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/sbin/pkgutil', '--forget', 'my.fake.pkg'] + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/pkgutil", "--forget", "my.fake.pkg"] ) pkg.uninstall end - it 'cleans broken symlinks, but leaves AOK symlinks' do - pkg = Hbc::Pkg.new('my.fake.pkg', Hbc::NeverSudoSystemCommand) + it "cleans broken symlinks, but leaves AOK symlinks" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) fake_dir = Pathname(Dir.mktmpdir) - fake_file = fake_dir.join('ima_file').tap { |path| FileUtils.touch(path) } + fake_file = fake_dir.join("ima_file").tap { |path| FileUtils.touch(path) } - intact_symlink = fake_dir.join('intact_symlink').tap { |path| path.make_symlink(fake_file) } - broken_symlink = fake_dir.join('broken_symlink').tap { |path| path.make_symlink('im_nota_file') } + intact_symlink = fake_dir.join("intact_symlink").tap { |path| path.make_symlink(fake_file) } + broken_symlink = fake_dir.join("broken_symlink").tap { |path| path.make_symlink("im_nota_file") } pkg.stubs(:pkgutil_bom_specials).returns([]) pkg.stubs(:pkgutil_bom_files).returns([]) @@ -63,15 +68,14 @@ describe Hbc::Pkg do fake_dir.must_be :exist? end - it 'snags permissions on ornery dirs, but returns them afterwords' do - pkg = Hbc::Pkg.new('my.fake.pkg', Hbc::NeverSudoSystemCommand) + it "snags permissions on ornery dirs, but returns them afterwords" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) - fake_dir = Pathname(Dir.mktmpdir) + fake_dir = Pathname(Dir.mktmpdir) - fake_file = fake_dir.join('ima_installed_file').tap { |path| FileUtils.touch(path) } - other_file = fake_dir.join('ima_other_file').tap { |path| FileUtils.touch(path) } + fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) } - fake_dir.chmod(0000) + fake_dir.chmod(0o000) pkg.stubs(:pkgutil_bom_specials).returns([]) pkg.stubs(:pkgutil_bom_files).returns([fake_file]) @@ -84,7 +88,7 @@ describe Hbc::Pkg do fake_dir.must_be :directory? fake_file.wont_be :file? - (fake_dir.stat.mode % 01000).to_s(8).must_equal '0' + (fake_dir.stat.mode % 0o1000).to_s(8).must_equal "0" end end end diff --git a/test/cask/staged_test.rb b/test/cask/staged_test.rb index 77bfbe2780..fe3bf23399 100644 --- a/test/cask/staged_test.rb +++ b/test/cask/staged_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" # TODO: this test should be named after the corresponding class, once # that class is abstracted from installer.rb. It makes little sense @@ -6,13 +6,13 @@ require 'test_helper' describe "Operations on staged Casks" do describe "bundle ID" do it "fetches the bundle ID from a staged cask" do - transmission_cask = Hbc.load('local-transmission') + transmission_cask = Hbc.load("local-transmission") tr_installer = Hbc::Installer.new(transmission_cask) shutup do tr_installer.install end - tr_installer.bundle_identifier.must_equal('org.m0k.transmission') + tr_installer.bundle_identifier.must_equal("org.m0k.transmission") end end end diff --git a/test/cask/url_checker_test.rb b/test/cask/url_checker_test.rb index 0409c9c0af..cb0e50d575 100644 --- a/test/cask/url_checker_test.rb +++ b/test/cask/url_checker_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" describe Hbc::UrlChecker do describe "request processing" do @@ -11,7 +11,7 @@ describe Hbc::UrlChecker do end it "properly populates the response code and headers from an http response" do - TestHelper.fake_response_for(TestHelper.test_cask.url, <<-RESPONSE.gsub(/^ */, '')) + TestHelper.fake_response_for(TestHelper.test_cask.url, <<-RESPONSE.gsub(%r{^ *}, "")) HTTP/1.1 200 OK Content-Type: application/x-apple-diskimage ETag: "b4208f3e84967be4b078ecaa03fba941" @@ -21,13 +21,11 @@ describe Hbc::UrlChecker do checker = Hbc::UrlChecker.new(TestHelper.test_cask, TestHelper.fake_fetcher) checker.run - checker.response_status.must_equal 'HTTP/1.1 200 OK' - checker.headers.must_equal({ - 'Content-Type' => 'application/x-apple-diskimage', - 'ETag' => '"b4208f3e84967be4b078ecaa03fba941"', - 'Content-Length' => '23726161', - 'Last-Modified' => 'Sun, 12 Aug 2012 21:17:21 GMT' - }) + checker.response_status.must_equal "HTTP/1.1 200 OK" + checker.headers.must_equal("Content-Type" => "application/x-apple-diskimage", + "ETag" => '"b4208f3e84967be4b078ecaa03fba941"', + "Content-Length" => "23726161", + "Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT") end end end diff --git a/test/cask_test.rb b/test/cask_test.rb index 06998535ef..05bdb6eff3 100644 --- a/test/cask_test.rb +++ b/test/cask_test.rb @@ -1,32 +1,32 @@ -require 'test_helper' +require "test_helper" describe "Cask" do describe "load" do it "returns an instance of the Cask for the given token" do c = Hbc.load("adium") c.must_be_kind_of(Hbc::Cask) - c.token.must_equal('adium') + c.token.must_equal("adium") end it "returns an instance of the Cask from a specific file location" do - location = File.expand_path('./Casks/dia.rb') + location = File.expand_path("./Casks/dia.rb") c = Hbc.load(location) c.must_be_kind_of(Hbc::Cask) - c.token.must_equal('dia') + c.token.must_equal("dia") end it "returns an instance of the Cask from a url" do - url = "file://" + File.expand_path('./Casks/dia.rb') + url = "file://" + File.expand_path("./Casks/dia.rb") c = shutup do Hbc.load(url) end c.must_be_kind_of(Hbc::Cask) - c.token.must_equal('dia') + c.token.must_equal("dia") end it "raises an error when failing to download a Cask from a url" do lambda { - url = "file://" + File.expand_path('./Casks/notacask.rb') + url = "file://" + File.expand_path("./Casks/notacask.rb") shutup do Hbc.load(url) end @@ -36,12 +36,12 @@ describe "Cask" do it "returns an instance of the Cask from a relative file location" do c = Hbc.load("./Casks/bbedit.rb") c.must_be_kind_of(Hbc::Cask) - c.token.must_equal('bbedit') + c.token.must_equal("bbedit") end it "uses exact match when loading by token" do - Hbc.load('test-opera').token.must_equal('test-opera') - Hbc.load('test-opera-mail').token.must_equal('test-opera-mail') + Hbc.load("test-opera").token.must_equal("test-opera") + Hbc.load("test-opera-mail").token.must_equal("test-opera-mail") end it "raises an error when attempting to load a Cask that doesn't exist" do @@ -63,7 +63,7 @@ describe "Cask" do it "proposes a versioned metadata directory name for each instance" do cask_token = "adium" c = Hbc.load(cask_token) - metadata_path = Hbc.caskroom.join(cask_token, '.metadata', c.version) + metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) c.metadata_versioned_container_path.to_s.must_equal(metadata_path.to_s) end end diff --git a/test/layout_test.rb b/test/layout_test.rb index 8d1fa52288..2b65c9a4ed 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" describe "Repo layout" do project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) @@ -10,53 +10,53 @@ describe "Repo layout" do # dot dirs are always a project of Dir.entries # other files are items that the developer hopefully has gitignored IGNORE_FILES = %w[ - . - .. - .DS_Store - .bundle - .rubocop.yml - .rubocop_todo.yml - .ruby-version - coverage - ] + . + .. + .DS_Store + .bundle + .rubocop.yml + .rubocop_todo.yml + .ruby-version + coverage + ].freeze # the developer has hopefully gitignored these IGNORE_REGEXPS = [ %r{~$}, # emacs - ] + ].freeze TOPLEVEL_DIRS = %w[ - .git - .github - Casks - Formula - ci - cmd - developer - doc - lib - man - spec - test - ] + .git + .github + Casks + Formula + ci + cmd + developer + doc + lib + man + spec + test + ].freeze TOPLEVEL_FILES = %w[ - .editorconfig - .gitattributes - .gitignore - .rspec - .rubocop.yml - .simplecov - .travis.yml - CONDUCT.md - CONTRIBUTING.md - Gemfile - Gemfile.lock - LICENSE - README.md - Rakefile - USAGE.md - ] + .editorconfig + .gitattributes + .gitignore + .rspec + .rubocop.yml + .simplecov + .travis.yml + CONDUCT.md + CONTRIBUTING.md + Gemfile + Gemfile.lock + LICENSE + README.md + Rakefile + USAGE.md + ].freeze describe "toplevel dir" do it "finds some files at the top level" do @@ -75,12 +75,12 @@ describe "Repo layout" do describe "Casks dir" do it "finds some files in the Casks dir" do - entries = Dir.entries(project_root.join('Casks')) + entries = Dir.entries(project_root.join("Casks")) entries.length.must_be :>, 0 end it "only finds .rb files in the Casks dir" do - entries = Dir.entries(project_root.join('Casks')) - IGNORE_FILES + entries = Dir.entries(project_root.join("Casks")) - IGNORE_FILES IGNORE_REGEXPS.each do |regexp| entries.reject! { |elt| elt.match(regexp) } end diff --git a/test/plist/parser_test.rb b/test/plist/parser_test.rb index 84b97dd323..a73d1f7f58 100644 --- a/test/plist/parser_test.rb +++ b/test/plist/parser_test.rb @@ -1,7 +1,7 @@ -require 'test_helper' +require "test_helper" describe Plist do - it 'parses some hdiutil output okay' do + it "parses some hdiutil output okay" do hdiutil_output = <<-HDIUTILOUTPUT @@ -50,16 +50,16 @@ describe Plist do parsed = Plist.parse_xml(hdiutil_output) - parsed.keys.must_equal ['system-entities'] - parsed['system-entities'].length.must_equal 3 - parsed['system-entities'].map { |e| e['dev-entry'] }.must_equal %w[ - /dev/disk3s1 - /dev/disk3 - /dev/disk3s2 - ] + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 3 + parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[ + /dev/disk3s1 + /dev/disk3 + /dev/disk3s2 + ] end - it 'can ignore garbage output before xml starts' do + it "can ignore garbage output before xml starts" do hdiutil_output = <<-HDIUTILOUTPUT Hello there! I am in no way XML am I?!?! @@ -96,11 +96,11 @@ Hopefully explode! parsed = Plist.parse_xml(hdiutil_output) - parsed.keys.must_equal ['system-entities'] - parsed['system-entities'].length.must_equal 1 + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 1 end - it 'does not choke on empty input' do - Plist.parse_xml('').must_equal {} + it "does not choke on empty input" do + Plist.parse_xml("").must_equal {} end end diff --git a/test/support/cleanup.rb b/test/support/cleanup.rb index 810f4f4a52..0cb9c02fac 100644 --- a/test/support/cleanup.rb +++ b/test/support/cleanup.rb @@ -2,9 +2,7 @@ module Hbc::CleanupHooks def after_teardown super Hbc.installed.each do |cask| - Hbc::Installer.new(cask).tap do |installer| - installer.purge_versioned_files - end + Hbc::Installer.new(cask).purge_versioned_files end end end diff --git a/test/support/fake_dirs.rb b/test/support/fake_dirs.rb index 83ac18b916..89612f850a 100644 --- a/test/support/fake_dirs.rb +++ b/test/support/fake_dirs.rb @@ -1,6 +1,6 @@ # wire in a set of fake link dirs per-test module FakeDirHooks - DIRS = [:appdir, :qlplugindir, :binarydir] + DIRS = [:appdir, :qlplugindir, :binarydir].freeze def before_setup super diff --git a/test/support/fake_fetcher.rb b/test/support/fake_fetcher.rb index 04a4527aba..a49a89f7f4 100644 --- a/test/support/fake_fetcher.rb +++ b/test/support/fake_fetcher.rb @@ -5,9 +5,7 @@ class Hbc::FakeFetcher def self.head(url) @responses ||= {} - unless @responses.key?(url) - fail("no response faked for #{url.inspect}") - end + raise("no response faked for #{url.inspect}") unless @responses.key?(url) @responses[url] end diff --git a/test/support/fake_system_command.rb b/test/support/fake_system_command.rb index a83e34723a..e19330fd04 100644 --- a/test/support/fake_system_command.rb +++ b/test/support/fake_system_command.rb @@ -17,26 +17,24 @@ class Hbc::FakeSystemCommand @system_calls = nil end - def self.stubs_command(command, response='') + def self.stubs_command(command, response = "") responses[command] = response end - def self.expects_command(command, response='', times=1) + def self.expects_command(command, response = "", times = 1) stubs_command(command, response) expectations[command] = times end - def self.expect_and_pass_through(command, times=1) - pass_through = lambda do |command, options| - Hbc::SystemCommand.run(command, options) - end + def self.expect_and_pass_through(command, times = 1) + pass_through = ->(cmd, opts) { Hbc::SystemCommand.run(cmd, opts) } expects_command(command, pass_through, times) end def self.verify_expectations! expectations.each do |command, times| unless system_calls[command] == times - fail("expected #{command.inspect} to be run #{times} times, but got #{system_calls[command]}") + raise("expected #{command.inspect} to be run #{times} times, but got #{system_calls[command]}") end end end @@ -44,7 +42,7 @@ class Hbc::FakeSystemCommand def self.run(command_string, options = {}) command = Hbc::SystemCommand.new(command_string, options).command unless responses.key?(command) - fail("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") + raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") end system_calls[command] += 1 @@ -52,12 +50,12 @@ class Hbc::FakeSystemCommand if response.respond_to?(:call) response.call(command_string, options) else - Hbc::SystemCommand::Result.new(command, response, '', 0) + Hbc::SystemCommand::Result.new(command, response, "", 0) end end def self.run!(command, options = {}) - run(command, options.merge(:must_succeed => true)) + run(command, options.merge(must_succeed: true)) end end diff --git a/test/support/never_sudo_system_command.rb b/test/support/never_sudo_system_command.rb index e67012e31d..50f510a7a5 100644 --- a/test/support/never_sudo_system_command.rb +++ b/test/support/never_sudo_system_command.rb @@ -1,5 +1,5 @@ class Hbc::NeverSudoSystemCommand < Hbc::SystemCommand def self.run(command, options = {}) - super(command, options.merge(:sudo => false)) + super(command, options.merge(sudo: false)) end end diff --git a/test/support/shared_examples.rb b/test/support/shared_examples.rb index 4ffab68de7..7bd7a0683a 100644 --- a/test/support/shared_examples.rb +++ b/test/support/shared_examples.rb @@ -11,8 +11,8 @@ module MiniTest::Spec::SharedExamples end def it_behaves_like(desc, *args, &block) - self.instance_exec *args, &MiniTest::Spec.shared_examples[desc] - self.instance_eval(&block) if block_given? + instance_exec(*args, &MiniTest::Spec.shared_examples[desc]) + instance_eval(&block) if block_given? end end diff --git a/test/support/shared_examples/staged.rb b/test/support/shared_examples/staged.rb index e51578c19e..ef4ff03418 100644 --- a/test/support/shared_examples/staged.rb +++ b/test/support/shared_examples/staged.rb @@ -1,55 +1,55 @@ -require 'test_helper' +require "test_helper" shared_examples_for Hbc::Staged do - let(:fake_pathname_exists) do - fake_pathname = Pathname('/path/to/file/that/exists') - fake_pathname.stubs(:exist? => true, :expand_path => fake_pathname) + let(:fake_pathname_exists) { + fake_pathname = Pathname("/path/to/file/that/exists") + fake_pathname.stubs(exist?: true, expand_path: fake_pathname) fake_pathname - end + } - let(:fake_pathname_does_not_exist) do - fake_pathname = Pathname('/path/to/file/that/does/not/exist') - fake_pathname.stubs(:exist? => false, :expand_path => 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 - end + } it "can run system commands with list-form arguments" do Hbc::FakeSystemCommand.expects_command( - ['echo', 'homebrew-cask', 'rocks!'] + ["echo", "homebrew-cask", "rocks!"] ) - staged.system_command("echo", :args => ["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') + 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') + staged.stubs(bundle_identifier: "com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( - ['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', staged.info_plist_file] + ["/usr/libexec/PlistBuddy", "-c", "Print CFBundleIdentifier", staged.info_plist_file] ) - staged.plist_exec('Print CFBundleIdentifier') + staged.plist_exec("Print CFBundleIdentifier") end it "can set a key in the Info.plist file" do - staged.stubs(:bundle_identifier => 'com.example.BasicCask') + staged.stubs(bundle_identifier: "com.example.BasicCask") Hbc::FakeSystemCommand.expects_command( - ['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', staged.info_plist_file] + ["/usr/libexec/PlistBuddy", "-c", "Set :JVMOptions:JVMVersion 1.6+", staged.info_plist_file] ) - staged.plist_set(':JVMOptions:JVMVersion', '1.6+') + 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) + staged.stubs(Pathname: fake_pathname) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', fake_pathname] + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname] ) - staged.set_permissions(fake_pathname.to_s, '777') + staged.set_permissions(fake_pathname.to_s, "777") end it "can set the permissions of multiple files" do @@ -57,53 +57,53 @@ shared_examples_for Hbc::Staged do staged.stubs(:Pathname).returns(fake_pathname) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/bin/chmod', '-R', '--', '777', fake_pathname, fake_pathname] + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname, fake_pathname] ) - staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], '777') + 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') + 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') + staged.stubs(current_user: "fake_user") fake_pathname = fake_pathname_exists - staged.stubs(:Pathname => fake_pathname) + staged.stubs(Pathname: fake_pathname) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', fake_pathname] + ["/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') + staged.stubs(current_user: "fake_user") fake_pathname = fake_pathname_exists - staged.stubs(:Pathname => fake_pathname) + staged.stubs(Pathname: fake_pathname) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'fake_user:staff', fake_pathname, fake_pathname] + ["/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) + staged.stubs(Pathname: fake_pathname) Hbc::FakeSystemCommand.expects_command( - ['/usr/bin/sudo', '-E', '--', '/usr/sbin/chown', '-R', '--', 'other_user:other_group', fake_pathname] + ["/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') + 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') + staged.stubs(current_user: "fake_user") fake_pathname = fake_pathname_does_not_exist - staged.stubs(:Pathname => fake_pathname) + staged.stubs(Pathname: fake_pathname) staged.set_ownership(fake_pathname.to_s) end end diff --git a/test/syntax_test.rb b/test/syntax_test.rb index 26dfff2d53..5dac34c13a 100644 --- a/test/syntax_test.rb +++ b/test/syntax_test.rb @@ -1,8 +1,8 @@ -require 'test_helper' +require "test_helper" describe "Syntax check" do project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) - backend_files = Dir[project_root.join('**', '*.rb')].reject{|f| f.match %r{/Casks/}} + backend_files = Dir[project_root.join("**", "*.rb")].reject { |f| f.match %r{/Casks/} } %w[2.0 2.1].each do |major_version| describe "under Ruby #{major_version}" do interpreter = Pathname.new("/System/Library/Frameworks/Ruby.framework/Versions/#{major_version}/usr/bin/ruby") @@ -11,13 +11,13 @@ describe "Syntax check" do interpreter = Pathname.new(Dir["/usr/local/bin/ruby{-,}#{major_version}*"].first.to_s) unless interpreter.exist? interpreter = Pathname.new(Dir["/opt/local/bin/ruby{-,}#{major_version}*"].first.to_s) unless interpreter.exist? flags = %w[-c] - flags.unshift '--disable-all' + flags.unshift "--disable-all" backend_files.each do |file| it "#{file} is valid Ruby" do - skip("Ruby #{ major_version } not found") unless interpreter.exist? - args = flags + [ '--', file ] + skip("Ruby #{major_version} not found") unless interpreter.exist? + args = flags + ["--", file] shutup do - raise SyntaxError.new("#{file} failed syntax check") unless system(interpreter, *args) + raise SyntaxError, "#{file} failed syntax check" unless system(interpreter, *args) end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index c93c908a48..9139c7a15d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,40 +1,37 @@ -require 'bundler' -require 'bundler/setup' -require 'pathname' +require "bundler" +require "bundler/setup" +require "pathname" -if ENV['COVERAGE'] - require 'coveralls' +if ENV["COVERAGE"] + require "coveralls" Coveralls.wear_merged! end # just in case -if RUBY_VERSION.to_i < 2 - raise 'brew-cask: Ruby 2.0 or greater is required.' -end +raise "brew-cask: Ruby 2.0 or greater is required." if RUBY_VERSION.to_i < 2 # add homebrew-cask lib to load path -brew_cask_path = Pathname.new(File.expand_path(__FILE__+'/../../')) -casks_path = brew_cask_path.join('Casks') -lib_path = brew_cask_path.join('lib') -$:.push(lib_path) +brew_cask_path = Pathname.new(File.expand_path(__FILE__ + "/../../")) +lib_path = brew_cask_path.join("lib") +$LOAD_PATH.push(lib_path) # TODO: removeme, this is transitional -require 'vendor/homebrew-fork/testing_env' +require "vendor/homebrew-fork/testing_env" # force some environment variables -ENV['HOMEBREW_NO_EMOJI'] = '1' -ENV['HOMEBREW_CASK_OPTS'] = nil +ENV["HOMEBREW_NO_EMOJI"] = "1" +ENV["HOMEBREW_CASK_OPTS"] = nil # TODO: temporary, copied from old Homebrew, this method is now moved inside a class def shutup - if ENV.has_key?('VERBOSE_TESTS') + if ENV.key?("VERBOSE_TESTS") yield else begin tmperr = $stderr.clone tmpout = $stdout.clone - $stderr.reopen '/dev/null', 'w' - $stdout.reopen '/dev/null', 'w' + $stderr.reopen "/dev/null", "w" + $stdout.reopen "/dev/null", "w" yield ensure $stderr.reopen tmperr @@ -49,45 +46,45 @@ end # making homebrew's cache dir allows us to actually download Casks in tests HOMEBREW_CACHE.mkpath -HOMEBREW_CACHE.join('Casks').mkpath +HOMEBREW_CACHE.join("Casks").mkpath # must be called after testing_env so at_exit hooks are in proper order -require 'minitest/autorun' -require 'minitest/reporters' +require "minitest/autorun" +require "minitest/reporters" Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true) # Force mocha to patch MiniTest since we have both loaded thanks to homebrew's testing_env -require 'mocha/api' -require 'mocha/integration/mini_test' +require "mocha/api" +require "mocha/integration/mini_test" Mocha::Integration::MiniTest.activate # our baby -require 'hbc' +require "hbc" # override Homebrew locations -Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join('prefix') +Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix") Hbc.homebrew_repository = Hbc.homebrew_prefix Hbc.homebrew_tapspath = nil # Look for Casks in testcasks by default. It is elsewhere required that # the string "test" appear in the directory name. -Hbc.default_tap = 'caskroom/homebrew-testcasks' +Hbc.default_tap = "caskroom/homebrew-testcasks" # our own testy caskroom -Hbc.caskroom = Hbc.homebrew_prefix.join('TestCaskroom') +Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom") class TestHelper # helpers for test Casks to reference local files easily def self.local_binary_path(name) - File.expand_path(File.join(File.dirname(__FILE__), 'support', 'binaries', name)) + File.expand_path(File.join(File.dirname(__FILE__), "support", "binaries", name)) end def self.local_binary_url(name) - 'file://' + local_binary_path(name) + "file://" + local_binary_path(name) end def self.test_cask - @test_cask ||= Hbc.load('basic-cask') + @test_cask ||= Hbc.load("basic-cask") end def self.fake_fetcher @@ -103,13 +100,12 @@ class TestHelper lambda.call end - case - when block_given? - yield (out+err).chomp - when expected.is_a?(Regexp) - (out+err).chomp.must_match expected + if block_given? + yield (out + err).chomp + elsif expected.is_a?(Regexp) + (out + err).chomp.must_match expected else - (out+err).chomp.must_equal expected.gsub(/^ */, '') + (out + err).chomp.must_equal expected.gsub(%r{^ *}, "") end end @@ -137,16 +133,16 @@ class TestHelper end # Extend MiniTest API with support for RSpec-style shared examples -require 'support/shared_examples' -require 'support/shared_examples/staged.rb' +require "support/shared_examples" +require "support/shared_examples/staged.rb" -require 'support/fake_fetcher' -require 'support/fake_dirs' -require 'support/fake_system_command' -require 'support/cleanup' -require 'support/never_sudo_system_command' -require 'tmpdir' -require 'tempfile' +require "support/fake_fetcher" +require "support/fake_dirs" +require "support/fake_system_command" +require "support/cleanup" +require "support/never_sudo_system_command" +require "tmpdir" +require "tempfile" # pretend like we installed the homebrew-cask tap project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) @@ -154,19 +150,17 @@ taps_dest = Hbc.homebrew_prefix.join(*%w[Library Taps caskroom]) # create directories FileUtils.mkdir_p taps_dest -FileUtils.mkdir_p Hbc.homebrew_prefix.join('bin') +FileUtils.mkdir_p Hbc.homebrew_prefix.join("bin") -FileUtils.ln_s project_root, taps_dest.join('homebrew-cask') +FileUtils.ln_s project_root, taps_dest.join("homebrew-cask") # Common superclass for test Casks for when we need to filter them out -module Hbc - class TestCask < Cask; end -end +class Hbc::TestCask < Hbc::Cask; end # jack in some optional utilities -FileUtils.ln_s '/usr/local/bin/cabextract', Hbc.homebrew_prefix.join('bin/cabextract') -FileUtils.ln_s '/usr/local/bin/unar', Hbc.homebrew_prefix.join('bin/unar') -FileUtils.ln_s '/usr/local/bin/lsar', Hbc.homebrew_prefix.join('bin/lsar') +FileUtils.ln_s "/usr/local/bin/cabextract", Hbc.homebrew_prefix.join("bin/cabextract") +FileUtils.ln_s "/usr/local/bin/unar", Hbc.homebrew_prefix.join("bin/unar") +FileUtils.ln_s "/usr/local/bin/lsar", Hbc.homebrew_prefix.join("bin/lsar") # also jack in some test Casks -FileUtils.ln_s project_root.join('test', 'support'), taps_dest.join('homebrew-testcasks') +FileUtils.ln_s project_root.join("test", "support"), taps_dest.join("homebrew-testcasks")