Sha256: 93d50372bb3696a1911c1e15a1e3ee4bbc5faa2ba6c52b16309abcf0e5e63d10

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 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

13 entries across 13 versions & 1 rubygems

Version Path
chef-dk-3.9.0 spec/shared/setup_git_committer_config.rb
chef-dk-3.8.14 spec/shared/setup_git_committer_config.rb
chef-dk-3.7.23 spec/shared/setup_git_committer_config.rb
chef-dk-3.6.57 spec/shared/setup_git_committer_config.rb
chef-dk-3.5.13 spec/shared/setup_git_committer_config.rb
chef-dk-2.6.2 spec/shared/setup_git_committer_config.rb
chef-dk-3.4.38 spec/shared/setup_git_committer_config.rb
chef-dk-2.6.1 spec/shared/setup_git_committer_config.rb
chef-dk-3.3.23 spec/shared/setup_git_committer_config.rb
chef-dk-3.2.30 spec/shared/setup_git_committer_config.rb
chef-dk-2.5.13 spec/shared/setup_git_committer_config.rb
chef-dk-3.1.0 spec/shared/setup_git_committer_config.rb
chef-dk-2.5.3 spec/shared/setup_git_committer_config.rb