Skip to content

Commit

Permalink
Merge pull request #20 from chubchenko/enhancement/rubocop-suggestions
Browse files Browse the repository at this point in the history
Add RuboCop suggestions
  • Loading branch information
chubchenko authored Dec 20, 2021
2 parents 9c58f09 + 5fc98d9 commit 67c13f5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 79 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ Layout/LineLength:

Style/FrozenStringLiteralComment:
Enabled: true

############### Style ###############

RSpec/DescribeClass:
IgnoredMetadata:
type:
- task

RSpec/ExampleLength:
Enabled: false
1 change: 1 addition & 0 deletions lib/tasks/defaults.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

namespace :load do
desc "Load default configuration for slacky"
task :defaults do
append :linked_files, "config/slacky.yml"
end
Expand Down
9 changes: 3 additions & 6 deletions spec/capistrano/slacky/fanout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
RSpec.describe Capistrano::Slacky::Fanout do
describe ".call" do
let(:backend) { instance_double(SSHKit::Backend::Netssh) }
let(:payload) do
{username: "ChatOps", text: "Hello, Slacky!"}
end

before do
allow(Capistrano::Slacky::On).to receive(:on)
.with(within: :shared)
.and_yield
end

before do
allow(SSHKit::Backend).to receive(:current).and_return(backend)
allow(backend).to receive(:capture).with(:cat, "config/slacky.yml").and_return(
"https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
Expand All @@ -19,10 +20,6 @@
allow(Net::HTTP).to receive(:post_form)
end

let(:payload) do
{username: "ChatOps", text: "Hello, Slacky!"}
end

it "makes an HTTP POST request" do
described_class.call(payload: payload)

Expand Down
2 changes: 1 addition & 1 deletion spec/capistrano/slacky/messaging/null_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Capistrano::Slacky::Messaging::Null do
describe "#payload_for" do
subject(:null) { described_class.new(env: Capistrano::Configuration.env) }
let(:null) { described_class.new(env: Capistrano::Configuration.env) }

context "when action is `updated`" do
before do
Expand Down
5 changes: 5 additions & 0 deletions spec/support/config/capistrano.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# frozen_string_literal: true

namespace :deploy do
desc "Dummy for a successful deployment"
task :finishing

desc "Dummy for successful rollback"
task :finishing_rollback

desc "Dummy for failure deployment or rollback"
task :failed
end
12 changes: 7 additions & 5 deletions spec/tasks/defaults_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

RSpec.describe "load:defaults" do
it "adds the file to the linked files" do
expect do
Rake::Task["load:defaults"].invoke
end.to change { Capistrano::Configuration.env.fetch(:linked_files) }.to(["config/slacky.yml"])
RSpec.describe "load", type: :task do
describe "defaults" do
it "adds the file to the linked files" do
expect do
Rake::Task["load:defaults"].invoke
end.to change { Capistrano::Configuration.env.fetch(:linked_files) }.to(["config/slacky.yml"])
end
end
end
136 changes: 69 additions & 67 deletions spec/tasks/slacky_spec.rb
Original file line number Diff line number Diff line change
@@ -1,105 +1,107 @@
# frozen_string_literal: true

RSpec.describe "slacky:updated" do
it "slacky after a successful deployment" do
allow(Capistrano::Slacky::Runner).to receive(:call)
RSpec.describe "slacky", type: :task do
describe "updated" do
it "slacky after a successful deployment" do
allow(Capistrano::Slacky::Runner).to receive(:call)

Rake::Task["slacky:updated"].invoke
Rake::Task["slacky:updated"].invoke

expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :updated
)
end
expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :updated
)
end

it "invokes slacky:updated after deploy:finishing" do
allow(Rake::Task["slacky:updated"]).to receive(:invoke)
it "invokes slacky:updated after deploy:finishing" do
allow(Rake::Task["slacky:updated"]).to receive(:invoke)

Rake::Task["deploy:finishing"].execute
Rake::Task["deploy:finishing"].execute

expect(Rake::Task["slacky:updated"]).to have_received(:invoke)
expect(Rake::Task["slacky:updated"]).to have_received(:invoke)
end
end
end

RSpec.describe "slacky:reverted" do
before { allow(Capistrano::Slacky::Command::CurrentRevision).to receive(:call) }
describe "reverted" do
before { allow(Capistrano::Slacky::Command::CurrentRevision).to receive(:call) }

it "slacky after successful rollback" do
allow(Capistrano::Slacky::Runner).to receive(:call)
it "slacky after successful rollback" do
allow(Capistrano::Slacky::Runner).to receive(:call)

Rake::Task["slacky:reverted"].invoke
Rake::Task["slacky:reverted"].invoke

expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :reverted
)
end
expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :reverted
)
end

it "invokes slacky:reverted after deploy:finishing_rollback" do
allow(Rake::Task["slacky:reverted"]).to receive(:invoke)
it "invokes slacky:reverted after deploy:finishing_rollback" do
allow(Rake::Task["slacky:reverted"]).to receive(:invoke)

Rake::Task["deploy:finishing_rollback"].execute
Rake::Task["deploy:finishing_rollback"].execute

expect(Rake::Task["slacky:reverted"]).to have_received(:invoke)
end
expect(Rake::Task["slacky:reverted"]).to have_received(:invoke)
end

it "invokes slacky:ensure_current_revision before slacky:reverted" do
expect(Rake::Task["slacky:reverted"].prerequisites).to match_array("ensure_current_revision")
it "invokes slacky:ensure_current_revision before slacky:reverted" do
expect(Rake::Task["slacky:reverted"].prerequisites).to match_array("ensure_current_revision")
end
end
end

RSpec.describe "slacky:failed" do
before do
allow(Capistrano::Slacky::Runner).to receive(:call)
end
describe "failed" do
before do
allow(Capistrano::Slacky::Runner).to receive(:call)
end

it "Slacky after failure deployment or rollback" do
Rake::Task["slacky:failed"].invoke
it "Slacky after failure deployment or rollback" do
Rake::Task["slacky:failed"].invoke

expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :failed
)
end
expect(Capistrano::Slacky::Runner).to have_received(:call).with(
action: :failed
)
end

it "invokes slacky:failed after deploy:failed" do
allow(Rake::Task["slacky:failed"]).to receive(:invoke)
it "invokes slacky:failed after deploy:failed" do
allow(Rake::Task["slacky:failed"]).to receive(:invoke)

Rake::Task["deploy:failed"].execute
Rake::Task["deploy:failed"].execute

expect(Rake::Task["slacky:failed"]).to have_received(:invoke)
expect(Rake::Task["slacky:failed"]).to have_received(:invoke)
end
end
end

RSpec.describe "slacky:ping" do
it "pings all available tasks" do
allow(Capistrano::Slacky::Runner).to receive(:call)
describe "ping" do
it "pings all available tasks" do
allow(Capistrano::Slacky::Runner).to receive(:call)

Rake::Task["slacky:ping"].invoke
Rake::Task["slacky:ping"].invoke

expect(Capistrano::Slacky::Runner).to have_received(:call).exactly(3).times
expect(Capistrano::Slacky::Runner).to have_received(:call).exactly(3).times
end
end
end

RSpec.describe "slacky:ensure_current_revision" do
context "when :current_revision is empty" do
before { allow(Capistrano::Slacky::Command::CurrentRevision).to receive(:call).and_return("2eab27b") }
describe "ensure_current_revision" do
context "when :current_revision is empty" do
before { allow(Capistrano::Slacky::Command::CurrentRevision).to receive(:call).and_return("2eab27b") }

around do |example|
previous = Capistrano::Configuration.env.delete(:current_revision)
example.run
Capistrano::Configuration.env.set(:current_revision, previous)
end
around do |example|
previous = Capistrano::Configuration.env.delete(:current_revision)
example.run
Capistrano::Configuration.env.set(:current_revision, previous)
end

it "sets :current_revision" do
Rake::Task["slacky:ensure_current_revision"].execute
it "sets :current_revision" do
Rake::Task["slacky:ensure_current_revision"].execute

expect(Capistrano::Configuration.env.fetch(:current_revision)).to eq("2eab27b")
expect(Capistrano::Configuration.env.fetch(:current_revision)).to eq("2eab27b")
end
end
end

context "when :current_revision is not empty" do
it "does not set :current_revision" do
Rake::Task["slacky:ensure_current_revision"].execute
context "when :current_revision is not empty" do
it "does not set :current_revision" do
Rake::Task["slacky:ensure_current_revision"].execute

expect(Capistrano::Configuration.env.fetch(:current_revision)).to eq("02c4c96")
expect(Capistrano::Configuration.env.fetch(:current_revision)).to eq("02c4c96")
end
end
end
end

0 comments on commit 67c13f5

Please sign in to comment.