Skip to content

Commit

Permalink
Add worktree spec
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Sep 30, 2024
1 parent 72e6be9 commit d860154
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
9 changes: 5 additions & 4 deletions spec/popups/branch_popup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@

it "creates and checks out a new local branch when choosing a remote"

it "creates and checks out a new local branch when name doesn't match existing local branch", skip: "requires FZF sorter" do # rubocop:disable Layout/LineLength
it "creates and checks out a new local branch when name doesn't match existing local branch" do
nvim.keys("bl")
nvim.keys("this branch doesnt exist<cr>")
nvim.keys("master<cr>")
expect(git.current_branch).to eq "this-branch-doesnt-exist"
nvim.keys("tmp<cr>") # Enter branch that doesn't exist
nvim.keys("mas<cr>") # Set base branch

expect(git.current_branch).to eq "tmp"
end
end

Expand Down
58 changes: 58 additions & 0 deletions spec/popups/worktree_popup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "Worktree Popup", :git, :nvim do
let(:dir) { "worktree_test_#{SecureRandom.hex(4)}" }

after do # Cleanup worktree dirs
Dir[File.join(Dir.tmpdir, "worktree_test_*")].each do |tmpdir|
FileUtils.rm_rf(tmpdir)
end
end

describe "Actions" do
describe "Checkout" do
before do
git.branch("worktree-test").checkout
git.branch("master").checkout
end

it "creates a worktree for an existing branch and checks it out", :aggregate_failures do
nvim.keys("ww") # Open popup/action
nvim.keys("wor<cr>") # Select "worktree-test" branch
nvim.keys("<cr>#{dir}<cr>") # go up level, new folder name

expect(git.worktrees.map(&:dir).last).to match(%r{/#{dir}$})
expect(nvim.cmd("pwd").first).to match(%r{/#{dir}$})
end
end

describe "Create" do
before do
git.branch("worktree-test").checkout
git.branch("master").checkout
end

it "creates a worktree for a new branch and checks it out", :aggregate_failures do
nvim.input("create-worktree-test") # Branch name

nvim.keys("wW") # Open popup/action
nvim.keys("<cr>#{dir}<cr>") # go up level, new folder name
nvim.keys("mas<cr>") # Set base branch to 'master'

expect(git.worktrees.map(&:dir).last).to match(%r{/#{dir}$})
expect(nvim.cmd("pwd").first).to match(%r{/#{dir}$})
end
end

describe "Goto" do
end

describe "Move" do
end

describe "Delete" do
end
end
end
4 changes: 3 additions & 1 deletion spec/support/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def dir_name(name)
name.match(%r{[^/]+/(?<dir_name>[^\.]+)})[:dir_name]
end

def ensure_installed(name)
def ensure_installed(name, build: nil)
tmp = File.join(PROJECT_DIR, "tmp")
FileUtils.mkdir_p(tmp)

Expand All @@ -17,7 +17,9 @@ def ensure_installed(name)
puts "Downloading dependency #{name} to #{dir}"
Dir.mkdir(dir)
Git.clone("[email protected]:#{name}.git", dir)
Dir.chdir(dir) { system(build) } if build.present?
end

ensure_installed "nvim-lua/plenary.nvim"
ensure_installed "nvim-telescope/telescope.nvim"
ensure_installed "nvim-telescope/telescope-fzf-native.nvim", build: "make"

0 comments on commit d860154

Please sign in to comment.