Sha256: af2c8463e1e92cc3d5c3bb2304701f5e77570cda8be247045f64f2360a343f83

Contents?: true

Size: 1.54 KB

Versions: 32

Compression:

Stored size: 1.54 KB

Contents

#
# Copyright:: Copyright (c) 2016 Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require "mixlib/shellout"

RSpec.shared_context("setup_git_committer_config") do

  def _have_git_config_key?(key)
    cmd = Mixlib::ShellOut.new("git config --global #{key}", returns: [0, 1])
    cmd.run_command
    cmd.error!
    cmd.status.success?
  end

  def _git_config(subcommand_args)
    cmd = Mixlib::ShellOut.new("git config --global #{subcommand_args}")
    cmd.run_command
    cmd.error!
    cmd
  end

  before(:all) do
    unless _have_git_config_key?("user.name")
      _git_config("user.name \"chefdk_rspec_user\"")
    end
    unless _have_git_config_key?("user.email")
      _git_config("user.email \"chefdk_rspec_user@example.com\"")
    end
  end

  after(:all) do
    if _git_config("user.name").stdout.include?("chefdk_rspec_user")
      _git_config("--unset user.name")
    end
    if _git_config("user.email").stdout.include?("chefdk_rspec_user")
      _git_config("--unset user.email")
    end
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
chef-dk-4.13.3 spec/shared/setup_git_committer_config.rb
chef-dk-4.12.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.11.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.10.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.9.7 spec/shared/setup_git_committer_config.rb
chef-dk-4.7.73 spec/shared/setup_git_committer_config.rb
chef-dk-3.13.1 spec/shared/setup_git_committer_config.rb
chef-dk-4.6.35 spec/shared/setup_git_committer_config.rb
chef-dk-3.12.10 spec/shared/setup_git_committer_config.rb
chef-dk-3.12.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.5.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.4.27 spec/shared/setup_git_committer_config.rb
chef-dk-4.3.13 spec/shared/setup_git_committer_config.rb
chef-dk-4.2.0 spec/shared/setup_git_committer_config.rb
chef-dk-4.1.7 spec/shared/setup_git_committer_config.rb
chef-dk-3.11.3 spec/shared/setup_git_committer_config.rb
chef-dk-3.10.1 spec/shared/setup_git_committer_config.rb
chef-dk-4.0.60 spec/shared/setup_git_committer_config.rb
chef-dk-3.0.36 spec/shared/setup_git_committer_config.rb
chef-dk-1.6.11 spec/shared/setup_git_committer_config.rb