Skip to content

Commit

Permalink
Introduce a new Run module (#39)
Browse files Browse the repository at this point in the history
This will allow us to add new functionality aside from rebasing
branches.
  • Loading branch information
mockdeep authored Jul 19, 2023
1 parent 6a928db commit 78eafb0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion exe/baes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

require_relative "../lib/baes"

Baes::Actions::Rebase.call(ARGV)
Baes::Actions::Run.call(ARGV)
1 change: 1 addition & 0 deletions lib/baes/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ module Baes::Actions; end
require_relative "actions/build_tree"
require_relative "actions/load_configuration"
require_relative "actions/rebase"
require_relative "actions/run"
5 changes: 2 additions & 3 deletions lib/baes/actions/rebase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ class Baes::Actions::Rebase
class << self
include Baes::Configuration::Helpers

# parse options and rebase branches
def call(options)
Baes::Actions::LoadConfiguration.call(options)
# rebase branches
def call
branches = generate_branches
root_branch = find_root_branch(branches)
Baes::Actions::BuildTree.call(branches, root_branch: root_branch)
Expand Down
11 changes: 11 additions & 0 deletions lib/baes/actions/run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# top-level class to parse options and run the command
module Baes::Actions::Run
# parse options and execute command
def self.call(options)
Baes::Actions::LoadConfiguration.call(options)

Baes::Actions::Rebase.call
end
end
12 changes: 12 additions & 0 deletions spec/baes/actions/load_configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# frozen_string_literal: true

RSpec.describe Baes::Actions::LoadConfiguration, "#call" do
it "sets the dry_run configuration given --dry-run" do
described_class.call(["--dry-run"])

expect(Baes::Configuration.dry_run?).to be(true)
end

it "displays the help and exits when given -h" do
expect { described_class.call(["-h"]) }
.to raise_error(SystemExit)

expect(Baes::Configuration.output.string).to include("prints this help")
end

it "sets the root_name configuration given --root" do
described_class.call(["--root", "staging"])

expect(Baes::Configuration.root_name).to eq("staging")
end

it "enables auto_skip given --auto-skip" do
described_class.call(["--auto-skip"])

Expand Down
15 changes: 9 additions & 6 deletions spec/baes/actions/rebase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
it "rebases branches on main" do
FakeGit.branch_names = ["main", "my_branch"]

expect { described_class.call([]) }
expect { described_class.call }
.to rebase("my_branch").on("main")
end

it "rebases branches on master" do
FakeGit.branch_names = ["master", "my_branch"]

expect { described_class.call([]) }
expect { described_class.call }
.to rebase("my_branch").on("master")
end

it "rebases chained branches" do
FakeGit.branch_names = ["main", "my_branch_1", "my_branch_2"]

expect { described_class.call([]) }
expect { described_class.call }
.to rebase("my_branch_1").on("main")
.and(rebase("my_branch_2").on("my_branch_1"))
end
Expand All @@ -29,8 +29,9 @@
FakeGit.branch_names = ["main", "my_branch_1", "my_branch_2"]
output = StringIO.new
Baes::Configuration.output = output
Baes::Configuration.dry_run = true

described_class.call(["--dry-run"])
described_class.call

expected_output = <<~TEXT
main
Expand All @@ -43,16 +44,18 @@

it "does not rebase branches" do
FakeGit.branch_names = ["main", "my_branch_1", "my_branch_2"]
Baes::Configuration.dry_run = true

expect { described_class.call(["--dry-run"]) }
expect { described_class.call }
.not_to(rebase("my_branch_1").on("main"))
end
end

it "uses a given base branch" do
FakeGit.branch_names = ["staging", "my_branch_1", "my_branch_2"]
Baes::Configuration.root_name = "staging"

expect { described_class.call(["--root", "staging"]) }
expect { described_class.call }
.to rebase("my_branch_1").on("staging")
.and(rebase("my_branch_2").on("my_branch_1"))
end
Expand Down
22 changes: 22 additions & 0 deletions spec/baes/actions/run_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

RSpec.describe Baes::Actions::Run do
describe ".call" do
it "loads configuration" do
FakeGit.branch_names = ["main", "my_branch"]
options = ["--dry-run"]

described_class.call(options)

expect(Baes::Configuration.dry_run?).to be(true)
end

it "rebases branches" do
FakeGit.branch_names = ["main", "my_branch"]

described_class.call([])

expect(FakeGit.rebases).to eq([["my_branch", "main"]])
end
end
end

0 comments on commit 78eafb0

Please sign in to comment.