diff --git a/.rubocop.yml b/.rubocop.yml index 3d6c7fb..8a75458 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -21,3 +21,13 @@ Layout/LineLength: Style/FrozenStringLiteralComment: Enabled: true + +############### Style ############### + +RSpec/DescribeClass: + IgnoredMetadata: + type: + - task + +RSpec/ExampleLength: + Enabled: false diff --git a/lib/tasks/defaults.rake b/lib/tasks/defaults.rake index faa088d..b3848b8 100644 --- a/lib/tasks/defaults.rake +++ b/lib/tasks/defaults.rake @@ -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 diff --git a/spec/capistrano/slacky/fanout_spec.rb b/spec/capistrano/slacky/fanout_spec.rb index ea6c8f7..2042e9c 100644 --- a/spec/capistrano/slacky/fanout_spec.rb +++ b/spec/capistrano/slacky/fanout_spec.rb @@ -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" @@ -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) diff --git a/spec/capistrano/slacky/messaging/null_spec.rb b/spec/capistrano/slacky/messaging/null_spec.rb index 5c251f6..29e90ed 100644 --- a/spec/capistrano/slacky/messaging/null_spec.rb +++ b/spec/capistrano/slacky/messaging/null_spec.rb @@ -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 diff --git a/spec/support/config/capistrano.rake b/spec/support/config/capistrano.rake index 7108394..de63ecd 100644 --- a/spec/support/config/capistrano.rake +++ b/spec/support/config/capistrano.rake @@ -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 diff --git a/spec/tasks/defaults_spec.rb b/spec/tasks/defaults_spec.rb index cd1a626..1852cb6 100644 --- a/spec/tasks/defaults_spec.rb +++ b/spec/tasks/defaults_spec.rb @@ -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 diff --git a/spec/tasks/slacky_spec.rb b/spec/tasks/slacky_spec.rb index 3ad596c..fd60141 100644 --- a/spec/tasks/slacky_spec.rb +++ b/spec/tasks/slacky_spec.rb @@ -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