Skip to content

Commit

Permalink
Add tests for run_locally and run_locally! [#1822]
Browse files Browse the repository at this point in the history
  • Loading branch information
edspc committed Oct 3, 2023
1 parent 5c35b00 commit 0631e1b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions spec/lib/capistrano/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DummyDSL
# see also - spec/integration/dsl_spec.rb
describe DSL do
let(:dsl) { DummyDSL.new }
let(:block) { proc {} }

describe "#t" do
before do
Expand Down Expand Up @@ -121,5 +122,72 @@ class DummyDSL
end
end
end

describe "#run_locally" do
context "dry run" do
before do
dsl.set(:sshkit_backend, SSHKit::Backend::Printer)
@localhost = mock("localhost")
SSHKit::Host.expects(:new).with(:local).returns(@localhost)
end

it "will call SSHKit printer backend" do
printer = mock("printer")
printer.expects(:run).with

SSHKit::Backend::Printer.expects(:new).with(@localhost) { |&block| expect(block).to be(block) }.returns(printer)

expect(dsl.dry_run?).to be_truthy
dsl.run_locally(&block)
end
end

context "regular run" do
before do
dsl.set(:sshkit_backend, nil)
end

it "will call SSHKit local backend" do
local = mock("local")
local.expects(:run).with

SSHKit::Backend::Local.expects(:new).with { |&block| expect(block).to be(block) }.returns(local)

expect(dsl.dry_run?).to be_falsey
dsl.run_locally(&block)
end
end
end

describe "#run_locally!" do
before do
local = mock("local")
local.expects(:run).with

SSHKit::Backend::Local.expects(:new).with { |&block| expect(block).to be(block) }.returns(local)
end

context "dry run" do
before do
dsl.set(:sshkit_backend, SSHKit::Backend::Printer)
end

it "will call SSHKit local backend" do
expect(dsl.dry_run?).to be_truthy
dsl.run_locally!(&block)
end
end

context "regular run" do
before do
dsl.set(:sshkit_backend, nil)
end

it "will call SSHKit local backend" do
expect(dsl.dry_run?).to be_falsey
dsl.run_locally!(&block)
end
end
end
end
end

0 comments on commit 0631e1b

Please sign in to comment.