From a075b0a1bdb9d5785e69521d229649da895810da Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 23 Sep 2024 18:32:21 +0200 Subject: [PATCH] Update the code style across the project (#242) Eventually, we'll move to standard, but this is a nice improvement which makes working with Appraisal much more pleasant. This commit does the following: * use double quotes everywhere * use the new Ruby 1.9 hash syntax * use uppercase heredoc delimiters * add parentheses to nested method call * add missing frozen string literal comment * %w-literals should be delimited by [ and ] * space inside } is missing * fix indentation * avoid comma after the last parameter of a method call * remove unnecessary disabling of Layout/LineLength * remove unnecessary spacing * use hash literal {} instead of Hash.new * place the . on the next line, together with the method name * use 2 spaces for indentation in a heredoc by using <<~ instead of <<- * make sure that the block will be associated with the PARTS.map method call * use class << self instead of def self. to define class methods * add missing space --- Rakefile | 14 ++-- appraisal.gemspec | 22 ++--- exe/appraisal | 10 ++- lib/appraisal.rb | 6 +- lib/appraisal/appraisal.rb | 34 ++++---- lib/appraisal/appraisal_file.rb | 12 +-- lib/appraisal/bundler_dsl.rb | 23 ++--- lib/appraisal/cli.rb | 84 ++++++++++--------- lib/appraisal/command.rb | 4 +- lib/appraisal/conditional.rb | 2 + lib/appraisal/customize.rb | 4 +- lib/appraisal/dependency.rb | 6 +- lib/appraisal/dependency_list.rb | 6 +- lib/appraisal/errors.rb | 2 + lib/appraisal/gemfile.rb | 2 + lib/appraisal/gemspec.rb | 8 +- lib/appraisal/git.rb | 4 +- lib/appraisal/group.rb | 12 +-- lib/appraisal/path.rb | 4 +- lib/appraisal/platform.rb | 12 +-- lib/appraisal/source.rb | 12 +-- lib/appraisal/task.rb | 14 ++-- lib/appraisal/utils.rb | 13 ++- lib/appraisal/version.rb | 2 + ...als_file_bundler_dsl_compatibility_spec.rb | 46 +++++----- .../bundle_with_custom_path_spec.rb | 35 ++++---- spec/acceptance/bundle_without_spec.rb | 12 +-- spec/acceptance/cli/clean_spec.rb | 24 +++--- spec/acceptance/cli/generate_spec.rb | 26 +++--- spec/acceptance/cli/help_spec.rb | 28 ++++--- spec/acceptance/cli/install_spec.rb | 78 +++++++---------- spec/acceptance/cli/list_spec.rb | 20 +++-- spec/acceptance/cli/run_spec.rb | 50 +++++------ spec/acceptance/cli/update_spec.rb | 38 +++++---- spec/acceptance/cli/version_spec.rb | 2 + spec/acceptance/cli/with_no_arguments_spec.rb | 18 ++-- .../gemfile_dsl_compatibility_spec.rb | 62 +++++++------- spec/acceptance/gemspec_spec.rb | 50 +++++------ spec/appraisal/appraisal_file_spec.rb | 10 ++- spec/appraisal/appraisal_spec.rb | 41 +++++---- spec/appraisal/customize_spec.rb | 33 ++++---- spec/appraisal/dependency_list_spec.rb | 2 + spec/appraisal/gemfile_spec.rb | 75 +++++++++-------- spec/appraisal/utils_spec.rb | 47 +++++------ spec/spec_helper.rb | 12 +-- spec/support/acceptance_test_helpers.rb | 50 +++++------ spec/support/dependency_helpers.rb | 18 ++-- spec/support/stream_helpers.rb | 2 + 48 files changed, 575 insertions(+), 516 deletions(-) diff --git a/Rakefile b/Rakefile index 3925e1e8..f8d79dbc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,14 @@ -require 'bundler/setup' -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +# frozen_string_literal: true + +require "bundler/setup" +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new do |t| - t.pattern = 'spec/**/*_spec.rb' + t.pattern = "spec/**/*_spec.rb" t.ruby_opts = %w[-w] t.verbose = false end -desc 'Default: run the rspec examples' -task :default => [:spec] +desc "Default: run the rspec examples" +task default: [:spec] diff --git a/appraisal.gemspec b/appraisal.gemspec index 9bce0d83..d136a37f 100644 --- a/appraisal.gemspec +++ b/appraisal.gemspec @@ -3,24 +3,24 @@ require_relative "lib/appraisal/version" Gem::Specification.new do |s| - s.name = 'appraisal' + s.name = "appraisal" s.version = Appraisal::VERSION.dup s.platform = Gem::Platform::RUBY - s.authors = ['Joe Ferris', 'Prem Sichanugrist'] - s.email = ['jferris@thoughtbot.com', 'prem@thoughtbot.com'] - s.homepage = 'http://github.com/thoughtbot/appraisal' - s.summary = 'Find out what your Ruby gems are worth' + s.authors = ["Joe Ferris", "Prem Sichanugrist"] + s.email = ["jferris@thoughtbot.com", "prem@thoughtbot.com"] + s.homepage = "http://github.com/thoughtbot/appraisal" + s.summary = "Find out what your Ruby gems are worth" s.description = 'Appraisal integrates with bundler and rake to test your library against different versions of dependencies in repeatable scenarios called "appraisals."' - s.license = 'MIT' + s.license = "MIT" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) } - s.bindir = 'exe' + s.executables = `git ls-files -- exe/*`.split("\n").map { |f| File.basename(f) } + s.bindir = "exe" s.required_ruby_version = ">= 2.3.0" - s.add_dependency('rake') - s.add_dependency('bundler') - s.add_dependency('thor', '>= 0.14.0') + s.add_dependency("rake") + s.add_dependency("bundler") + s.add_dependency("thor", ">= 0.14.0") end diff --git a/exe/appraisal b/exe/appraisal index 95f478a4..4e963840 100755 --- a/exe/appraisal +++ b/exe/appraisal @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -require 'rubygems' -require 'bundler/setup' -require 'appraisal' -require 'appraisal/cli' +# frozen_string_literal: true + +require "rubygems" +require "bundler/setup" +require "appraisal" +require "appraisal/cli" begin Appraisal::CLI.start diff --git a/lib/appraisal.rb b/lib/appraisal.rb index 9b7be847..3f5c8aa5 100644 --- a/lib/appraisal.rb +++ b/lib/appraisal.rb @@ -1,4 +1,6 @@ -require 'appraisal/version' -require 'appraisal/task' +# frozen_string_literal: true + +require "appraisal/version" +require "appraisal/task" Appraisal::Task.new diff --git a/lib/appraisal/appraisal.rb b/lib/appraisal/appraisal.rb index 7d7634d0..86f2c3eb 100644 --- a/lib/appraisal/appraisal.rb +++ b/lib/appraisal/appraisal.rb @@ -1,9 +1,11 @@ -require 'appraisal/gemfile' -require 'appraisal/command' +# frozen_string_literal: true + +require "appraisal/gemfile" +require "appraisal/command" require "appraisal/customize" -require 'appraisal/utils' -require 'fileutils' -require 'pathname' +require "appraisal/utils" +require "fileutils" +require "pathname" module Appraisal # Represents one appraisal and its dependencies @@ -79,15 +81,15 @@ def install(options = {}) command = commands.join(" || ") if Bundler.settings[:path] - env = { 'BUNDLE_DISABLE_SHARED_GEMS' => '1' } - Command.new(command, :env => env).run + env = { "BUNDLE_DISABLE_SHARED_GEMS" => "1" } + Command.new(command, env: env).run else Command.new(command).run end end def update(gems = []) - Command.new(update_command(gems), :gemfile => gemfile_path).run + Command.new(update_command(gems), gemfile: gemfile_path).run end def gemfile_path @@ -107,10 +109,10 @@ def relativize relative_path = current_directory.relative_path_from(gemfile_root).cleanpath lockfile_content = File.read(lockfile_path) - File.open(lockfile_path, 'w') do |file| + File.open(lockfile_path, "w") do |file| file.write lockfile_content.gsub( / #{current_directory}/, - " #{relative_path}", + " #{relative_path}" ) end end @@ -119,16 +121,16 @@ def relativize def check_command gemfile_option = "--gemfile='#{gemfile_path}'" - ['bundle', 'check', gemfile_option] + ["bundle", "check", gemfile_option] end def install_command(options = {}) gemfile_option = "--gemfile='#{gemfile_path}'" - ['bundle', 'install', gemfile_option, bundle_options(options)].compact + ["bundle", "install", gemfile_option, bundle_options(options)].compact end def update_command(gems) - ['bundle', 'update', *gems].compact + ["bundle", "update", *gems].compact end def gemfile_root @@ -148,7 +150,7 @@ def lockfile_path end def clean_name - name.gsub(/[^\w\.]/, '_') + name.gsub(/[^\w\.]/, "_") end def bundle_options(options) @@ -159,8 +161,8 @@ def bundle_options(options) if Utils.support_parallel_installation? options_strings << "--jobs=#{jobs}" else - warn 'Your current version of Bundler does not support parallel installation. Please ' + - 'upgrade Bundler to version >= 1.4.0, or invoke `appraisal` without `--jobs` option.' + warn "Your current version of Bundler does not support parallel installation. Please " + + "upgrade Bundler to version >= 1.4.0, or invoke `appraisal` without `--jobs` option." end end diff --git a/lib/appraisal/appraisal_file.rb b/lib/appraisal/appraisal_file.rb index f5ade60d..2d182038 100644 --- a/lib/appraisal/appraisal_file.rb +++ b/lib/appraisal/appraisal_file.rb @@ -1,7 +1,9 @@ -require 'appraisal/appraisal' +# frozen_string_literal: true + +require "appraisal/appraisal" require "appraisal/customize" -require 'appraisal/errors' -require 'appraisal/gemfile' +require "appraisal/errors" +require "appraisal/gemfile" module Appraisal # Loads and parses Appraisals file @@ -15,7 +17,7 @@ def self.each(&block) def initialize @appraisals = [] @gemfile = Gemfile.new - @gemfile.load(ENV['BUNDLE_GEMFILE'] || 'Gemfile') + @gemfile.load(ENV["BUNDLE_GEMFILE"] || "Gemfile") if File.exist? path run IO.read(path) @@ -45,7 +47,7 @@ def run(definitions) end def path - 'Appraisals' + "Appraisals" end end end diff --git a/lib/appraisal/bundler_dsl.rb b/lib/appraisal/bundler_dsl.rb index ebe039f8..e102f4cd 100644 --- a/lib/appraisal/bundler_dsl.rb +++ b/lib/appraisal/bundler_dsl.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + require "appraisal/dependency_list" module Appraisal class BundlerDSL attr_reader :dependencies - PARTS = %w(source ruby_version gits paths dependencies groups - platforms source_blocks install_if gemspec) + PARTS = %w[source ruby_version gits paths dependencies groups + platforms source_blocks install_if gemspec] def initialize @sources = [] @ruby_version = nil @dependencies = DependencyList.new @gemspecs = [] - @groups = Hash.new - @platforms = Hash.new - @gits = Hash.new - @paths = Hash.new - @source_blocks = Hash.new + @groups = {} + @platforms = {} + @gits = {} + @paths = {} + @source_blocks = {} @git_sources = {} @install_if = {} end @@ -80,11 +82,11 @@ def path(source, options = {}, &block) end def to_s - Utils.join_parts PARTS.map { |part| send("#{part}_entry") } + Utils.join_parts(PARTS.map { |part| send("#{part}_entry") }) end def for_dup - Utils.join_parts PARTS.map { |part| send("#{part}_entry_for_dup") } + Utils.join_parts(PARTS.map { |part| send("#{part}_entry_for_dup") }) end def gemspec(options = {}) @@ -134,8 +136,7 @@ def dependencies_entry_for_dup @dependencies.for_dup end - %i[gits paths platforms groups source_blocks install_if]. - each do |method_name| + %i[gits paths platforms groups source_blocks install_if].each do |method_name| class_eval <<-METHODS, __FILE__, __LINE__ private diff --git a/lib/appraisal/cli.rb b/lib/appraisal/cli.rb index c6970a35..d92577ba 100644 --- a/lib/appraisal/cli.rb +++ b/lib/appraisal/cli.rb @@ -1,52 +1,56 @@ -require 'thor' -require 'fileutils' +# frozen_string_literal: true + +require "thor" +require "fileutils" module Appraisal class CLI < Thor default_task :install map ["-v", "--version"] => "version" - # Override help command to print out usage - def self.help(shell, subcommand = false) - shell.say strip_heredoc(<<-help) - Appraisal: Find out what your Ruby gems are worth. + class << self + # Override help command to print out usage + def help(shell, subcommand = false) + shell.say strip_heredoc(<<-HELP) + Appraisal: Find out what your Ruby gems are worth. - Usage: - appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND + Usage: + appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND - If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given - appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals. - help + If APPRAISAL_NAME is given, only run that EXTERNAL_COMMAND against the given + appraisal, otherwise it runs the EXTERNAL_COMMAND against all appraisals. + HELP - if File.exist?('Appraisals') - shell.say - shell.say 'Available Appraisal(s):' + if File.exist?("Appraisals") + shell.say + shell.say "Available Appraisal(s):" - AppraisalFile.each do |appraisal| - shell.say " - #{appraisal.name}" + AppraisalFile.each do |appraisal| + shell.say " - #{appraisal.name}" + end end - end - shell.say + shell.say - super - end + super + end - def self.exit_on_failure? - true + def exit_on_failure? + true + end end - desc 'install', 'Resolve and install dependencies for each appraisal' - method_option 'jobs', :aliases => 'j', :type => :numeric, :default => 1, - :banner => 'SIZE', - :desc => 'Install gems in parallel using the given number of workers.' - method_option 'retry', :type => :numeric, :default => 1, - :desc => 'Retry network and git requests that have failed' - method_option "without", :banner => "GROUP_NAMES", - :desc => "A space-separated list of groups referencing gems to skip " + + desc "install", "Resolve and install dependencies for each appraisal" + method_option "jobs", aliases: "j", type: :numeric, default: 1, + banner: "SIZE", + desc: "Install gems in parallel using the given number of workers." + method_option "retry", type: :numeric, default: 1, + desc: "Retry network and git requests that have failed" + method_option "without", banner: "GROUP_NAMES", + desc: "A space-separated list of groups referencing gems to skip " + "during installation. Bundler will remember this option." - method_option "full-index", :type => :boolean, - :desc => "Run bundle install with the " \ + method_option "full-index", type: :boolean, + desc: "Run bundle install with the " \ "full-index argument." method_option "path", type: :string, desc: "Install gems in the specified directory. " \ @@ -61,19 +65,19 @@ def install end end - desc 'generate', 'Generate a gemfile for each appraisal' + desc "generate", "Generate a gemfile for each appraisal" def generate AppraisalFile.each do |appraisal| appraisal.write_gemfile end end - desc 'clean', 'Remove all generated gemfiles and lockfiles from gemfiles folder' + desc "clean", "Remove all generated gemfiles and lockfiles from gemfiles folder" def clean - FileUtils.rm_f Dir['gemfiles/*.{gemfile,gemfile.lock}'] + FileUtils.rm_f Dir["gemfiles/*.{gemfile,gemfile.lock}"] end - desc 'update [LIST_OF_GEMS]', 'Remove all generated gemfiles and lockfiles, resolve, and install dependencies again' + desc "update [LIST_OF_GEMS]", "Remove all generated gemfiles and lockfiles, resolve, and install dependencies again" def update(*gems) invoke :generate, [] @@ -82,7 +86,7 @@ def update(*gems) end end - desc 'list', 'List the names of the defined appraisals' + desc "list", "List the names of the defined appraisals" def list AppraisalFile.new.appraisals.each { |appraisal| puts appraisal.name } end @@ -100,17 +104,17 @@ def method_missing(name, *args, &block) end if matching_appraisal - Command.new(args, :gemfile => matching_appraisal.gemfile_path).run + Command.new(args, gemfile: matching_appraisal.gemfile_path).run else AppraisalFile.each do |appraisal| - Command.new(ARGV, :gemfile => appraisal.gemfile_path).run + Command.new(ARGV, gemfile: appraisal.gemfile_path).run end end end def self.strip_heredoc(string) indent = string.scan(/^[ \t]*(?=\S)/).min.size || 0 - string.gsub(/^[ \t]{#{indent}}/, '') + string.gsub(/^[ \t]{#{indent}}/, "") end end end diff --git a/lib/appraisal/command.rb b/lib/appraisal/command.rb index 6de50162..facadfd9 100644 --- a/lib/appraisal/command.rb +++ b/lib/appraisal/command.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "shellwords" module Appraisal @@ -70,7 +72,7 @@ def command_starting_with_bundle(original_command) if command_starts_with_bundle?(original_command) original_command else - %w(bundle exec) + original_command + %w[bundle exec] + original_command end end diff --git a/lib/appraisal/conditional.rb b/lib/appraisal/conditional.rb index f0702c55..db15ff33 100644 --- a/lib/appraisal/conditional.rb +++ b/lib/appraisal/conditional.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" require "appraisal/utils" diff --git a/lib/appraisal/customize.rb b/lib/appraisal/customize.rb index 0de1a78e..20cb99ac 100644 --- a/lib/appraisal/customize.rb +++ b/lib/appraisal/customize.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Appraisal class Customize def initialize(heading: nil, single_quotes: false) @@ -25,7 +27,7 @@ def self.customize(heading, gemfile) lockfile: "#{gemfile.send('gemfile_name')}.lock", lockfile_path: gemfile.send("lockfile_path"), relative_gemfile_path: gemfile.relative_gemfile_path, - relative_lockfile_path: "#{gemfile.relative_gemfile_path}.lock", + relative_lockfile_path: "#{gemfile.relative_gemfile_path}.lock" ) end diff --git a/lib/appraisal/dependency.rb b/lib/appraisal/dependency.rb index 1d61d6a5..37302ab8 100644 --- a/lib/appraisal/dependency.rb +++ b/lib/appraisal/dependency.rb @@ -1,4 +1,6 @@ -require 'appraisal/utils' +# frozen_string_literal: true + +require "appraisal/utils" module Appraisal # Dependency on a gem and optional version requirements @@ -43,7 +45,7 @@ def formatted_output(output_requirements) end def gem_name - %{gem "#{name}"} + %(gem "#{name}") end def no_requirements? diff --git a/lib/appraisal/dependency_list.rb b/lib/appraisal/dependency_list.rb index cfdf36ea..9b6fb8d9 100644 --- a/lib/appraisal/dependency_list.rb +++ b/lib/appraisal/dependency_list.rb @@ -1,10 +1,12 @@ -require 'appraisal/dependency' +# frozen_string_literal: true + +require "appraisal/dependency" require "set" module Appraisal class DependencyList def initialize - @dependencies = Hash.new + @dependencies = {} @removed_dependencies = Set.new end diff --git a/lib/appraisal/errors.rb b/lib/appraisal/errors.rb index d4005a5c..3475aff6 100644 --- a/lib/appraisal/errors.rb +++ b/lib/appraisal/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Appraisal # Raises when Appraisal is unable to locate Appraisals file in the current directory. class AppraisalsNotFound < StandardError diff --git a/lib/appraisal/gemfile.rb b/lib/appraisal/gemfile.rb index 3fbe7572..bfbb4580 100644 --- a/lib/appraisal/gemfile.rb +++ b/lib/appraisal/gemfile.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" module Appraisal diff --git a/lib/appraisal/gemspec.rb b/lib/appraisal/gemspec.rb index be09ccea..8c4d6a0a 100644 --- a/lib/appraisal/gemspec.rb +++ b/lib/appraisal/gemspec.rb @@ -1,4 +1,6 @@ -require 'appraisal/utils' +# frozen_string_literal: true + +require "appraisal/utils" module Appraisal class Gemspec @@ -6,7 +8,7 @@ class Gemspec def initialize(options = {}) @options = options - @options[:path] ||= '.' + @options[:path] ||= "." end def to_s @@ -22,7 +24,7 @@ def for_dup def exported_options @options.merge( - :path => Utils.prefix_path(@options[:path]) + path: Utils.prefix_path(@options[:path]) ) end end diff --git a/lib/appraisal/git.rb b/lib/appraisal/git.rb index 3f4db2fe..5849cca1 100644 --- a/lib/appraisal/git.rb +++ b/lib/appraisal/git.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" -require 'appraisal/utils' +require "appraisal/utils" module Appraisal class Git < BundlerDSL diff --git a/lib/appraisal/group.rb b/lib/appraisal/group.rb index 4d68449a..2327298c 100644 --- a/lib/appraisal/group.rb +++ b/lib/appraisal/group.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" -require 'appraisal/utils' +require "appraisal/utils" module Appraisal class Group < BundlerDSL @@ -20,10 +22,10 @@ def for_dup private def formatted_output(output_dependencies) - <<-OUTPUT.strip -group #{Utils.format_arguments(@group_names)} do -#{output_dependencies} -end + <<~OUTPUT.strip + group #{Utils.format_arguments(@group_names)} do + #{output_dependencies} + end OUTPUT end end diff --git a/lib/appraisal/path.rb b/lib/appraisal/path.rb index 918f7e97..f06d2737 100644 --- a/lib/appraisal/path.rb +++ b/lib/appraisal/path.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" -require 'appraisal/utils' +require "appraisal/utils" module Appraisal class Path < BundlerDSL diff --git a/lib/appraisal/platform.rb b/lib/appraisal/platform.rb index 390d3fc0..ad98ce1f 100644 --- a/lib/appraisal/platform.rb +++ b/lib/appraisal/platform.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" -require 'appraisal/utils' +require "appraisal/utils" module Appraisal class Platform < BundlerDSL @@ -20,10 +22,10 @@ def for_dup private def formatted_output(output_dependencies) - <<-OUTPUT.strip -platforms #{Utils.format_arguments(@platform_names)} do -#{output_dependencies} -end + <<~OUTPUT.strip + platforms #{Utils.format_arguments(@platform_names)} do + #{output_dependencies} + end OUTPUT end end diff --git a/lib/appraisal/source.rb b/lib/appraisal/source.rb index ab74458c..c5905617 100644 --- a/lib/appraisal/source.rb +++ b/lib/appraisal/source.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "appraisal/bundler_dsl" require "appraisal/utils" @@ -20,11 +22,11 @@ def for_dup private def formatted_output(output_dependencies) - <<-OUTPUT.strip -source #{@source.inspect} do -#{output_dependencies} -end - OUTPUT + <<~OUTPUT.strip + source #{@source.inspect} do + #{output_dependencies} + end + OUTPUT end end end diff --git a/lib/appraisal/task.rb b/lib/appraisal/task.rb index d0629d37..5c649925 100644 --- a/lib/appraisal/task.rb +++ b/lib/appraisal/task.rb @@ -1,5 +1,7 @@ -require 'appraisal/appraisal_file' -require 'rake/tasklib' +# frozen_string_literal: true + +require "appraisal/appraisal_file" +require "rake/tasklib" module Appraisal # Defines tasks for installing appraisal dependencies and running other tasks @@ -11,21 +13,21 @@ def initialize task :gemfiles do warn "`rake appraisal:gemfile` task is deprecated and will be removed soon. " + "Please use `appraisal generate`." - exec 'bundle exec appraisal generate' + exec "bundle exec appraisal generate" end desc "DEPRECATED: Resolve and install dependencies for each appraisal" task :install do warn "`rake appraisal:install` task is deprecated and will be removed soon. " + "Please use `appraisal install`." - exec 'bundle exec appraisal install' + exec "bundle exec appraisal install" end desc "DEPRECATED: Remove all generated gemfiles from gemfiles/ folder" task :cleanup do warn "`rake appraisal:cleanup` task is deprecated and will be removed soon. " + "Please use `appraisal clean`." - exec 'bundle exec appraisal clean' + exec "bundle exec appraisal clean" end begin @@ -48,7 +50,7 @@ def initialize end desc "Run the given task for all appraisals" - task :appraisal => "appraisal:all" + task appraisal: "appraisal:all" end end end diff --git a/lib/appraisal/utils.rb b/lib/appraisal/utils.rb index fc5b1049..40e6c31e 100644 --- a/lib/appraisal/utils.rb +++ b/lib/appraisal/utils.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module Appraisal # Contains methods for various operations module Utils def self.support_parallel_installation? - Gem::Version.create(Bundler::VERSION) >= Gem::Version.create('1.4.0.pre.1') + Gem::Version.create(Bundler::VERSION) >= Gem::Version.create("1.4.0.pre.1") end def self.format_string(object, enclosing_object = false) @@ -15,7 +17,7 @@ def self.format_string(object, enclosing_object = false) if enclosing_object "{ #{items.join(', ')} }" else - items.join(', ') + items.join(", ") end else object.inspect @@ -35,7 +37,7 @@ def self.format_hash_value(key, value) def self.format_arguments(arguments) unless arguments.empty? - arguments.map { |object| format_string(object, false) }.join(', ') + arguments.map { |object| format_string(object, false) }.join(", ") end end @@ -53,10 +55,7 @@ def self.prefix_path(path) end def self.bundler_version - Gem::Specification. - detect { |spec| spec.name == "bundler" }. - version. - to_s + Gem::Specification.detect { |spec| spec.name == "bundler" }.version.to_s end end end diff --git a/lib/appraisal/version.rb b/lib/appraisal/version.rb index 5ed40d98..71f6c23e 100644 --- a/lib/appraisal/version.rb +++ b/lib/appraisal/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Appraisal VERSION = "2.5.0".freeze end diff --git a/spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb b/spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb index d5deaf94..41e6cdd6 100644 --- a/spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb +++ b/spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb @@ -1,12 +1,14 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'Appraisals file Bundler DSL compatibility' do - it 'supports all Bundler DSL in Appraisals file' do - build_gems %w(bagel orange_juice milk waffle coffee ham - sausage pancake rotten_egg mayonnaise) - build_git_gems %w(egg croissant pain_au_chocolat omelette) +require "spec_helper" - build_gemfile <<-Gemfile +RSpec.describe "Appraisals file Bundler DSL compatibility" do + it "supports all Bundler DSL in Appraisals file" do + build_gems %w[bagel orange_juice milk waffle coffee ham + sausage pancake rotten_egg mayonnaise] + build_git_gems %w[egg croissant pain_au_chocolat omelette] + + build_gemfile <<-GEMFILE source 'https://rubygems.org' git_source(:custom_git_source) { |repo| "../build/\#{repo}" } ruby RUBY_VERSION @@ -45,9 +47,9 @@ end gem 'appraisal', :path => #{PROJECT_ROOT.inspect} - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise 'breakfast' do source 'http://some-other-source.com' ruby "2.3.0" @@ -87,12 +89,12 @@ gemspec gemspec :path => "sitepress" end - Appraisals + APPRAISALS - run 'bundle install --local' - run 'appraisal generate' + run "bundle install --local" + run "appraisal generate" - expect(content_of 'gemfiles/breakfast.gemfile').to eq <<-Gemfile.strip_heredoc + expect(content_of("gemfiles/breakfast.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" @@ -147,28 +149,28 @@ gemspec :path => "../" gemspec :path => "../sitepress" - Gemfile + GEMFILE end it 'supports ruby file: ".ruby-version" DSL' do - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source 'https://rubygems.org' ruby RUBY_VERSION gem 'appraisal', :path => #{PROJECT_ROOT.inspect} - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise 'ruby-version' do ruby file: ".ruby-version" end - Appraisals + APPRAISALS - run 'bundle install --local' - run 'appraisal generate' + run "bundle install --local" + run "appraisal generate" - expect(content_of 'gemfiles/ruby_version.gemfile').to eq <<-Gemfile.strip_heredoc + expect(content_of("gemfiles/ruby_version.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" @@ -176,6 +178,6 @@ ruby({:file=>".ruby-version"}) gem "appraisal", :path => #{PROJECT_ROOT.inspect} - Gemfile + GEMFILE end end diff --git a/spec/acceptance/bundle_with_custom_path_spec.rb b/spec/acceptance/bundle_with_custom_path_spec.rb index 77cba434..b0d2157b 100644 --- a/spec/acceptance/bundle_with_custom_path_spec.rb +++ b/spec/acceptance/bundle_with_custom_path_spec.rb @@ -1,37 +1,38 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe "Bundle with custom path" do - let(:gem_name) { 'rack' } - let(:path) { 'vendor/bundle' } + let(:gem_name) { "rack" } + let(:path) { "vendor/bundle" } shared_examples :gemfile_dependencies_are_satisfied do - - it 'installs gems in the --path directory' do - build_gemfile <<-Gemfile + it "installs gems in the --path directory" do + build_gemfile <<-GEMFILE source "https://rubygems.org" gem 'appraisal', :path => #{PROJECT_ROOT.inspect} - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise "#{gem_name}" do gem '#{gem_name}' end - Appraisals + APPRAISALS run "bundle config set --local path #{path}" run "bundle install" - run 'bundle exec appraisal install' + run "bundle exec appraisal install" - installed_gem = Dir.glob("tmp/stage/#{path}/#{Gem.ruby_engine}/*/gems/*"). - map { |path| path.split('/').last }. - select { |gem| gem.include?(gem_name) } + installed_gem = Dir.glob("tmp/stage/#{path}/#{Gem.ruby_engine}/*/gems/*") + .map { |path| path.split("/").last } + .select { |gem| gem.include?(gem_name) } expect(installed_gem).not_to be_empty - bundle_output = run 'bundle check' + bundle_output = run "bundle check" expect(bundle_output).to include("The Gemfile's dependencies are satisfied") - appraisal_output = run 'bundle exec appraisal install' + appraisal_output = run "bundle exec appraisal install" expect(appraisal_output).to include("The Gemfile's dependencies are satisfied") run "bundle config unset --local path" @@ -40,13 +41,13 @@ include_examples :gemfile_dependencies_are_satisfied - context 'when already installed in vendor/another' do + context "when already installed in vendor/another" do before do - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source "https://rubygems.org" gem '#{gem_name}' - Gemfile + GEMFILE run "bundle config set --local path vendor/another" run "bundle install" diff --git a/spec/acceptance/bundle_without_spec.rb b/spec/acceptance/bundle_without_spec.rb index 484c804f..7eb1b71f 100644 --- a/spec/acceptance/bundle_without_spec.rb +++ b/spec/acceptance/bundle_without_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe "Bundler without flag" do it "passes --without flag to Bundler on install" do - build_gems %w(pancake orange_juice waffle coffee sausage soda) + build_gems %w[pancake orange_juice waffle coffee sausage soda] - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source "https://rubygems.org" gem "pancake" @@ -15,9 +17,9 @@ end gem "appraisal", :path => #{PROJECT_ROOT.inspect} - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise "breakfast" do gem "waffle" @@ -33,7 +35,7 @@ gem "soda" end end - Appraisals + APPRAISALS run "bundle install --local" run "bundle config set --local without 'drinks'" diff --git a/spec/acceptance/cli/clean_spec.rb b/spec/acceptance/cli/clean_spec.rb index a8e19bfc..7eed158c 100644 --- a/spec/acceptance/cli/clean_spec.rb +++ b/spec/acceptance/cli/clean_spec.rb @@ -1,20 +1,22 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal clean' do - it 'remove all gemfiles from gemfiles directory' do - build_appraisal_file <<-Appraisal +require "spec_helper" + +RSpec.describe "CLI", "appraisal clean" do + it "remove all gemfiles from gemfiles directory" do + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL - run 'appraisal install' - write_file 'gemfiles/non_related_file', '' + run "appraisal install" + write_file "gemfiles/non_related_file", "" - run 'appraisal clean' + run "appraisal clean" - expect(file 'gemfiles/1.0.0.gemfile').not_to be_exists - expect(file 'gemfiles/1.0.0.gemfile.lock').not_to be_exists - expect(file 'gemfiles/non_related_file').to be_exists + expect(file("gemfiles/1.0.0.gemfile")).not_to be_exists + expect(file("gemfiles/1.0.0.gemfile.lock")).not_to be_exists + expect(file("gemfiles/non_related_file")).to be_exists end end diff --git a/spec/acceptance/cli/generate_spec.rb b/spec/acceptance/cli/generate_spec.rb index af5f65ea..285fc215 100644 --- a/spec/acceptance/cli/generate_spec.rb +++ b/spec/acceptance/cli/generate_spec.rb @@ -1,14 +1,16 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal generate' do - it 'generates the gemfiles' do - build_gemfile <<-Gemfile +require "spec_helper" + +RSpec.describe "CLI", "appraisal generate" do + it "generates the gemfiles" do + build_gemfile <<-GEMFILE source "https://rubygems.org" gem "appraisal", :path => "#{PROJECT_ROOT}" - Gemfile + GEMFILE - build_appraisal_file <<-Appraisal + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end @@ -16,19 +18,19 @@ appraise '1.1.0' do gem 'dummy', '1.1.0' end - Appraisal + APPRAISAL - run 'appraisal generate' + run "appraisal generate" - expect(file 'gemfiles/1.0.0.gemfile').to be_exists - expect(file 'gemfiles/1.1.0.gemfile').to be_exists - expect(content_of 'gemfiles/1.0.0.gemfile').to eq <<-gemfile.strip_heredoc + expect(file("gemfiles/1.0.0.gemfile")).to be_exists + expect(file("gemfiles/1.1.0.gemfile")).to be_exists + expect(content_of("gemfiles/1.0.0.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", :path => "#{PROJECT_ROOT}" gem "dummy", "1.0.0" - gemfile + GEMFILE end end diff --git a/spec/acceptance/cli/help_spec.rb b/spec/acceptance/cli/help_spec.rb index 56a8dded..da99f7a3 100644 --- a/spec/acceptance/cli/help_spec.rb +++ b/spec/acceptance/cli/help_spec.rb @@ -1,24 +1,26 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal help' do - it 'prints usage along with commands, and list of appraisals' do - build_appraisal_file <<-Appraisal +require "spec_helper" + +RSpec.describe "CLI", "appraisal help" do + it "prints usage along with commands, and list of appraisals" do + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL - output = run 'appraisal help' + output = run "appraisal help" - expect(output).to include 'Usage:' - expect(output).to include 'appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND' - expect(output).to include '1.0.0' + expect(output).to include "Usage:" + expect(output).to include "appraisal [APPRAISAL_NAME] EXTERNAL_COMMAND" + expect(output).to include "1.0.0" end - it 'prints out usage even Appraisals file does not exist' do - output = run 'appraisal help' + it "prints out usage even Appraisals file does not exist" do + output = run "appraisal help" - expect(output).to include 'Usage:' - expect(output).not_to include 'Unable to locate' + expect(output).to include "Usage:" + expect(output).not_to include "Unable to locate" end end diff --git a/spec/acceptance/cli/install_spec.rb b/spec/acceptance/cli/install_spec.rb index 00d910df..09dcc106 100644 --- a/spec/acceptance/cli/install_spec.rb +++ b/spec/acceptance/cli/install_spec.rb @@ -1,14 +1,16 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal install' do - it 'raises error when there is no Appraisals file' do - output = run 'appraisal install 2>&1', false +require "spec_helper" + +RSpec.describe "CLI", "appraisal install" do + it "raises error when there is no Appraisals file" do + output = run "appraisal install 2>&1", false expect(output).to include "Unable to locate 'Appraisals' file" end - it 'installs the dependencies' do - build_appraisal_file <<-Appraisal + it "installs the dependencies" do + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end @@ -16,28 +18,27 @@ appraise '1.1.0' do gem 'dummy', '1.1.0' end - Appraisal + APPRAISAL - run 'appraisal install' + run "appraisal install" - expect(file 'gemfiles/1.0.0.gemfile.lock').to be_exists - expect(file 'gemfiles/1.1.0.gemfile.lock').to be_exists + expect(file("gemfiles/1.0.0.gemfile.lock")).to be_exists + expect(file("gemfiles/1.1.0.gemfile.lock")).to be_exists end - it 'relativize directory in gemfile.lock' do + it "relativize directory in gemfile.lock" do build_gemspec add_gemspec_to_gemfile - build_appraisal_file <<-Appraisal + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL - run 'appraisal install' + run "appraisal install" - expect(content_of("gemfiles/1.0.0.gemfile.lock")). - not_to include(current_directory) + expect(content_of("gemfiles/1.0.0.gemfile.lock")).not_to include(current_directory) end it "does not relativize directory of uris in gemfile.lock" do @@ -56,39 +57,30 @@ run "appraisal install" - expect(content_of("gemfiles/1.0.0.gemfile.lock")). - to include("file://#{uri_dummy_path}") + expect(content_of("gemfiles/1.0.0.gemfile.lock")).to include("file://#{uri_dummy_path}") end - context 'with job size', :parallel => true do + context "with job size", parallel: true do before do - build_appraisal_file <<-Appraisal + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL end - it 'accepts --jobs option to set job size' do - output = run 'appraisal install --jobs=2' + it "accepts --jobs option to set job size" do + output = run "appraisal install --jobs=2" - expect(output).to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=2" - ) + expect(output).to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=2") end - it 'ignores --jobs option if the job size is less than or equal to 1' do - output = run 'appraisal install --jobs=0' - - expect(output).to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}'" - ) - expect(output).not_to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=0" - ) - expect(output).not_to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=1" - ) + it "ignores --jobs option if the job size is less than or equal to 1" do + output = run "appraisal install --jobs=0" + + expect(output).to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}'") + expect(output).not_to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=0") + expect(output).not_to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --jobs=1") end end @@ -104,10 +96,7 @@ it "accepts --full-index option to pull the full RubyGems index" do output = run("appraisal install --full-index") - expect(output).to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' " \ - "--retry 1 --full-index true" - ) + expect(output).to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --retry 1 --full-index true") end end @@ -123,10 +112,7 @@ it "accepts --path option to specify the location to install gems into" do output = run("appraisal install --path vendor/appraisal") - expect(output).to include( - "bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' " \ - "--path #{file('vendor/appraisal')} --retry 1", - ) + expect(output).to include("bundle install --gemfile='#{file('gemfiles/1.0.0.gemfile')}' --path #{file('vendor/appraisal')} --retry 1") end end end diff --git a/spec/acceptance/cli/list_spec.rb b/spec/acceptance/cli/list_spec.rb index 4374db4b..917712ee 100644 --- a/spec/acceptance/cli/list_spec.rb +++ b/spec/acceptance/cli/list_spec.rb @@ -1,8 +1,10 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal list' do - it 'prints list of appraisals' do - build_appraisal_file <<-Appraisal +require "spec_helper" + +RSpec.describe "CLI", "appraisal list" do + it "prints list of appraisals" do + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end @@ -12,16 +14,16 @@ appraise '1.1.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL - output = run 'appraisal list' + output = run "appraisal list" expect(output).to eq("1.0.0\n2.0.0\n1.1.0\n") end - it 'prints nothing if there are no appraisals in the file' do - build_appraisal_file '' - output = run 'appraisal list' + it "prints nothing if there are no appraisals in the file" do + build_appraisal_file "" + output = run "appraisal list" expect(output.length).to eq(0) end diff --git a/spec/acceptance/cli/run_spec.rb b/spec/acceptance/cli/run_spec.rb index 91f01f4f..6bfcfd8c 100644 --- a/spec/acceptance/cli/run_spec.rb +++ b/spec/acceptance/cli/run_spec.rb @@ -1,8 +1,10 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI appraisal (with arguments)' do +require "spec_helper" + +RSpec.describe "CLI appraisal (with arguments)" do before do - build_appraisal_file <<-Appraisal + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end @@ -10,47 +12,47 @@ appraise '1.1.0' do gem 'dummy', '1.1.0' end - Appraisal + APPRAISAL - run 'appraisal install' - write_file 'test.rb', 'puts "Running: #{$dummy_version}"' - write_file 'test with spaces.rb', 'puts "Running: #{$dummy_version}"' + run "appraisal install" + write_file "test.rb", 'puts "Running: #{$dummy_version}"' + write_file "test with spaces.rb", 'puts "Running: #{$dummy_version}"' end - it 'sets APPRAISAL_INITIALIZED environment variable' do - write_file 'test.rb', <<-TEST_FILE.strip_heredoc + it "sets APPRAISAL_INITIALIZED environment variable" do + write_file "test.rb", <<-TEST_FILE.strip_heredoc if ENV['APPRAISAL_INITIALIZED'] puts "Appraisal initialized!" end TEST_FILE - output = run 'appraisal 1.0.0 ruby -rbundler/setup -rdummy test.rb' - expect(output).to include 'Appraisal initialized!' + output = run "appraisal 1.0.0 ruby -rbundler/setup -rdummy test.rb" + expect(output).to include "Appraisal initialized!" end - context 'with appraisal name' do - it 'runs the given command against a correct versions of dependency' do - output = run 'appraisal 1.0.0 ruby -rbundler/setup -rdummy test.rb' + context "with appraisal name" do + it "runs the given command against a correct versions of dependency" do + output = run "appraisal 1.0.0 ruby -rbundler/setup -rdummy test.rb" - expect(output).to include 'Running: 1.0.0' - expect(output).not_to include 'Running: 1.1.0' + expect(output).to include "Running: 1.0.0" + expect(output).not_to include "Running: 1.1.0" end end - context 'without appraisal name' do - it 'runs the given command against all versions of dependency' do - output = run 'appraisal ruby -rbundler/setup -rdummy test.rb' + context "without appraisal name" do + it "runs the given command against all versions of dependency" do + output = run "appraisal ruby -rbundler/setup -rdummy test.rb" - expect(output).to include 'Running: 1.0.0' - expect(output).to include 'Running: 1.1.0' + expect(output).to include "Running: 1.0.0" + expect(output).to include "Running: 1.1.0" end end - context 'when one of the arguments contains spaces' do - it 'preserves those spaces' do + context "when one of the arguments contains spaces" do + it "preserves those spaces" do command = 'appraisal 1.0.0 ruby -rbundler/setup -rdummy "test with spaces.rb"' output = run(command) - expect(output).to include 'Running: 1.0.0' + expect(output).to include "Running: 1.0.0" end end end diff --git a/spec/acceptance/cli/update_spec.rb b/spec/acceptance/cli/update_spec.rb index 262a1451..8929c89c 100644 --- a/spec/acceptance/cli/update_spec.rb +++ b/spec/acceptance/cli/update_spec.rb @@ -1,19 +1,21 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI', 'appraisal update' do +require "spec_helper" + +RSpec.describe "CLI", "appraisal update" do before do - build_gem 'dummy2', '1.0.0' + build_gem "dummy2", "1.0.0" - build_appraisal_file <<-Appraisal + build_appraisal_file <<-APPRAISAL appraise 'dummy' do gem 'dummy', '~> 1.0.0' gem 'dummy2', '~> 1.0.0' end - Appraisal + APPRAISAL - run 'appraisal install' - build_gem 'dummy', '1.0.1' - build_gem 'dummy2', '1.0.1' + run "appraisal install" + build_gem "dummy", "1.0.1" + build_gem "dummy2", "1.0.1" end after do @@ -23,22 +25,22 @@ end end - context 'with no arguments' do - it 'updates all the gems' do - output = run 'appraisal update' + context "with no arguments" do + it "updates all the gems" do + output = run "appraisal update" expect(output).to include("gemfiles/dummy.gemfile bundle update") - expect(content_of 'gemfiles/dummy.gemfile.lock').to include 'dummy (1.0.1)' - expect(content_of 'gemfiles/dummy.gemfile.lock').to include 'dummy2 (1.0.1)' + expect(content_of("gemfiles/dummy.gemfile.lock")).to include "dummy (1.0.1)" + expect(content_of("gemfiles/dummy.gemfile.lock")).to include "dummy2 (1.0.1)" end end - context 'with a list of gems' do - it 'only updates specified gems' do - run 'appraisal update dummy' + context "with a list of gems" do + it "only updates specified gems" do + run "appraisal update dummy" - expect(content_of 'gemfiles/dummy.gemfile.lock').to include 'dummy (1.0.1)' - expect(content_of 'gemfiles/dummy.gemfile.lock').to include 'dummy2 (1.0.0)' + expect(content_of("gemfiles/dummy.gemfile.lock")).to include "dummy (1.0.1)" + expect(content_of("gemfiles/dummy.gemfile.lock")).to include "dummy2 (1.0.0)" end end end diff --git a/spec/acceptance/cli/version_spec.rb b/spec/acceptance/cli/version_spec.rb index 5840a0d1..e47a6548 100644 --- a/spec/acceptance/cli/version_spec.rb +++ b/spec/acceptance/cli/version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe "CLI", "appraisal version" do diff --git a/spec/acceptance/cli/with_no_arguments_spec.rb b/spec/acceptance/cli/with_no_arguments_spec.rb index 82626cb5..4a04e64a 100644 --- a/spec/acceptance/cli/with_no_arguments_spec.rb +++ b/spec/acceptance/cli/with_no_arguments_spec.rb @@ -1,16 +1,18 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'CLI appraisal (with no arguments)' do - it 'runs install command' do - build_appraisal_file <<-Appraisal +require "spec_helper" + +RSpec.describe "CLI appraisal (with no arguments)" do + it "runs install command" do + build_appraisal_file <<-APPRAISAL appraise '1.0.0' do gem 'dummy', '1.0.0' end - Appraisal + APPRAISAL - run 'appraisal' + run "appraisal" - expect(file 'gemfiles/1.0.0.gemfile').to be_exists - expect(file 'gemfiles/1.0.0.gemfile.lock').to be_exists + expect(file("gemfiles/1.0.0.gemfile")).to be_exists + expect(file("gemfiles/1.0.0.gemfile.lock")).to be_exists end end diff --git a/spec/acceptance/gemfile_dsl_compatibility_spec.rb b/spec/acceptance/gemfile_dsl_compatibility_spec.rb index 7a6baa64..2a9dcac3 100644 --- a/spec/acceptance/gemfile_dsl_compatibility_spec.rb +++ b/spec/acceptance/gemfile_dsl_compatibility_spec.rb @@ -1,12 +1,14 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'Gemfile DSL compatibility' do - it 'supports all Bundler DSL in Gemfile' do - build_gems %w(bacon orange_juice waffle) - build_git_gem 'egg' +require "spec_helper" + +RSpec.describe "Gemfile DSL compatibility" do + it "supports all Bundler DSL in Gemfile" do + build_gems %w[bacon orange_juice waffle] + build_git_gem "egg" build_gemspec - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source "https://rubygems.org" ruby RUBY_VERSION @@ -29,9 +31,9 @@ gem 'appraisal', :path => #{PROJECT_ROOT.inspect} gemspec - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise "japanese" do gem "rice" gem "miso_soup" @@ -40,12 +42,12 @@ appraise "english" do gem "bread" end - Appraisals + APPRAISALS - run 'bundle install --local' - run 'appraisal generate' + run "bundle install --local" + run "appraisal generate" - expect(content_of 'gemfiles/japanese.gemfile').to eq <<-Gemfile.strip_heredoc + expect(content_of("gemfiles/japanese.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" @@ -73,9 +75,9 @@ end gemspec :path => "../" - Gemfile + GEMFILE - expect(content_of 'gemfiles/english.gemfile').to eq <<-Gemfile.strip_heredoc + expect(content_of("gemfiles/english.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" @@ -102,7 +104,7 @@ end gemspec :path => "../" - Gemfile + GEMFILE end it "merges gem requirements" do @@ -110,14 +112,14 @@ build_gem "bacon", "1.1.0" build_gem "bacon", "1.2.0" - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source "https://rubygems.org" gem "appraisal", :path => #{PROJECT_ROOT.inspect} gem "bacon", "1.2.0" - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise "1.0.0" do gem "bacon", "1.0.0" end @@ -129,21 +131,21 @@ appraise "1.2.0" do gem "bacon", "1.2.0" end - Appraisals + APPRAISALS - run 'bundle install --local' - run 'appraisal generate' + run "bundle install --local" + run "appraisal generate" - expect(content_of "gemfiles/1.0.0.gemfile").to include('gem "bacon", "1.0.0"') - expect(content_of "gemfiles/1.1.0.gemfile").to include('gem "bacon", "1.1.0"') - expect(content_of "gemfiles/1.2.0.gemfile").to include('gem "bacon", "1.2.0"') + expect(content_of("gemfiles/1.0.0.gemfile")).to include('gem "bacon", "1.0.0"') + expect(content_of("gemfiles/1.1.0.gemfile")).to include('gem "bacon", "1.1.0"') + expect(content_of("gemfiles/1.2.0.gemfile")).to include('gem "bacon", "1.2.0"') end it "supports gemspec in the group block" do build_gem "bacon", "1.0.0" build_gemspec - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source "https://rubygems.org" gem "appraisal", :path => #{PROJECT_ROOT.inspect} @@ -151,18 +153,18 @@ group :plugin do gemspec end - Gemfile + GEMFILE - build_appraisal_file <<-Appraisals + build_appraisal_file <<-APPRAISALS appraise "1.0.0" do gem "bacon", "1.0.0" end - Appraisals + APPRAISALS run "bundle install --local" run "appraisal generate" - expect(content_of "gemfiles/1.0.0.gemfile").to eq <<-gemfile.strip_heredoc + expect(content_of("gemfiles/1.0.0.gemfile")).to eq <<-GEMFILE.strip_heredoc # This file was generated by Appraisal source "https://rubygems.org" @@ -173,6 +175,6 @@ group :plugin do gemspec :path => "../" end - gemfile + GEMFILE end end diff --git a/spec/acceptance/gemspec_spec.rb b/spec/acceptance/gemspec_spec.rb index eed13b24..d85fdf08 100644 --- a/spec/acceptance/gemspec_spec.rb +++ b/spec/acceptance/gemspec_spec.rb @@ -1,57 +1,59 @@ -require 'spec_helper' +# frozen_string_literal: true -RSpec.describe 'Gemspec' do +require "spec_helper" + +RSpec.describe "Gemspec" do before do build_appraisal_file build_rakefile end - it 'supports gemspec syntax with default options' do + it "supports gemspec syntax with default options" do build_gemspec - write_file 'Gemfile', <<-Gemfile + write_file "Gemfile", <<-GEMFILE source "https://rubygems.org" gem 'appraisal', :path => #{PROJECT_ROOT.inspect} gemspec - Gemfile + GEMFILE - run 'bundle install --local' - run 'appraisal install' - output = run 'appraisal rake version' + run "bundle install --local" + run "appraisal install" + output = run "appraisal rake version" - expect(output).to include 'Loaded 1.1.0' + expect(output).to include "Loaded 1.1.0" end - it 'supports gemspec syntax with path option' do - build_gemspec 'specdir' + it "supports gemspec syntax with path option" do + build_gemspec "specdir" - write_file 'Gemfile', <<-Gemfile + write_file "Gemfile", <<-GEMFILE source "https://rubygems.org" gem 'appraisal', :path => #{PROJECT_ROOT.inspect} gemspec :path => './specdir' - Gemfile + GEMFILE - run 'bundle install --local' - run 'appraisal install' - output = run 'appraisal rake version' + run "bundle install --local" + run "appraisal install" + output = run "appraisal rake version" - expect(output).to include 'Loaded 1.1.0' + expect(output).to include "Loaded 1.1.0" end def build_appraisal_file - super <<-Appraisals + super <<-APPRAISALS appraise 'stock' do gem 'rake' end - Appraisals + APPRAISALS end def build_rakefile - write_file 'Rakefile', <<-rakefile + write_file "Rakefile", <<-RAKEFILE require 'rubygems' require 'bundler/setup' require 'appraisal' @@ -60,13 +62,13 @@ def build_rakefile require 'dummy' puts "Loaded \#{$dummy_version}" end - rakefile + RAKEFILE end - def build_gemspec(path = '.') + def build_gemspec(path = ".") Dir.mkdir("tmp/stage/#{path}") rescue nil - write_file File.join(path, 'gemspec_project.gemspec'), <<-gemspec + write_file File.join(path, "gemspec_project.gemspec"), <<-GEMSPEC Gem::Specification.new do |s| s.name = 'gemspec_project' s.version = '0.1' @@ -75,6 +77,6 @@ def build_gemspec(path = '.') s.add_development_dependency('dummy', '1.1.0') end - gemspec + GEMSPEC end end diff --git a/spec/appraisal/appraisal_file_spec.rb b/spec/appraisal/appraisal_file_spec.rb index 878526e8..8b583ea8 100644 --- a/spec/appraisal/appraisal_file_spec.rb +++ b/spec/appraisal/appraisal_file_spec.rb @@ -1,10 +1,12 @@ -require 'spec_helper' -require 'appraisal/appraisal_file' +# frozen_string_literal: true + +require "spec_helper" +require "appraisal/appraisal_file" # Requiring this to make the test pass on Rubinius 2.2.5 # https://github.com/rubinius/rubinius/issues/2934 -require 'rspec/matchers/composable' -require 'rspec/matchers/built_in/raise_error' +require "rspec/matchers/composable" +require "rspec/matchers/built_in/raise_error" RSpec.describe Appraisal::AppraisalFile do it "complains when no Appraisals file is found" do diff --git a/spec/appraisal/appraisal_spec.rb b/spec/appraisal/appraisal_spec.rb index b4f04298..d68bfd57 100644 --- a/spec/appraisal/appraisal_spec.rb +++ b/spec/appraisal/appraisal_spec.rb @@ -1,6 +1,8 @@ -require 'spec_helper' -require 'appraisal/appraisal' -require 'tempfile' +# frozen_string_literal: true + +require "spec_helper" +require "appraisal/appraisal" +require "tempfile" RSpec.describe Appraisal::Appraisal do it "converts spaces to underscores in the gemfile path" do @@ -85,50 +87,45 @@ end end - context 'parallel installation' do + context "parallel installation" do include StreamHelpers before do - @appraisal = Appraisal::Appraisal.new('fake', 'fake') + @appraisal = Appraisal::Appraisal.new("fake", "fake") allow(@appraisal).to receive(:gemfile_path).and_return("/home/test/test directory") - allow(@appraisal).to receive(:project_root). - and_return(Pathname.new("/home/test")) - allow(Appraisal::Command).to receive(:new).and_return(double(:run => true)) + allow(@appraisal).to receive(:project_root).and_return(Pathname.new("/home/test")) + allow(Appraisal::Command).to receive(:new).and_return(double(run: true)) end - it 'runs single install command on Bundler < 1.4.0' do - stub_const('Bundler::VERSION', '1.3.0') + it "runs single install command on Bundler < 1.4.0" do + stub_const("Bundler::VERSION", "1.3.0") warning = capture(:stderr) do @appraisal.install("jobs" => 42) end - expect(Appraisal::Command).to have_received(:new). - with("#{bundle_check_command} || #{bundle_single_install_command}") - expect(warning).to include 'Please upgrade Bundler' + expect(Appraisal::Command).to have_received(:new).with("#{bundle_check_command} || #{bundle_single_install_command}") + expect(warning).to include "Please upgrade Bundler" end - it 'runs parallel install command on Bundler >= 1.4.0' do - stub_const('Bundler::VERSION', '1.4.0') + it "runs parallel install command on Bundler >= 1.4.0" do + stub_const("Bundler::VERSION", "1.4.0") @appraisal.install("jobs" => 42) - expect(Appraisal::Command).to have_received(:new). - with("#{bundle_check_command} || #{bundle_parallel_install_command}") + expect(Appraisal::Command).to have_received(:new).with("#{bundle_check_command} || #{bundle_parallel_install_command}") end - it 'runs install command with retries on Bundler' do + it "runs install command with retries on Bundler" do @appraisal.install("retry" => 3) - expect(Appraisal::Command).to have_received(:new). - with("#{bundle_check_command} || #{bundle_install_command_with_retries}") + expect(Appraisal::Command).to have_received(:new).with("#{bundle_check_command} || #{bundle_install_command_with_retries}") end it "runs install command with path on Bundler" do @appraisal.install("path" => "vendor/appraisal") - expect(Appraisal::Command).to have_received(:new). - with("#{bundle_check_command} || #{bundle_install_command_with_path}") + expect(Appraisal::Command).to have_received(:new).with("#{bundle_check_command} || #{bundle_install_command_with_path}") end def bundle_check_command diff --git a/spec/appraisal/customize_spec.rb b/spec/appraisal/customize_spec.rb index 8486a7e8..98e77f36 100644 --- a/spec/appraisal/customize_spec.rb +++ b/spec/appraisal/customize_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "appraisal/appraisal" require "appraisal/customize" @@ -62,8 +64,7 @@ allow(appraisal).to receive(:gemfile_name).and_return(gemfile) allow(appraisal).to receive(:gemfile_path).and_return(gemfile_full_path) allow(appraisal).to receive(:lockfile_path).and_return(lockfile_full_path) - allow(appraisal).to receive(:relative_gemfile_path). - and_return(gemfile_relative_path) + allow(appraisal).to receive(:relative_gemfile_path).and_return(gemfile_relative_path) end it "returns nil if no heading is set" do @@ -76,15 +77,15 @@ expect(described_class.send( :customize, single_line_heading, - appraisal, + appraisal )).to eq(single_line_heading) end it "returns the heading with the appraisal name" do expect(described_class.send( :customize, - "Appraisal: %{appraisal}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Appraisal: %{appraisal}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Appraisal: #{appraisal_name}") end @@ -92,47 +93,47 @@ expect(described_class.send( :customize, "Gemfile: %{gemfile}", # rubocop:disable Style/FormatStringToken - appraisal, + appraisal )).to eq("Gemfile: #{gemfile}") end it "returns the heading with the gemfile path" do expect(described_class.send( :customize, - "Gemfile: %{gemfile_path}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Gemfile: %{gemfile_path}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Gemfile: #{gemfile_full_path}") end it "returns the heading with the lockfile name" do expect(described_class.send( :customize, - "Lockfile: %{lockfile}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Lockfile: %{lockfile}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Lockfile: #{lockfile}") end it "returns the heading with the lockfile path" do expect(described_class.send( :customize, - "Lockfile: %{lockfile_path}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Lockfile: %{lockfile_path}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Lockfile: #{lockfile_full_path}") end it "returns the heading with the relative gemfile path" do expect(described_class.send( :customize, - "Gemfile: %{relative_gemfile_path}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Gemfile: %{relative_gemfile_path}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Gemfile: #{gemfile_relative_path}") end it "returns the heading with the relative lockfile path" do expect(described_class.send( :customize, - "Gemfile: %{relative_lockfile_path}", # rubocop:disable Style/FormatStringToken, Metrics/LineLength - appraisal, + "Gemfile: %{relative_lockfile_path}", # rubocop:disable Style/FormatStringToken + appraisal )).to eq("Gemfile: #{lockfile_relative_path}") end end diff --git a/spec/appraisal/dependency_list_spec.rb b/spec/appraisal/dependency_list_spec.rb index ec80a1db..8b322984 100644 --- a/spec/appraisal/dependency_list_spec.rb +++ b/spec/appraisal/dependency_list_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "appraisal/dependency_list" diff --git a/spec/appraisal/gemfile_spec.rb b/spec/appraisal/gemfile_spec.rb index 2785536c..666c07ba 100644 --- a/spec/appraisal/gemfile_spec.rb +++ b/spec/appraisal/gemfile_spec.rb @@ -1,27 +1,29 @@ -require 'spec_helper' -require 'appraisal/gemfile' -require 'active_support/core_ext/string/strip' +# frozen_string_literal: true + +require "spec_helper" +require "appraisal/gemfile" +require "active_support/core_ext/string/strip" RSpec.describe Appraisal::Gemfile do include StreamHelpers it "supports gemfiles without sources" do gemfile = Appraisal::Gemfile.new - expect(gemfile.to_s.strip).to eq '' + expect(gemfile.to_s.strip).to eq "" end it "supports multiple sources" do gemfile = Appraisal::Gemfile.new gemfile.source "one" gemfile.source "two" - expect(gemfile.to_s.strip).to eq %{source "one"\nsource "two"} + expect(gemfile.to_s.strip).to eq %(source "one"\nsource "two") end it "ignores duplicate sources" do gemfile = Appraisal::Gemfile.new gemfile.source "one" gemfile.source "one" - expect(gemfile.to_s.strip).to eq %{source "one"} + expect(gemfile.to_s.strip).to eq %(source "one") end it "preserves dependency order" do @@ -35,10 +37,10 @@ it "supports symbol sources" do gemfile = Appraisal::Gemfile.new gemfile.source :one - expect(gemfile.to_s.strip).to eq %{source :one} + expect(gemfile.to_s.strip).to eq %(source :one) end - it 'supports group syntax' do + it "supports group syntax" do gemfile = Appraisal::Gemfile.new gemfile.group :development, :test do @@ -84,7 +86,7 @@ GEMFILE end - it 'supports platform syntax' do + it "supports platform syntax" do gemfile = Appraisal::Gemfile.new gemfile.platform :jruby do @@ -226,7 +228,7 @@ context "no contents" do it "shows empty string" do gemfile = Appraisal::Gemfile.new - expect(gemfile.to_s).to eq '' + expect(gemfile.to_s).to eq "" end end @@ -251,26 +253,26 @@ end context "relative path handling" do - before { stub_const('RUBY_VERSION', '2.3.0') } + before { stub_const("RUBY_VERSION", "2.3.0") } context "in :path option" do it "handles dot path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :path => "." + gemfile.gem "bacon", path: "." expect(gemfile.to_s).to eq %(gem "bacon", path: "../") end it "handles relative path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :path => "../bacon" + gemfile.gem "bacon", path: "../bacon" expect(gemfile.to_s).to eq %(gem "bacon", path: "../../bacon") end it "handles absolute path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :path => "/tmp" + gemfile.gem "bacon", path: "/tmp" expect(gemfile.to_s).to eq %(gem "bacon", path: "/tmp") end @@ -279,31 +281,30 @@ context "in :git option" do it "handles dot git path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :git => "." + gemfile.gem "bacon", git: "." expect(gemfile.to_s).to eq %(gem "bacon", git: "../") end it "handles relative git path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :git => "../bacon" + gemfile.gem "bacon", git: "../bacon" expect(gemfile.to_s).to eq %(gem "bacon", git: "../../bacon") end it "handles absolute git path" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :git => "/tmp" + gemfile.gem "bacon", git: "/tmp" expect(gemfile.to_s).to eq %(gem "bacon", git: "/tmp") end it "handles git uri" do gemfile = Appraisal::Gemfile.new - gemfile.gem "bacon", :git => "git@github.com:bacon/bacon.git" + gemfile.gem "bacon", git: "git@github.com:bacon/bacon.git" - expect(gemfile.to_s). - to eq %(gem "bacon", git: "git@github.com:bacon/bacon.git") + expect(gemfile.to_s).to eq %(gem "bacon", git: "git@github.com:bacon/bacon.git") end end @@ -315,11 +316,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip path "../" do gem "bacon" end - gemfile + GEMFILE end it "handles relative path" do @@ -329,11 +330,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip path "../../bacon" do gem "bacon" end - gemfile + GEMFILE end it "handles absolute path" do @@ -343,11 +344,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip path "/tmp" do gem "bacon" end - gemfile + GEMFILE end end @@ -359,11 +360,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip git "../" do gem "bacon" end - gemfile + GEMFILE end it "handles relative git path" do @@ -373,11 +374,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip git "../../bacon" do gem "bacon" end - gemfile + GEMFILE end it "handles absolute git path" do @@ -387,11 +388,11 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip git "/tmp" do gem "bacon" end - gemfile + GEMFILE end it "handles git uri" do @@ -401,18 +402,18 @@ gem "bacon" end - expect(gemfile.to_s).to eq <<-gemfile.strip_heredoc.strip + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip git "git@github.com:bacon/bacon.git" do gem "bacon" end - gemfile + GEMFILE end end context "in gemspec directive" do it "handles gemspec path" do gemfile = Appraisal::Gemfile.new - gemfile.gemspec :path => "." + gemfile.gemspec path: "." expect(gemfile.to_s).to eq %(gemspec path: "../") end @@ -420,12 +421,12 @@ end context "git_source support" do - before { stub_const('RUBY_VERSION', '2.3.0') } + before { stub_const("RUBY_VERSION", "2.3.0") } it "stores git_source declaration and apply it as git option" do gemfile = Appraisal::Gemfile.new gemfile.git_source(:custom_source) { |repo| "path/#{repo}" } - gemfile.gem "bacon", :custom_source => "bacon_pancake" + gemfile.gem "bacon", custom_source: "bacon_pancake" expect(gemfile.to_s).to eq %(gem "bacon", git: "../path/bacon_pancake") end diff --git a/spec/appraisal/utils_spec.rb b/spec/appraisal/utils_spec.rb index 0a1d2e92..04dfe910 100644 --- a/spec/appraisal/utils_spec.rb +++ b/spec/appraisal/utils_spec.rb @@ -1,34 +1,32 @@ -require 'spec_helper' -require 'appraisal/utils' +# frozen_string_literal: true + +require "spec_helper" +require "appraisal/utils" RSpec.describe Appraisal::Utils do - describe '.format_string' do + describe ".format_string" do it "prints out a nice looking hash without brackets with new syntax" do - hash = { :foo => 'bar' } + hash = { foo: "bar" } expect(Appraisal::Utils.format_string(hash)).to eq('foo: "bar"') - hash = { 'baz' => { :ball => 'boo' }} - expect(Appraisal::Utils.format_string(hash)). - to eq('"baz" => { ball: "boo" }') + hash = { "baz" => { ball: "boo" } } + expect(Appraisal::Utils.format_string(hash)).to eq('"baz" => { ball: "boo" }') end end - describe '.format_arguments' do - before { stub_const('RUBY_VERSION', '2.3.0') } + describe ".format_arguments" do + before { stub_const("RUBY_VERSION", "2.3.0") } - it 'prints out arguments without enclosing square brackets' do - arguments = [:foo, { :bar => { :baz => 'ball' }}] + it "prints out arguments without enclosing square brackets" do + arguments = [:foo, { bar: { baz: "ball" } }] - expect(Appraisal::Utils.format_arguments(arguments)).to eq( - ':foo, bar: { baz: "ball" }' - ) + expect(Appraisal::Utils.format_arguments(arguments)).to eq(':foo, bar: { baz: "ball" }') end it "returns nil if arguments is empty" do arguments = [] - expect(Appraisal::Utils.format_arguments(arguments)). - to eq(nil) + expect(Appraisal::Utils.format_arguments(arguments)).to eq(nil) end end @@ -45,25 +43,20 @@ expect(Appraisal::Utils.prefix_path("/tmp")).to eq "/tmp" end - it "strips out './' from path" do - expect(Appraisal::Utils.prefix_path("./tmp/./appraisal././")). - to eq "../tmp/appraisal./" + it "strips out './' from path" do + expect(Appraisal::Utils.prefix_path("./tmp/./appraisal././")).to eq "../tmp/appraisal./" end it "does not prefix Git uri" do - expect(Appraisal::Utils.prefix_path("git@github.com:bacon/bacon.git")). - to eq "git@github.com:bacon/bacon.git" - expect(Appraisal::Utils.prefix_path("git://github.com/bacon/bacon.git")). - to eq "git://github.com/bacon/bacon.git" - expect( - Appraisal::Utils.prefix_path("https://github.com/bacon/bacon.git") - ).to eq("https://github.com/bacon/bacon.git") + expect(Appraisal::Utils.prefix_path("git@github.com:bacon/bacon.git")).to eq "git@github.com:bacon/bacon.git" + expect(Appraisal::Utils.prefix_path("git://github.com/bacon/bacon.git")).to eq "git://github.com/bacon/bacon.git" + expect(Appraisal::Utils.prefix_path("https://github.com/bacon/bacon.git")).to eq("https://github.com/bacon/bacon.git") end end describe ".bundler_version" do it "returns the bundler version" do - bundler = double("Bundler", :name => "bundler", :version => "a.b.c") + bundler = double("Bundler", name: "bundler", version: "a.b.c") allow(Gem::Specification).to receive(:detect).and_return(bundler) version = Appraisal::Utils.bundler_version diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 249f049e..20b036de 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,11 @@ -require 'rubygems' -require 'bundler/setup' +# frozen_string_literal: true + +require "rubygems" +require "bundler/setup" require "./spec/support/acceptance_test_helpers" require "./spec/support/stream_helpers" -PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze +PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")).freeze TMP_GEM_ROOT = File.join(PROJECT_ROOT, "tmp", "bundler") TMP_GEM_BUILD = File.join(PROJECT_ROOT, "tmp", "build") ENV["APPRAISAL_UNDER_TEST"] = "1" @@ -11,11 +13,11 @@ RSpec.configure do |config| config.raise_errors_for_deprecations! - config.define_derived_metadata(:file_path => %r{spec\/acceptance\/}) do |metadata| + config.define_derived_metadata(file_path: %r{spec\/acceptance\/}) do |metadata| metadata[:type] = :acceptance end - config.include AcceptanceTestHelpers, :type => :acceptance + config.include AcceptanceTestHelpers, type: :acceptance # disable monkey patching # see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode diff --git a/spec/support/acceptance_test_helpers.rb b/spec/support/acceptance_test_helpers.rb index 2b3f4216..52e0c60a 100644 --- a/spec/support/acceptance_test_helpers.rb +++ b/spec/support/acceptance_test_helpers.rb @@ -1,28 +1,30 @@ -require 'rspec/expectations/expectation_target' -require 'active_support/core_ext/string/strip' -require 'active_support/core_ext/string/filters' -require 'active_support/concern' -require 'appraisal/utils' +# frozen_string_literal: true + +require "rspec/expectations/expectation_target" +require "active_support/core_ext/string/strip" +require "active_support/core_ext/string/filters" +require "active_support/concern" +require "appraisal/utils" require "./spec/support/dependency_helpers" module AcceptanceTestHelpers extend ActiveSupport::Concern include DependencyHelpers - BUNDLER_ENVIRONMENT_VARIABLES = %w( + BUNDLER_ENVIRONMENT_VARIABLES = %w[ RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE BUNDLER_SETUP - ).freeze + ].freeze included do metadata[:type] = :acceptance - before :parallel => true do + before parallel: true do unless Appraisal::Utils.support_parallel_installation? - pending 'This Bundler version does not support --jobs flag.' + pending "This Bundler version does not support --jobs flag." end end @@ -44,7 +46,7 @@ module AcceptanceTestHelpers def save_environment_variables @original_environment_variables = {} - (BUNDLER_ENVIRONMENT_VARIABLES + %w(PATH)).each do |key| + (BUNDLER_ENVIRONMENT_VARIABLES + %w[PATH]).each do |key| @original_environment_variables[key] = ENV[key] end end @@ -56,7 +58,7 @@ def unset_bundler_environment_variables end def add_binstub_path - ENV['PATH'] = "bin:#{ENV['PATH']}" + ENV["PATH"] = "bin:#{ENV['PATH']}" end def restore_environment_variables @@ -66,28 +68,28 @@ def restore_environment_variables end def build_appraisal_file(content) - write_file 'Appraisals', content.strip_heredoc + write_file "Appraisals", content.strip_heredoc end def build_gemfile(content) - write_file 'Gemfile', content.strip_heredoc + write_file "Gemfile", content.strip_heredoc end def add_gemspec_to_gemfile in_test_directory do - File.open('Gemfile', 'a') { |file| file.puts 'gemspec' } + File.open("Gemfile", "a") { |file| file.puts "gemspec" } end end def build_gemspec - write_file "stage.gemspec", <<-gemspec + write_file "stage.gemspec", <<-GEMSPEC Gem::Specification.new do |s| s.name = 'stage' s.version = '0.1' s.summary = 'Awesome Gem!' s.authors = "Appraisal" end - gemspec + GEMSPEC end def content_of(path) @@ -107,11 +109,11 @@ def be_exists private def current_directory - File.expand_path('tmp/stage') + File.expand_path("tmp/stage") end def write_file(filename, content) - in_test_directory { File.open(filename, 'w') { |file| file.puts content } } + in_test_directory { File.open(filename, "w") { |file| file.puts content } } end def cleanup_artifacts @@ -121,8 +123,8 @@ def cleanup_artifacts def build_default_dummy_gems FileUtils.mkdir_p(TMP_GEM_ROOT) - build_gem 'dummy', '1.0.0' - build_gem 'dummy', '1.1.0' + build_gem "dummy", "1.0.0" + build_gem "dummy", "1.1.0" end def ensure_bundler_is_available @@ -140,11 +142,11 @@ def ensure_bundler_is_available end def build_default_gemfile - build_gemfile <<-Gemfile + build_gemfile <<-GEMFILE source 'https://rubygems.org' gem 'appraisal', :path => '#{PROJECT_ROOT}' - Gemfile + GEMFILE run "bundle install --local" run "bundle binstubs --all" @@ -165,10 +167,10 @@ def run(command, raise_on_error = true) end if raise_on_error && exitstatus != 0 - raise RuntimeError, <<-error_message.strip_heredoc + raise RuntimeError, <<-ERROR_MESSAGE.strip_heredoc Command #{command.inspect} exited with status #{exitstatus}. Output: #{output.gsub(/^/, ' ')} - error_message + ERROR_MESSAGE end end end diff --git a/spec/support/dependency_helpers.rb b/spec/support/dependency_helpers.rb index 14cf1308..54752d20 100644 --- a/spec/support/dependency_helpers.rb +++ b/spec/support/dependency_helpers.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module DependencyHelpers - def build_gem(gem_name, version = '1.0.0') - ENV['GEM_HOME'] = TMP_GEM_ROOT + def build_gem(gem_name, version = "1.0.0") + ENV["GEM_HOME"] = TMP_GEM_ROOT unless File.exist? "#{TMP_GEM_ROOT}/gems/#{gem_name}-#{version}" FileUtils.mkdir_p "#{TMP_GEM_BUILD}/#{gem_name}/lib" @@ -9,8 +11,8 @@ def build_gem(gem_name, version = '1.0.0') gemspec = "#{gem_name}.gemspec" lib_file = "lib/#{gem_name}.rb" - File.open gemspec, 'w' do |file| - file.puts <<-gemspec + File.open gemspec, "w" do |file| + file.puts <<-GEMSPEC Gem::Specification.new do |s| s.name = #{gem_name.inspect} s.version = #{version.inspect} @@ -21,14 +23,14 @@ def build_gem(gem_name, version = '1.0.0') s.homepage = 'http://github.com/thoughtbot/#{gem_name}' s.required_ruby_version = '>= 2.3.0' end - gemspec + GEMSPEC end - File.open lib_file, 'w' do |file| + File.open lib_file, "w" do |file| file.puts "$#{gem_name}_version = '#{version}'" end - redirect = ENV['VERBOSE'] ? '' : '2>&1' + redirect = ENV["VERBOSE"] ? "" : "2>&1" puts "building gem: #{gem_name} #{version}" if ENV["VERBOSE"] `gem build #{gemspec} #{redirect}` @@ -45,7 +47,7 @@ def build_gems(gems) gems.each { |gem| build_gem(gem) } end - def build_git_gem(gem_name, version = '1.0.0') + def build_git_gem(gem_name, version = "1.0.0") puts "building git gem: #{gem_name} #{version}" if ENV["VERBOSE"] build_gem gem_name, version diff --git a/spec/support/stream_helpers.rb b/spec/support/stream_helpers.rb index dfd7c353..ca0eb436 100644 --- a/spec/support/stream_helpers.rb +++ b/spec/support/stream_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "tempfile" module StreamHelpers