diff options
Diffstat (limited to 'spec/integration/dependabot/git_spec.rb')
| -rw-r--r-- | spec/integration/dependabot/git_spec.rb | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/spec/integration/dependabot/git_spec.rb b/spec/integration/dependabot/git_spec.rb index 9dfabcb..8dea207 100644 --- a/spec/integration/dependabot/git_spec.rb +++ b/spec/integration/dependabot/git_spec.rb @@ -1,24 +1,25 @@ # frozen_string_literal: true RSpec.describe ::Dependabot::Git do - def setup_git_repo(path) - system "git init --quiet #{path}" - system "git config user.email you@example.com" - system "git config user.name example" - system "echo 'hello' > README.md" - system "git add README.md" - system "git commit --quiet --no-gpg-sign -m 'initial commit'" - system "echo 'change' > README.md" + def within_git_repo + within_tmp_dir do |path| + system "git init --quiet #{path}" + system "git config user.email you@example.com" + system "git config user.name example" + system "echo 'hello' > README.md" + system "git add README.md" + system "git commit --quiet --no-gpg-sign -m 'initial commit'" + system "echo 'change' > README.md" + yield described_class.new(path) + end end describe "#checkout" do context "when the branch does not exist" do - let(:branch_name) { "example" } + let(:branch_name) { SecureRandom.uuid } it "creates a new branch" do - within_tmp_dir do |path| - setup_git_repo(path) - subject = described_class.new(path) + within_git_repo do |subject| subject.checkout(branch: branch_name) expect(`git branch`).to include(branch_name) @@ -26,9 +27,21 @@ RSpec.describe ::Dependabot::Git do end it "switches to the new branch" do - within_tmp_dir do |path| - setup_git_repo(path) - subject = described_class.new(path) + within_git_repo do |subject| + subject.checkout(branch: branch_name) + + expect(File.read(".git/HEAD").chomp).to eql("ref: refs/heads/#{branch_name}") + end + end + end + + context "when the branch already exists" do + let(:branch_name) { SecureRandom.uuid } + + it "switches to that branch" do + within_git_repo do |subject| + system "git branch #{branch_name}" + subject.checkout(branch: branch_name) expect(File.read(".git/HEAD").chomp).to eql("ref: refs/heads/#{branch_name}") @@ -40,9 +53,7 @@ RSpec.describe ::Dependabot::Git do describe "#commit" do context "when a tracked file is changed" do def within_dir - within_tmp_dir do |path| - setup_git_repo(path) - subject = described_class.new(path) + within_git_repo do |subject| subject.checkout(branch: "example") subject.commit(all: true, message: "The message") yield |
