diff --git a/lib/support_engine/file.rb b/lib/support_engine/file.rb index 82b167f..c7f7bad 100644 --- a/lib/support_engine/file.rb +++ b/lib/support_engine/file.rb @@ -5,7 +5,7 @@ module SupportEngine module File class << self # Regex to select encoding details from file -bi command results - CHARSET_DETECT_REGEXP = /charset=(.*)\n/.freeze + CHARSET_DETECT_REGEXP = /charset=(.*)\n/ # Default fallback encoding DEFAULT_ENCODING = 'utf-8' diff --git a/lib/support_engine/git.rb b/lib/support_engine/git.rb index 6ae9487..93daea0 100644 --- a/lib/support_engine/git.rb +++ b/lib/support_engine/git.rb @@ -9,7 +9,9 @@ class << self # @param local_path [String] local path to which we clone # @return [Boolean] true if repository got cloned # @raise [Errors::FailedShellCommand] raised when anything went wrong + # rubocop:disable Naming/PredicateMethod def clone_mirror(remote_path, local_path) + # rubocop:enable Naming/PredicateMethod Shell.call("git clone --mirror #{remote_path} #{local_path}/.git/") Shell.call_in_path(local_path, 'git remote update --prune') Shell.call_in_path(local_path, 'git config --bool core.bare false') @@ -22,7 +24,9 @@ def clone_mirror(remote_path, local_path) # @param path [String] path of a current repository build # @param ref [String] branch or commit that we want to checkout to # @return [Boolean] true if we were able to checkout + # rubocop:disable Naming/PredicateMethod def checkout(path, ref) + # rubocop:enable Naming/PredicateMethod result = SupportEngine::Shell.call_in_path( path, "git checkout #{ref}", diff --git a/lib/support_engine/git/branch.rb b/lib/support_engine/git/branch.rb index beeabae..1b21929 100644 --- a/lib/support_engine/git/branch.rb +++ b/lib/support_engine/git/branch.rb @@ -28,7 +28,7 @@ class Branch < Base DETACH_STRING = 'HEAD detached' # Regexp to remove the '* ' prefix of current branch - CURRENT_BRANCH_SANITIZER = /\A\*\s{1}/.freeze + CURRENT_BRANCH_SANITIZER = /\A\*\s{1}/ class << self # Detects a given commit branch @@ -45,13 +45,13 @@ def commit(path, commit_hash) # If the head points to HEAD it means that the repo is in the detach state # and we need to pick the latest ref to get a head branch - head = head == 'HEAD' ? sanitize_branch(Ref.latest(path)) : head + head = sanitize_branch(Ref.latest(path)) if head == 'HEAD' candidates = call_in_path!(path, cmd)[:stdout] - .split("\n") - .map { |cand| cand.gsub(CURRENT_BRANCH_SANITIZER, '') } - .map(&:strip) - .tap { |arr| arr.delete_if { |cand| cand.include?(DETACH_STRING) } } + .split("\n") + .map { |cand| cand.gsub(CURRENT_BRANCH_SANITIZER, '') } + .map(&:strip) + .tap { |arr| arr.delete_if { |cand| cand.include?(DETACH_STRING) } } resolve_branch( candidates, @@ -151,7 +151,9 @@ def resolve_branch(each_ref, commit_hash, head) # @param commit_hash [String] commit hash we're checking # @param head [String] name of the head branch # @return [String] origin branch of a commit hash + # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity def resolve_from_origins(origin_refs, commit_hash, head) + # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # We prioritize head branches as main branches of a commit if they are in the head return head if origin_refs.any? do |candidate| candidate.include?('origin/HEAD') || candidate.include?("refs/heads/#{head}") @@ -172,7 +174,7 @@ def resolve_from_origins(origin_refs, commit_hash, head) end # And we pick the first one with and sanitize it to get only the branch name - (branch || candidates.first) + branch || candidates.first end # When we cannot find branch of a commit hash, we try to find pull request as it probably @@ -201,7 +203,7 @@ def sanitize_branch(branch) raise SupportEngine::Errors::UnknownBranch unless branch UNWANTED_PREFIXES.each { |prefix| branch.gsub!(/\A#{prefix}/, '') } - branch.gsub!(%r{\/head\z}, '') if branch.start_with?('pull/') + branch.delete_suffix!('/head') if branch.start_with?('pull/') branch end diff --git a/lib/support_engine/git/commits.rb b/lib/support_engine/git/commits.rb index 173f5a7..66ae703 100644 --- a/lib/support_engine/git/commits.rb +++ b/lib/support_engine/git/commits.rb @@ -189,7 +189,7 @@ def clean_for_each_ref_results(data, source) { commit_hash: part2[0], committed_at: Time.zone.parse(part1[0]), - source: source + source: } end data.uniq! { |h| h[:commit_hash] } diff --git a/lib/support_engine/git/gc.rb b/lib/support_engine/git/gc.rb index 121babd..44892b1 100644 --- a/lib/support_engine/git/gc.rb +++ b/lib/support_engine/git/gc.rb @@ -11,7 +11,9 @@ class << self # @raise [SupportEngine::Errors::FailedShellCommand] raised when anything went wrong # @example Reset state (watch out - this will reset for real!) # SupportEngine::Git::Gc.reset('./') #=> true + # rubocop:disable Naming/PredicateMethod def reset(path) + # rubocop:enable Naming/PredicateMethod Shell::Git.call_in_path(path, :reset, '--hard HEAD') Shell::Git.call_in_path(path, :clean, '-f -d') true diff --git a/lib/support_engine/git/log.rb b/lib/support_engine/git/log.rb index b49726e..9d56898 100644 --- a/lib/support_engine/git/log.rb +++ b/lib/support_engine/git/log.rb @@ -61,7 +61,7 @@ def shortstat(path, limit: nil, since: 20.years.ago) # @param path [String] path of a current repository build # @return [DateTime] datetime of a head commit def head_committed_at(path) - Time.parse(Shell::Git.call_in_path(path, :log, '-1 --format=%cd').first) + Time.zone.parse(Shell::Git.call_in_path(path, :log, '-1 --format=%cd').first) end end end diff --git a/lib/support_engine/git/ref.rb b/lib/support_engine/git/ref.rb index fdf6e29..22cf98e 100644 --- a/lib/support_engine/git/ref.rb +++ b/lib/support_engine/git/ref.rb @@ -25,11 +25,11 @@ def latest(local_path) # @example # Git::Ref.head() #=> # {:stdout=>"develop\n", :stderr=>"", :exit_code=>0} - def head(local_path, raise_on_invalid_exit = true) + def head(local_path, raise_on_invalid_exit: true) Shell.call_in_path( local_path, 'git rev-parse --abbrev-ref HEAD', - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) end @@ -41,7 +41,7 @@ def head(local_path, raise_on_invalid_exit = true) # @example # Git::Ref.head!() #=> develop def head!(local_path) - result = head(local_path, false) + result = head(local_path, raise_on_invalid_exit: false) return result[:stdout].strip if head?(result) Shell.call_in_path(local_path, "git symbolic-ref HEAD #{latest(local_path)}") @@ -52,13 +52,15 @@ def head!(local_path) # @param result [Hash] hash with 3 keys describing output # (stdout, stderr, exit_code) # @return [Boolean] + # rubocop:disable Rails/NegateInclude def head?(result) - result[:stderr].empty? || \ + result[:stderr].empty? || !result[:stderr].include?( "fatal: ambiguous argument 'HEAD': " \ 'unknown revision or path not in the working tree' ) end + # rubocop:enable Rails/NegateInclude end end end diff --git a/lib/support_engine/git/repo_builder/base.rb b/lib/support_engine/git/repo_builder/base.rb index c80a9aa..ec45e73 100644 --- a/lib/support_engine/git/repo_builder/base.rb +++ b/lib/support_engine/git/repo_builder/base.rb @@ -13,39 +13,29 @@ module RepoBuilder class Base class << self # @return [String] Where should we put our test dummy repo - def location - ::File.join(SupportEngine.gem_root, 'tmp', "test_repo_#{name}") - end + def location = ::File.join(SupportEngine.gem_root, 'tmp', "test_repo_#{name}") # @return [String] Path to .git folder of our location - def location_git - ::File.join(location, '.git') - end + def location_git = ::File.join(location, '.git') # @return [String] Origin poiting to external location - def origin - "https://something.origin/#{name}" - end + def origin = "https://something.origin/#{name}" # @return [String] Default committer that is git compatible # @example # self.committer #=> 'Committer ' - def committer - Committer.call - end + def committer = Committer.call # @return [String] underscored name of current class without modules # @example # self.name #=> 'master_mirror' - def name - to_s.split('::').last.underscore - end + def name = to_s.split('::').last.underscore # @param message [String] commit message that we want to have # @param author [String] author details in git compatible format # @param committed_at [Time, DateTime] time of a commit (now is the default) # @return [String] git commit command with proper message, date and author - def commit(message, author: committer, committed_at: Time.now) + def commit(message, author: committer, committed_at: Time.current) cmd = [] cmd << "GIT_COMMITTER_DATE='#{committed_at}'" cmd << "git commit --no-gpg-sign -m '#{message}'" @@ -56,9 +46,12 @@ def commit(message, author: committer, committed_at: Time.now) # Creates a dummy repository in LOCATION with some commits and branches def bootstrap destroy - SupportEngine::Shell.call(const_get(:BOOTSTRAP_CMD)) + SupportEngine::Shell.call(bootstrap_cmd) end + # @return [String] Bootstrap command - override in subclasses + def bootstrap_cmd = raise NotImplementedError + # Destroys dummy repository directory def destroy FileUtils.rm_r(location, secure: true) if Dir.exist?(location) diff --git a/lib/support_engine/git/repo_builder/broken_head_ref.rb b/lib/support_engine/git/repo_builder/broken_head_ref.rb index 2f1a16f..e0e0f29 100644 --- a/lib/support_engine/git/repo_builder/broken_head_ref.rb +++ b/lib/support_engine/git/repo_builder/broken_head_ref.rb @@ -6,27 +6,29 @@ module RepoBuilder # Creates repository with no master branch and broken head ref class BrokenHeadRef < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit'), - 'git branch develop', - 'git checkout develop', - 'echo "hash = { \'test\' => 2 }" > develop.rb', - 'git add --all ./', - commit('develop commit'), - 'git branch different-branch', - 'git checkout different-branch', - 'touch different-branch.txt', - 'git add --all ./', - commit('different-branch commit'), - 'git checkout develop', - "git remote add origin #{origin}", - 'git branch -D master', - 'echo "ref: refs/heads/master" > .git/HEAD' - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit'), + 'git branch develop', + 'git checkout develop', + 'echo "hash = { \'test\' => 2 }" > develop.rb', + 'git add --all ./', + commit('develop commit'), + 'git branch different-branch', + 'git checkout different-branch', + 'touch different-branch.txt', + 'git add --all ./', + commit('different-branch commit'), + 'git checkout develop', + "git remote add origin #{origin}", + 'git branch -D master', + 'echo "ref: refs/heads/master" > .git/HEAD' + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master.rb b/lib/support_engine/git/repo_builder/master.rb index cbde693..c6eea30 100644 --- a/lib/support_engine/git/repo_builder/master.rb +++ b/lib/support_engine/git/repo_builder/master.rb @@ -6,20 +6,22 @@ module RepoBuilder # Creates repository with master branch class Master < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit', committed_at: 2.days.ago), - 'git branch different-branch', - 'git checkout different-branch', - 'touch different-branch.txt', - 'git add --all ./', - commit('different-branch commit'), - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit', committed_at: 2.days.ago), + 'git branch different-branch', + 'git checkout different-branch', + 'touch different-branch.txt', + 'git add --all ./', + commit('different-branch commit'), + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_bare_mirror.rb b/lib/support_engine/git/repo_builder/master_bare_mirror.rb index d1f4c9b..2b72458 100644 --- a/lib/support_engine/git/repo_builder/master_bare_mirror.rb +++ b/lib/support_engine/git/repo_builder/master_bare_mirror.rb @@ -6,7 +6,9 @@ module RepoBuilder # Creates new mirror repository from master repository class MasterBareMirror < Base # Steps we need to take in order to setup dummy repository with --mirror - BOOTSTRAP_CMD = "git clone --mirror #{Master.location} #{location}/.git/" + def self.bootstrap_cmd + "git clone --mirror #{Master.location} #{location}/.git/" + end end end end diff --git a/lib/support_engine/git/repo_builder/master_multiple_committers.rb b/lib/support_engine/git/repo_builder/master_multiple_committers.rb index 1202f44..1098823 100644 --- a/lib/support_engine/git/repo_builder/master_multiple_committers.rb +++ b/lib/support_engine/git/repo_builder/master_multiple_committers.rb @@ -6,26 +6,28 @@ module RepoBuilder # Creates repository with master branch and multiple committers class MasterMultipleCommitters < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit'), - 'echo "hash = { \'test\' => 2 }" > master.rb', - 'git add --all ./', - commit('master commit committer2', author: 'Committer2 '), - 'echo "hash = { \'test\' => 3 }" > master.rb', - 'git add --all ./', - commit('master commit committer3', author: 'Committer3 '), - 'git branch different-branch', - 'git checkout different-branch', - 'touch different-branch.txt', - 'git add --all ./', - commit('different-branch commit'), - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit'), + 'echo "hash = { \'test\' => 2 }" > master.rb', + 'git add --all ./', + commit('master commit committer2', author: 'Committer2 '), + 'echo "hash = { \'test\' => 3 }" > master.rb', + 'git add --all ./', + commit('master commit committer3', author: 'Committer3 '), + 'git branch different-branch', + 'git checkout different-branch', + 'touch different-branch.txt', + 'git add --all ./', + commit('different-branch commit'), + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_only.rb b/lib/support_engine/git/repo_builder/master_only.rb index 50ee694..1dc11ed 100644 --- a/lib/support_engine/git/repo_builder/master_only.rb +++ b/lib/support_engine/git/repo_builder/master_only.rb @@ -6,20 +6,22 @@ module RepoBuilder # Creates repository with master branch only class MasterOnly < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit', committed_at: 2.days.ago), - 'echo "hash = { \'test\' => 2 }" > master.rb', - 'git add --all ./', - commit('master commit 2', committed_at: 1.days.ago), - 'echo "hash = { \'test\' => 3 }" > master.rb', - 'git add --all ./', - commit('master commit 3', committed_at: 0.days.ago), - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit', committed_at: 2.days.ago), + 'echo "hash = { \'test\' => 2 }" > master.rb', + 'git add --all ./', + commit('master commit 2', committed_at: 1.day.ago), + 'echo "hash = { \'test\' => 3 }" > master.rb', + 'git add --all ./', + commit('master commit 3', committed_at: 0.days.ago), + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_with_big_branch.rb b/lib/support_engine/git/repo_builder/master_with_big_branch.rb index 4087cd9..3dea137 100644 --- a/lib/support_engine/git/repo_builder/master_with_big_branch.rb +++ b/lib/support_engine/git/repo_builder/master_with_big_branch.rb @@ -17,18 +17,20 @@ def self.create_commits end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit', committed_at: 30.days.ago), - 'git branch different-branch', - 'git checkout different-branch', - create_commits, - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit', committed_at: 30.days.ago), + 'git branch different-branch', + 'git checkout different-branch', + create_commits, + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_with_big_branch60.rb b/lib/support_engine/git/repo_builder/master_with_big_branch60.rb index 63b13e8..676a882 100644 --- a/lib/support_engine/git/repo_builder/master_with_big_branch60.rb +++ b/lib/support_engine/git/repo_builder/master_with_big_branch60.rb @@ -17,18 +17,20 @@ def self.create_commits end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit', committed_at: 90.days.ago), - 'git branch different-branch', - 'git checkout different-branch', - create_commits, - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit', committed_at: 90.days.ago), + 'git branch different-branch', + 'git checkout different-branch', + create_commits, + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_with_history.rb b/lib/support_engine/git/repo_builder/master_with_history.rb index 6b3297b..408929d 100644 --- a/lib/support_engine/git/repo_builder/master_with_history.rb +++ b/lib/support_engine/git/repo_builder/master_with_history.rb @@ -9,7 +9,7 @@ class MasterWithHistory < Base def self.create_commits 30.downto(0).flat_map do |number| [ - "echo \"hash = { \'test\' => #{number} }\" > master.rb", + "echo \"hash = { 'test' => #{number} }\" > master.rb", 'git add --all ./', commit("master commit #{number}", committed_at: number.days.ago), "git branch different-branch-#{number}", @@ -23,13 +23,15 @@ def self.create_commits end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - create_commits, - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + create_commits, + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/master_with_weird_branch.rb b/lib/support_engine/git/repo_builder/master_with_weird_branch.rb index 980987e..29362db 100644 --- a/lib/support_engine/git/repo_builder/master_with_weird_branch.rb +++ b/lib/support_engine/git/repo_builder/master_with_weird_branch.rb @@ -17,18 +17,20 @@ def self.create_commits end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit', committed_at: 30.days.ago), - 'git branch \'#w@eird-branch\'', - 'git checkout \'#w@eird-branch\'', - create_commits, - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit', committed_at: 30.days.ago), + 'git branch \'#w@eird-branch\'', + 'git checkout \'#w@eird-branch\'', + create_commits, + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/no_master.rb b/lib/support_engine/git/repo_builder/no_master.rb index 78468c0..48cfa44 100644 --- a/lib/support_engine/git/repo_builder/no_master.rb +++ b/lib/support_engine/git/repo_builder/no_master.rb @@ -6,26 +6,28 @@ module RepoBuilder # Creates repository with no master branch class NoMaster < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'echo "hash = { \'test\' => 1 }" > master.rb', - 'git add --all ./', - commit('master commit'), - 'git branch develop', - 'git checkout develop', - 'echo "hash = { \'test\' => 2 }" > develop.rb', - 'git add --all ./', - commit('develop commit'), - 'git branch different-branch', - 'git checkout different-branch', - 'touch different-branch.txt', - 'git add --all ./', - commit('different-branch commit'), - 'git checkout develop', - "git remote add origin #{origin}", - 'git branch -D master' - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'echo "hash = { \'test\' => 1 }" > master.rb', + 'git add --all ./', + commit('master commit'), + 'git branch develop', + 'git checkout develop', + 'echo "hash = { \'test\' => 2 }" > develop.rb', + 'git add --all ./', + commit('develop commit'), + 'git branch different-branch', + 'git checkout different-branch', + 'touch different-branch.txt', + 'git add --all ./', + commit('different-branch commit'), + 'git checkout develop', + "git remote add origin #{origin}", + 'git branch -D master' + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/outdated_gems.rb b/lib/support_engine/git/repo_builder/outdated_gems.rb index ffd2ebf..c78ad8d 100644 --- a/lib/support_engine/git/repo_builder/outdated_gems.rb +++ b/lib/support_engine/git/repo_builder/outdated_gems.rb @@ -42,15 +42,17 @@ def gemfile_lock end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - "printf \"#{gemfile}\" > Gemfile", - "printf \"#{gemfile_lock}\" > Gemfile.lock", - 'git add --all ./', - commit('master commit'), - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + "printf \"#{gemfile}\" > Gemfile", + "printf \"#{gemfile_lock}\" > Gemfile.lock", + 'git add --all ./', + commit('master commit'), + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/outdated_gems_strict.rb b/lib/support_engine/git/repo_builder/outdated_gems_strict.rb index f789966..57bfb18 100644 --- a/lib/support_engine/git/repo_builder/outdated_gems_strict.rb +++ b/lib/support_engine/git/repo_builder/outdated_gems_strict.rb @@ -42,15 +42,17 @@ def gemfile_lock end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - "printf \"#{gemfile}\" > Gemfile", - "printf \"#{gemfile_lock}\" > Gemfile.lock", - 'git add --all ./', - commit('master commit'), - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + "printf \"#{gemfile}\" > Gemfile", + "printf \"#{gemfile_lock}\" > Gemfile.lock", + 'git add --all ./', + commit('master commit'), + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/private_gem.rb b/lib/support_engine/git/repo_builder/private_gem.rb index 06e9e55..559a556 100644 --- a/lib/support_engine/git/repo_builder/private_gem.rb +++ b/lib/support_engine/git/repo_builder/private_gem.rb @@ -47,15 +47,17 @@ def gemfile_lock end # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - "printf \"#{gemfile}\" > Gemfile", - "printf \"#{gemfile_lock}\" > Gemfile.lock", - 'git add --all ./', - commit('master commit'), - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + "printf \"#{gemfile}\" > Gemfile", + "printf \"#{gemfile_lock}\" > Gemfile.lock", + 'git add --all ./', + commit('master commit'), + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/git/repo_builder/yarn.rb b/lib/support_engine/git/repo_builder/yarn.rb index 48c14c1..5185c48 100644 --- a/lib/support_engine/git/repo_builder/yarn.rb +++ b/lib/support_engine/git/repo_builder/yarn.rb @@ -6,21 +6,23 @@ module RepoBuilder # Creates repository with yarn and cloc installed, so we can test yarn run command class Yarn < Base # Steps we need to take in order to setup dummy repository - BOOTSTRAP_CMD = [ - "git init #{location}", - "cd #{location}", - 'yarn init -y', - 'yarn add cloc', - 'git add --all ./', - commit('master commit'), - 'git branch different-branch', - 'git checkout different-branch', - 'touch different-branch.txt', - 'git add --all ./', - commit('different-branch commit'), - 'git checkout master', - "git remote add origin #{origin}" - ].join(' && ').freeze + def self.bootstrap_cmd + [ + "git init #{location}", + "cd #{location}", + 'yarn init -y', + 'yarn add cloc', + 'git add --all ./', + commit('master commit'), + 'git branch different-branch', + 'git checkout different-branch', + 'touch different-branch.txt', + 'git add --all ./', + commit('different-branch commit'), + 'git checkout master', + "git remote add origin #{origin}" + ].join(' && ') + end end end end diff --git a/lib/support_engine/rspec_locator.rb b/lib/support_engine/rspec_locator.rb index 1e8a9ef..69931e9 100644 --- a/lib/support_engine/rspec_locator.rb +++ b/lib/support_engine/rspec_locator.rb @@ -3,7 +3,7 @@ %w[ active_support/inflector fileutils -].each(&method(:require)) +].each { require(it) } module SupportEngine # RSpec extension for the `RSpec.describe` subject class auto-discovery @@ -15,6 +15,7 @@ module SupportEngine class RSpecLocator < Module # @param spec_helper_file_path [String] path to the spec_helper.rb file def initialize(spec_helper_file_path) + super() @specs_root_dir = ::File.dirname(spec_helper_file_path) end @@ -29,12 +30,12 @@ def extended(rspec) # out the proper class that we want to describe # @param block [Proc] block with specs rspec.define_singleton_method :describe_current do |&block| - describe(this.inherited, &block) + describe(this.described_class_from_path, &block) end end # @return [Class] class name for the RSpec `#describe` method - def inherited + def described_class_from_path caller(2..2) .first .split(':') @@ -43,7 +44,7 @@ def inherited .gsub('_spec.rb', '') .split('/') .delete_if(&:empty?) - .itself[1..-1] + .itself[1..] .join('/') .camelize .constantize diff --git a/lib/support_engine/shell.rb b/lib/support_engine/shell.rb index 2297073..9f07407 100644 --- a/lib/support_engine/shell.rb +++ b/lib/support_engine/shell.rb @@ -38,15 +38,10 @@ def call(command_with_options, raise_on_invalid_exit: true) # @return [Hash] hash with 3 keys describing output (stdout, stderr, exit_code) def call_in_path(path, command, raise_on_invalid_exit: true) command = ['cd', path.to_s.shellescape, '&&', command] - call(command.join(' '), raise_on_invalid_exit: raise_on_invalid_exit) + call(command.join(' '), raise_on_invalid_exit:) end - # Escapes any dangerous parameters so we can use a string in a safe way in shell - # @param shell_string [String] string that we want to escape - # @return [String] safe shell parameter string - def escape(shell_string) - Shellwords.escape(shell_string) - end + delegate :escape, to: Shellwords end end end diff --git a/lib/support_engine/shell/git.rb b/lib/support_engine/shell/git.rb index 392afd9..c54888d 100644 --- a/lib/support_engine/shell/git.rb +++ b/lib/support_engine/shell/git.rb @@ -17,7 +17,7 @@ class << self def call_in_path(path, command, options, raise_on_invalid_exit: true) result = SupportEngine::Shell::Utf8.call( "git -C #{path} #{command} #{options}", - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) result[:stdout].split("\n") diff --git a/lib/support_engine/shell/utf8.rb b/lib/support_engine/shell/utf8.rb index a80c4d4..e7836f9 100644 --- a/lib/support_engine/shell/utf8.rb +++ b/lib/support_engine/shell/utf8.rb @@ -16,7 +16,7 @@ def call(command_with_options, raise_on_invalid_exit: true) encode( Shell.call( command_with_options, - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) ) end @@ -30,7 +30,7 @@ def call_in_path(path, command, raise_on_invalid_exit: true) Shell.call_in_path( path, command, - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) ) end diff --git a/lib/support_engine/shell/yarn.rb b/lib/support_engine/shell/yarn.rb index ec992f4..ebc8539 100644 --- a/lib/support_engine/shell/yarn.rb +++ b/lib/support_engine/shell/yarn.rb @@ -13,7 +13,7 @@ class << self def call(command, options, raise_on_invalid_exit: true) Shell::Utf8.call( "yarn run --silent #{command} #{options}", - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) end @@ -26,7 +26,7 @@ def call_in_path(path, command, options, raise_on_invalid_exit: true) Shell::Utf8.call_in_path( path, "yarn run --silent #{command} #{options}", - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) end end diff --git a/spec/lib/support_engine/git/branch_spec.rb b/spec/lib/support_engine/git/branch_spec.rb index 79c47a7..dd1e839 100644 --- a/spec/lib/support_engine/git/branch_spec.rb +++ b/spec/lib/support_engine/git/branch_spec.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# rubocop:disable Capybara/FindAllFirst RSpec.describe_current do let(:commits_scope) { SupportEngine::Git::Commits } let(:path) { SupportEngine::Git::RepoBuilder::Master.location } @@ -55,7 +56,7 @@ context 'when master with branch' do let(:path) { SupportEngine::Git::RepoBuilder::Master.location } let(:branch) { 'master' } - let(:commit_hash) { commits_scope.all(path, branch: branch).first[:commit_hash] } + let(:commit_hash) { commits_scope.all(path, branch:).first[:commit_hash] } before { SupportEngine::Git::RepoBuilder::Master.bootstrap } @@ -79,7 +80,7 @@ context 'when master branch only' do let(:branch) { 'master' } let(:path) { SupportEngine::Git::RepoBuilder::MasterOnly.location } - let(:commit_hash) { commits_scope.all(path, branch: branch).first[:commit_hash] } + let(:commit_hash) { commits_scope.all(path, branch:).first[:commit_hash] } before { SupportEngine::Git::RepoBuilder::MasterOnly.bootstrap } @@ -137,3 +138,4 @@ end end end +# rubocop:enable Capybara/FindAllFirst diff --git a/spec/lib/support_engine/git/commits_spec.rb b/spec/lib/support_engine/git/commits_spec.rb index b3502d4..f901f0b 100644 --- a/spec/lib/support_engine/git/commits_spec.rb +++ b/spec/lib/support_engine/git/commits_spec.rb @@ -39,9 +39,9 @@ context 'when we want limited number of commits by time' do # on local machines timezone is in CET and Time.zone.now returns UTC - subject(:all) { described_class.all(path, since: since) } + subject(:all) { described_class.all(path, since:) } - let(:since) { Time.zone.now + 6.hours } + let(:since) { 6.hours.from_now } let(:path) { SupportEngine::Git::RepoBuilder::MasterMirror.location } # There won't be any commits from now @@ -73,7 +73,7 @@ end describe '.latest_by_day' do - subject(:latest_by_day) { described_class.latest_by_day(path, limit: limit) } + subject(:latest_by_day) { described_class.latest_by_day(path, limit:) } let(:limit) { nil } diff --git a/spec/lib/support_engine/git/gc_spec.rb b/spec/lib/support_engine/git/gc_spec.rb index 99db13b..1eed288 100644 --- a/spec/lib/support_engine/git/gc_spec.rb +++ b/spec/lib/support_engine/git/gc_spec.rb @@ -6,13 +6,13 @@ context 'when some files were introduced' do let(:path) { SupportEngine::Git::RepoBuilder::Master.location } - let(:introduced_file_name1) { rand.to_s } - let(:introduced_file_name2) { rand.to_s } + let(:first_introduced_file) { rand.to_s } + let(:second_introduced_file) { rand.to_s } let(:introduced) { SupportEngine::Git::Status.introduced(path) } before do - `echo change >> #{File.join(path, introduced_file_name1)}` - `echo change >> #{File.join(path, introduced_file_name2)}` + `echo change >> #{File.join(path, first_introduced_file)}` + `echo change >> #{File.join(path, second_introduced_file)}` reset end diff --git a/spec/lib/support_engine/git/ref_spec.rb b/spec/lib/support_engine/git/ref_spec.rb index e71f83e..6a250ed 100644 --- a/spec/lib/support_engine/git/ref_spec.rb +++ b/spec/lib/support_engine/git/ref_spec.rb @@ -29,7 +29,7 @@ end context 'when raise_on_invalid_exit false' do - subject(:head) { described_class.head(path, false) } + subject(:head) { described_class.head(path, raise_on_invalid_exit: false) } let(:path) { SupportEngine::Git::RepoBuilder::BrokenHeadRef.location } @@ -66,7 +66,7 @@ end describe '#head?' do - subject(:head?) { described_class.head?(described_class.head(path, false)) } + subject(:head?) { described_class.head?(described_class.head(path, raise_on_invalid_exit: false)) } context 'when valid head ref' do let(:path) { SupportEngine::Git::RepoBuilder::Master.location } diff --git a/spec/lib/support_engine/git/repo_builder/base_spec.rb b/spec/lib/support_engine/git/repo_builder/base_spec.rb index 85274d7..aa56e95 100644 --- a/spec/lib/support_engine/git/repo_builder/base_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/base_spec.rb @@ -33,12 +33,14 @@ let(:command) { 'command' } - before { described_class.const_set(:BOOTSTRAP_CMD, command) } + before { allow(described_class).to receive(:bootstrap_cmd).and_return(command) } - it 'expect to call, destroy and match shell result' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(command).and_return('test') + it 'expect to call, destroy and match shell result' do + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(command).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(command) end end @@ -60,8 +62,9 @@ context 'when dir does not exist' do it 'expect not to try to remove it' do - expect(FileUtils).not_to receive(:rm_r) + allow(FileUtils).to receive(:rm_r) destroy + expect(FileUtils).not_to have_received(:rm_r) end end end diff --git a/spec/lib/support_engine/git/repo_builder/broken_head_ref_mirror_spec.rb b/spec/lib/support_engine/git/repo_builder/broken_head_ref_mirror_spec.rb index 7494baf..4afd730 100644 --- a/spec/lib/support_engine/git/repo_builder/broken_head_ref_mirror_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/broken_head_ref_mirror_spec.rb @@ -12,9 +12,11 @@ end it 'expect to remove previous repo, clone mirror to a new one and return clone path' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Git).to have_received(:clone_mirror).with(*clone_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/broken_head_ref_spec.rb b/spec/lib/support_engine/git/repo_builder/broken_head_ref_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/broken_head_ref_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/broken_head_ref_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_bare_mirror_spec.rb b/spec/lib/support_engine/git/repo_builder/master_bare_mirror_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/master_bare_mirror_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_bare_mirror_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_mirror_spec.rb b/spec/lib/support_engine/git/repo_builder/master_mirror_spec.rb index 179c139..9f70dd2 100644 --- a/spec/lib/support_engine/git/repo_builder/master_mirror_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_mirror_spec.rb @@ -12,9 +12,11 @@ end it 'expect to remove previous repo, clone mirror to a new one and return clone path' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Git).to have_received(:clone_mirror).with(*clone_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_multiple_committers_spec.rb b/spec/lib/support_engine/git/repo_builder/master_multiple_committers_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/master_multiple_committers_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_multiple_committers_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_only_spec.rb b/spec/lib/support_engine/git/repo_builder/master_only_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/master_only_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_only_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_spec.rb b/spec/lib/support_engine/git/repo_builder/master_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/master_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_with_big_branch60_spec.rb b/spec/lib/support_engine/git/repo_builder/master_with_big_branch60_spec.rb index d1a594f..887eff6 100644 --- a/spec/lib/support_engine/git/repo_builder/master_with_big_branch60_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_with_big_branch60_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } after { described_class.destroy } diff --git a/spec/lib/support_engine/git/repo_builder/master_with_big_branch_mirror_spec.rb b/spec/lib/support_engine/git/repo_builder/master_with_big_branch_mirror_spec.rb index 463cb75..bbb349e 100644 --- a/spec/lib/support_engine/git/repo_builder/master_with_big_branch_mirror_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_with_big_branch_mirror_spec.rb @@ -12,9 +12,11 @@ end it 'expect to remove previous repo, clone mirror to a new one and return clone path' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Git).to have_received(:clone_mirror).with(*clone_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/master_with_big_branch_spec.rb b/spec/lib/support_engine/git/repo_builder/master_with_big_branch_spec.rb index d1a594f..887eff6 100644 --- a/spec/lib/support_engine/git/repo_builder/master_with_big_branch_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_with_big_branch_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } after { described_class.destroy } diff --git a/spec/lib/support_engine/git/repo_builder/master_with_history_spec.rb b/spec/lib/support_engine/git/repo_builder/master_with_history_spec.rb index d1a594f..887eff6 100644 --- a/spec/lib/support_engine/git/repo_builder/master_with_history_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_with_history_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } after { described_class.destroy } diff --git a/spec/lib/support_engine/git/repo_builder/master_with_weird_branch_spec.rb b/spec/lib/support_engine/git/repo_builder/master_with_weird_branch_spec.rb index d1a594f..887eff6 100644 --- a/spec/lib/support_engine/git/repo_builder/master_with_weird_branch_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/master_with_weird_branch_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } after { described_class.destroy } diff --git a/spec/lib/support_engine/git/repo_builder/no_master_mirror_spec.rb b/spec/lib/support_engine/git/repo_builder/no_master_mirror_spec.rb index 6f29577..54f2347 100644 --- a/spec/lib/support_engine/git/repo_builder/no_master_mirror_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/no_master_mirror_spec.rb @@ -12,9 +12,11 @@ end it 'expect to remove previous repo, clone mirror to a new one and return clone path' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Git).to receive(:clone_mirror).with(*clone_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Git).to have_received(:clone_mirror).with(*clone_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/no_master_spec.rb b/spec/lib/support_engine/git/repo_builder/no_master_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/no_master_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/no_master_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/outdated_gems_spec.rb b/spec/lib/support_engine/git/repo_builder/outdated_gems_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/outdated_gems_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/outdated_gems_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/outdated_gems_strict_spec.rb b/spec/lib/support_engine/git/repo_builder/outdated_gems_strict_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/outdated_gems_strict_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/outdated_gems_strict_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder/private_gem_spec.rb b/spec/lib/support_engine/git/repo_builder/private_gem_spec.rb index d1a594f..887eff6 100644 --- a/spec/lib/support_engine/git/repo_builder/private_gem_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/private_gem_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } after { described_class.destroy } diff --git a/spec/lib/support_engine/git/repo_builder/yarn_spec.rb b/spec/lib/support_engine/git/repo_builder/yarn_spec.rb index 694f050..aa784ca 100644 --- a/spec/lib/support_engine/git/repo_builder/yarn_spec.rb +++ b/spec/lib/support_engine/git/repo_builder/yarn_spec.rb @@ -1,15 +1,17 @@ # frozen_string_literal: true RSpec.describe_current do - describe 'BOOTSTRAP_CMD' do + describe '.bootstrap_cmd' do subject(:bootstrap) { described_class.bootstrap } - let(:shell_args) { described_class::BOOTSTRAP_CMD } + let(:shell_args) { described_class.bootstrap_cmd } it 'expect to remove previous repo, build new and return path to it' do - expect(described_class).to receive(:destroy) - expect(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') + allow(described_class).to receive(:destroy) + allow(SupportEngine::Shell).to receive(:call).with(shell_args).and_return('test') expect(bootstrap).to eq('test') + expect(described_class).to have_received(:destroy) + expect(SupportEngine::Shell).to have_received(:call).with(shell_args) end end end diff --git a/spec/lib/support_engine/git/repo_builder_spec.rb b/spec/lib/support_engine/git/repo_builder_spec.rb index 4daae78..d405544 100644 --- a/spec/lib/support_engine/git/repo_builder_spec.rb +++ b/spec/lib/support_engine/git/repo_builder_spec.rb @@ -8,9 +8,11 @@ let(:versions) { [version] } it 'expect to take all the versions and bootstrap all of them' do - expect(described_class).to receive(:versions) { versions } - expect(version).to receive(:bootstrap) + allow(described_class).to receive(:versions).and_return(versions) + allow(version).to receive(:bootstrap) bootstrap + expect(described_class).to have_received(:versions) + expect(version).to have_received(:bootstrap) end end @@ -21,9 +23,11 @@ let(:versions) { [version] } it 'expect to take all the versions and destroy all of them' do - expect(described_class).to receive(:versions) { versions } - expect(version).to receive(:destroy) + allow(described_class).to receive(:versions).and_return(versions) + allow(version).to receive(:destroy) destroy + expect(described_class).to have_received(:versions) + expect(version).to have_received(:destroy) end end diff --git a/spec/lib/support_engine/git/status_spec.rb b/spec/lib/support_engine/git/status_spec.rb index 662e615..46ff1f6 100644 --- a/spec/lib/support_engine/git/status_spec.rb +++ b/spec/lib/support_engine/git/status_spec.rb @@ -21,32 +21,32 @@ end context 'when some files were introduced' do - let(:introduced_file_name1) { rand.to_s } - let(:introduced_file_name2) { rand.to_s } + let(:first_introduced_file) { rand.to_s } + let(:second_introduced_file) { rand.to_s } before do - `echo change >> #{File.join(path, introduced_file_name1)}` - `echo change >> #{File.join(path, introduced_file_name2)}` + `echo change >> #{File.join(path, first_introduced_file)}` + `echo change >> #{File.join(path, second_introduced_file)}` end it { expect(introduced.size).to eq 2 } - it { is_expected.to include introduced_file_name1 } - it { is_expected.to include introduced_file_name2 } + it { is_expected.to include first_introduced_file } + it { is_expected.to include second_introduced_file } end context 'when some files were introduced and changed' do - let(:introduced_file_name1) { rand.to_s } - let(:introduced_file_name2) { rand.to_s } + let(:first_introduced_file) { rand.to_s } + let(:second_introduced_file) { rand.to_s } before do `echo change >> #{File.join(path, 'master.rb')}` - `echo change >> #{File.join(path, introduced_file_name1)}` - `echo change >> #{File.join(path, introduced_file_name2)}` + `echo change >> #{File.join(path, first_introduced_file)}` + `echo change >> #{File.join(path, second_introduced_file)}` end it { expect(introduced.size).to eq 2 } - it { is_expected.to include introduced_file_name1 } - it { is_expected.to include introduced_file_name2 } + it { is_expected.to include first_introduced_file } + it { is_expected.to include second_introduced_file } end end end diff --git a/spec/lib/support_engine/git_spec.rb b/spec/lib/support_engine/git_spec.rb index ecde764..b0d9c84 100644 --- a/spec/lib/support_engine/git_spec.rb +++ b/spec/lib/support_engine/git_spec.rb @@ -133,12 +133,12 @@ let(:ref) { '7987d360dc73ac64ead4a26f8a451822e37788f5' } let(:message) do "Note: checking out '7987d360dc73ac64ead4a26f8a451822e37788f5'.\n\n" \ - "You are in 'detached HEAD' state. You can look around, make experimental\n" \ - "changes and commit them, and you can discard any commits you make in this\n" \ - "state without impacting any branches by performing another checkout.\n\n" \ - "If you want to create a new branch to retain commits you create, you may\n" \ - "do so (now or later) by using -b with the checkout command again. Example:\n\n " \ - "git checkout -b \n\nHEAD is now at 7987d36... master commit" + "You are in 'detached HEAD' state. You can look around, make experimental\n" \ + "changes and commit them, and you can discard any commits you make in this\n" \ + "state without impacting any branches by performing another checkout.\n\n" \ + "If you want to create a new branch to retain commits you create, you may\n" \ + "do so (now or later) by using -b with the checkout command again. Example:\n\n " \ + "git checkout -b \n\nHEAD is now at 7987d36... master commit" end it { is_expected.to be true } diff --git a/spec/lib/support_engine/rspec_locator_spec.rb b/spec/lib/support_engine/rspec_locator_spec.rb index 64d9fa3..1829cf5 100644 --- a/spec/lib/support_engine/rspec_locator_spec.rb +++ b/spec/lib/support_engine/rspec_locator_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +# rubocop:disable RSpec/SpecFilePathFormat RSpec.describe SupportEngine::RSpecLocator do - pending + pending 'Not yet implemented' end +# rubocop:enable RSpec/SpecFilePathFormat diff --git a/spec/lib/support_engine/shell/utf8_spec.rb b/spec/lib/support_engine/shell/utf8_spec.rb index 17114d9..441151f 100644 --- a/spec/lib/support_engine/shell/utf8_spec.rb +++ b/spec/lib/support_engine/shell/utf8_spec.rb @@ -9,12 +9,13 @@ let(:command_with_options) { 'ls' } let(:options) { { raise_on_invalid_exit: true } } - after { shell_result } - it 'expect to run shell and encode' do - expect(SupportEngine::Shell).to receive(:call) + allow(SupportEngine::Shell).to receive(:call) .with(command_with_options, options).and_return(true) - expect(described_class).to receive(:encode).with(true) + allow(described_class).to receive(:encode).with(true) + shell_result + expect(SupportEngine::Shell).to have_received(:call).with(command_with_options, options) + expect(described_class).to have_received(:encode).with(true) end end @@ -28,11 +29,12 @@ let(:options) { { raise_on_invalid_exit: true } } let(:shell_args) { [path, command_with_options, options] } - after { shell_result } - it 'expect to call shell in path and encode' do - expect(SupportEngine::Shell).to receive(:call_in_path).with(*shell_args).and_return(true) - expect(described_class).to receive(:encode).with(true) + allow(SupportEngine::Shell).to receive(:call_in_path).with(*shell_args).and_return(true) + allow(described_class).to receive(:encode).with(true) + shell_result + expect(SupportEngine::Shell).to have_received(:call_in_path).with(*shell_args) + expect(described_class).to have_received(:encode).with(true) end end diff --git a/spec/lib/support_engine/shell/yarn_spec.rb b/spec/lib/support_engine/shell/yarn_spec.rb index 31933b2..f9597b0 100644 --- a/spec/lib/support_engine/shell/yarn_spec.rb +++ b/spec/lib/support_engine/shell/yarn_spec.rb @@ -9,13 +9,14 @@ let(:args) do [ "yarn run --silent #{command} #{options}", - raise_on_invalid_exit: true + { raise_on_invalid_exit: true } ] end it 'expect to run yarn in shell' do - expect(SupportEngine::Shell::Utf8).to receive(:call).with(*args) + allow(SupportEngine::Shell::Utf8).to receive(:call).with(*args) shell_result + expect(SupportEngine::Shell::Utf8).to have_received(:call).with(*args) end end diff --git a/spec/lib/support_engine/shell_spec.rb b/spec/lib/support_engine/shell_spec.rb index 88215a0..8d44c6c 100644 --- a/spec/lib/support_engine/shell_spec.rb +++ b/spec/lib/support_engine/shell_spec.rb @@ -5,7 +5,7 @@ subject(:shell_result) do described_class.call( command_with_options, - raise_on_invalid_exit: raise_on_invalid_exit + raise_on_invalid_exit: ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 516ffd4..2a9a094 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,8 +15,10 @@ require 'support_engine/git/repo_builder' require 'support_engine/rspec_locator' +# rubocop:disable Rails/TimeZoneAssignment # Set default timezone Time.zone = 'UTC' +# rubocop:enable Rails/TimeZoneAssignment SimpleCov.minimum_coverage 98.5