Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1797 from mattbrictson/scm-plugin-class
Change SCMs to inherit from new SCM::Plugin base class
- Loading branch information
Showing
10 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "capistrano/plugin" | ||
require "capistrano/scm" | ||
|
||
# Base class for all built-in and third-party SCM plugins. Notice that this | ||
# class doesn't really do anything other than provide an `scm?` predicate. This | ||
# tells Capistrano that the plugin provides SCM functionality. All other plugin | ||
# features are inherited from Capistrano::Plugin. | ||
# | ||
class Capistrano::SCM::Plugin < Capistrano::Plugin | ||
def scm? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
spec/lib/capistrano/configuration/plugin_installer_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
require "spec_helper" | ||
require "capistrano/plugin" | ||
require "capistrano/scm/plugin" | ||
|
||
module Capistrano | ||
class Configuration | ||
class ExamplePlugin < Capistrano::Plugin | ||
def set_defaults | ||
set_if_empty :example_variable, "foo" | ||
end | ||
|
||
def define_tasks | ||
task :example | ||
task :example_prerequisite | ||
end | ||
|
||
def register_hooks | ||
before :example, :example_prerequisite | ||
end | ||
end | ||
|
||
class ExampleSCMPlugin < Capistrano::SCM::Plugin | ||
end | ||
|
||
describe PluginInstaller do | ||
include Capistrano::DSL | ||
|
||
let(:installer) { PluginInstaller.new } | ||
let(:options) { {} } | ||
let(:plugin) { ExamplePlugin.new } | ||
|
||
before do | ||
installer.install(plugin, **options) | ||
end | ||
|
||
after do | ||
Rake::Task.clear | ||
Capistrano::Configuration.reset! | ||
end | ||
|
||
context "installing plugin" do | ||
it "defines tasks" do | ||
expect(Rake::Task[:example]).to_not be_nil | ||
expect(Rake::Task[:example_prerequisite]).to_not be_nil | ||
end | ||
|
||
it "registers hooks" do | ||
task = Rake::Task[:example] | ||
expect(task.prerequisites).to eq([:example_prerequisite]) | ||
end | ||
|
||
it "sets defaults when load:defaults is invoked" do | ||
expect(fetch(:example_variable)).to be_nil | ||
invoke "load:defaults" | ||
expect(fetch(:example_variable)).to eq("foo") | ||
end | ||
|
||
it "doesn't say an SCM is installed" do | ||
expect(installer.scm_installed?).to be_falsey | ||
end | ||
end | ||
|
||
context "installing plugin class" do | ||
let(:plugin) { ExamplePlugin } | ||
|
||
it "defines tasks" do | ||
expect(Rake::Task[:example]).to_not be_nil | ||
expect(Rake::Task[:example_prerequisite]).to_not be_nil | ||
end | ||
end | ||
|
||
context "installing plugin without hooks" do | ||
let(:options) { { load_hooks: false } } | ||
|
||
it "doesn't register hooks" do | ||
task = Rake::Task[:example] | ||
expect(task.prerequisites).to be_empty | ||
end | ||
end | ||
|
||
context "installing plugin and loading immediately" do | ||
let(:options) { { load_immediately: true } } | ||
|
||
it "sets defaults immediately" do | ||
expect(fetch(:example_variable)).to eq("foo") | ||
end | ||
end | ||
|
||
context "installing an SCM plugin" do | ||
let(:plugin) { ExampleSCMPlugin } | ||
|
||
it "says an SCM is installed" do | ||
expect(installer.scm_installed?).to be_truthy | ||
end | ||
end | ||
end | ||
end | ||
end |