From 564428993c56f9d8c53bdeca8202a2b8557f36e6 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:08:46 +0200 Subject: [PATCH 01/19] Fix current rubocop offense Rubocop suggest to use mfa when you're releasing gems on rubygems.org. That's to protect your users from malicious attacker who might steal your password and publish new versions in your name. Nobody wants that. --- heartcheck.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/heartcheck.gemspec b/heartcheck.gemspec index cf9adea..35eabc8 100644 --- a/heartcheck.gemspec +++ b/heartcheck.gemspec @@ -14,6 +14,8 @@ Gem::Specification.new do |spec| spec.description = 'A simple way to check your app heart.' spec.license = 'MIT' + spec.metadata['rubygems_mfa_required'] = 'true' + spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end From 60dfb56e395e2ed224e3ba0db26815ab98974f2c Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:10:10 +0200 Subject: [PATCH 02/19] Adding rubcop-rspec to the project --- .rubocop.yml | 1 + heartcheck.gemspec | 1 + 2 files changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9e2b76b..6e2ceb7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ inherit_from: .rubocop_todo.yml +require: rubocop-rspec AllCops: NewCops: enable diff --git a/heartcheck.gemspec b/heartcheck.gemspec index 35eabc8..99a0814 100644 --- a/heartcheck.gemspec +++ b/heartcheck.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec', '~> 3.5.0' spec.add_development_dependency 'rubocop' + spec.add_development_dependency 'rubocop-rspec' spec.add_development_dependency 'rubycritic' spec.add_development_dependency 'thor', '~> 0.19.1' spec.add_development_dependency 'yard', '~> 0.9.5' From 15e327a9825d2936d3370ac403e28391b5cf6d2c Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:13:39 +0200 Subject: [PATCH 03/19] Fix RSpec/ScatteredLet --- spec/lib/heartcheck_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index 0328abf..d176c2b 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -96,6 +96,7 @@ subject(:add) { described_class.add(name, &blk) } let(:name) { :process } + let(:blk) { ->(c) { c.this_is_terrible } } let(:plugin) { Heartcheck::Checks::Process.new } let(:blk) { ->(_) {} } @@ -118,7 +119,6 @@ ) end - let(:blk) { ->(c) { c.this_is_terrible } } it 'instantiates the class passing the given block' do expect(plugin).to receive(:this_is_terrible) From 415e789f526b764879e4bf65be2a054f14c4531e Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:16:10 +0200 Subject: [PATCH 04/19] Fix RSpec/ExcessiveDocstringSpacing --- spec/lib/heartcheck_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index d176c2b..4b5813b 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -61,7 +61,7 @@ end context 'with threaded' do - it 'returns a threaded executor' do + it 'returns a threaded executor' do described_class.use_threaded_executor! expect(described_class.executor).to be_a(Heartcheck::Executors::Threaded) end From 69abc84a3c75c9cc9cbd0476e20e111c90be4ebc Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:16:43 +0200 Subject: [PATCH 05/19] Fix RSpec/HookArgument --- spec/lib/heartcheck_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index 4b5813b..64c96b3 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -25,7 +25,7 @@ describe '#format' do context 'with default' do - before(:each) { described_class.instance_variable_set :@formatter, nil } + before { described_class.instance_variable_set :@formatter, nil } it 'returns a Heartcheck::Formatters::Base' do described_class.setup do |monitor| expect(monitor.formatter).to be_a(Heartcheck::Formatters::Base) @@ -34,7 +34,7 @@ end context 'with hash formatter' do - before(:each) { described_class.instance_variable_set :@formatter, nil } + before { described_class.instance_variable_set :@formatter, nil } it 'returns a Heartcheck::Formatters::Base' do described_class.setup do |monitor| described_class.use_hash_formatter! From 46642d45d252f296db5e91ac1baeed83a9e4380c Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:17:16 +0200 Subject: [PATCH 06/19] Fix RSpec/ImplicitSubject --- spec/lib/heartcheck/controllers/environment_spec.rb | 4 ++-- spec/lib/heartcheck_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/heartcheck/controllers/environment_spec.rb b/spec/lib/heartcheck/controllers/environment_spec.rb index 9837a51..e629bfb 100644 --- a/spec/lib/heartcheck/controllers/environment_spec.rb +++ b/spec/lib/heartcheck/controllers/environment_spec.rb @@ -20,7 +20,7 @@ module Controllers it 'gets info from the right constants and functions' do allow(Sys::Uname).to receive(:uname).and_return(system_info_example) - is_expected.to include( + expect(subject).to include( system_info: { example_key: 'example_value' }, ruby_version: '2.4.0', rails_version: '5.0.0' @@ -64,7 +64,7 @@ module Controllers context 'given Rails is not used' do it 'gets the info indicating Rails is not used' do allow(Sys::Uname).to receive(:uname).and_return(system_info_example) - is_expected.to include( + expect(subject).to include( system_info: { example_key: 'example_value' }, ruby_version: '2.4.0', rails_version: '(none)' diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index 64c96b3..0c3605a 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -108,7 +108,7 @@ end it 'returns the built instance' do - is_expected.to eq([plugin]) + expect(subject).to eq([plugin]) end it 'adds to context list' do From 0d1ffd89f52e78f0f1ccc96449655b3951469507 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:17:43 +0200 Subject: [PATCH 07/19] Fix RSpec/EmptyLineAfterHook --- spec/lib/heartcheck/checks/base_spec.rb | 1 + spec/lib/heartcheck_spec.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/spec/lib/heartcheck/checks/base_spec.rb b/spec/lib/heartcheck/checks/base_spec.rb index 841ad0f..90a52a4 100644 --- a/spec/lib/heartcheck/checks/base_spec.rb +++ b/spec/lib/heartcheck/checks/base_spec.rb @@ -120,6 +120,7 @@ context 'with success' do before { allow(subject).to receive(:validate) } + it 'returns empty array' do expect(subject.check).to eq('base' => { 'status' => 'ok' }) end diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index 0c3605a..db313c5 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -26,6 +26,7 @@ describe '#format' do context 'with default' do before { described_class.instance_variable_set :@formatter, nil } + it 'returns a Heartcheck::Formatters::Base' do described_class.setup do |monitor| expect(monitor.formatter).to be_a(Heartcheck::Formatters::Base) @@ -35,6 +36,7 @@ context 'with hash formatter' do before { described_class.instance_variable_set :@formatter, nil } + it 'returns a Heartcheck::Formatters::Base' do described_class.setup do |monitor| described_class.use_hash_formatter! From 572b9e71b71dad4f839e87ca129401fcaa03746b Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:18:36 +0200 Subject: [PATCH 08/19] Fix RSpec/ExampleWording --- spec/lib/heartcheck/checks/base_spec.rb | 4 ++-- spec/lib/heartcheck/executors/base_spec.rb | 6 +++--- spec/lib/heartcheck/executors/threaded_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/lib/heartcheck/checks/base_spec.rb b/spec/lib/heartcheck/checks/base_spec.rb index 90a52a4..da5705f 100644 --- a/spec/lib/heartcheck/checks/base_spec.rb +++ b/spec/lib/heartcheck/checks/base_spec.rb @@ -144,7 +144,7 @@ ) end - it 'should not accumulate errors' do + it 'does not accumulate errors' do subject.check expect(subject.check).to eq( 'base' => { @@ -200,7 +200,7 @@ allow(subject).to receive(:info).and_return(response) end - it 'should show a response' do + it 'shows a response' do expect(subject.informations).to eq(response) end end diff --git a/spec/lib/heartcheck/executors/base_spec.rb b/spec/lib/heartcheck/executors/base_spec.rb index 4149dbf..95687d2 100644 --- a/spec/lib/heartcheck/executors/base_spec.rb +++ b/spec/lib/heartcheck/executors/base_spec.rb @@ -16,18 +16,18 @@ module Executors end end - it 'should register a log entry for each checker' do + it 'registers a log entry for each checker' do expect(Logger).to receive(:info).exactly(registered).times subject.dispatch(checkers) end - it 'should have a :time key in the checker response' do + it 'has a :time key in the checker response' do subject.dispatch(checkers).each do |current| expect(current).to include(:time) end end - it 'should have a float value (time key)' do + it 'has a float value (time key)' do subject.dispatch(checkers).each do |current| expect(current[:time]).to be_a(Float) end diff --git a/spec/lib/heartcheck/executors/threaded_spec.rb b/spec/lib/heartcheck/executors/threaded_spec.rb index ac54ccd..d910f0d 100644 --- a/spec/lib/heartcheck/executors/threaded_spec.rb +++ b/spec/lib/heartcheck/executors/threaded_spec.rb @@ -22,18 +22,18 @@ module Executors end end - it 'should register a log entry for each checker' do + it 'registers a log entry for each checker' do expect(Logger).to receive(:info).exactly(registered).times subject.dispatch(checkers) end - it 'should have a :time key in the checker response' do + it 'has a :time key in the checker response' do subject.dispatch(checkers).each do |current| expect(current).to include(:time) end end - it 'should have a float value (time key)' do + it 'has a float value (time key)' do subject.dispatch(checkers).each do |current| expect(current[:time]).to be_a(Float) end From e7fa12d42d4d99b2150c5050c015dcd40892fae4 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:19:04 +0200 Subject: [PATCH 09/19] Fix RSpec/EmptyLineAfterExample --- spec/lib/heartcheck/app_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/heartcheck/app_spec.rb b/spec/lib/heartcheck/app_spec.rb index eeaf799..546ed63 100644 --- a/spec/lib/heartcheck/app_spec.rb +++ b/spec/lib/heartcheck/app_spec.rb @@ -55,6 +55,7 @@ it 'has execution_time' do expect(subject.body).to match(/"execution_time":"([0-9]{1,2}).([0-9]{2}) ms"/) end + it 'has total_execution_time' do expect(subject.body).to match(/"total_execution_time":"([0-9]{1,2}).([0-9]{2}) ms"/) end From 9bd5087aa7744387c69b60c57a8ca69b888b18ae Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:19:31 +0200 Subject: [PATCH 10/19] Fix RSpec/LeadingSubject --- spec/lib/heartcheck/app_spec.rb | 2 +- spec/lib/heartcheck/checks/firewall_spec.rb | 8 ++++---- spec/lib/heartcheck/checks/process_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/lib/heartcheck/app_spec.rb b/spec/lib/heartcheck/app_spec.rb index 546ed63..cc3722a 100644 --- a/spec/lib/heartcheck/app_spec.rb +++ b/spec/lib/heartcheck/app_spec.rb @@ -6,8 +6,8 @@ describe Heartcheck::App do include Rack::Test::Methods - let(:app) { described_class.new } subject { last_response } + let(:app) { described_class.new } describe '#body' do subject { super().body } diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index 9fbe76d..acaa7eb 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -72,15 +72,15 @@ end context 'with proxy' do - let(:host) { 'lala.com' } - let(:port) { 443 } - let(:proxy) { 'http://uriproxy.com.br:8888' } - subject do described_class.new.tap do |c| c.add_service(port: port, host: host, proxy: proxy) end end + let(:host) { 'lala.com' } + let(:port) { 443 } + let(:proxy) { 'http://uriproxy.com.br:8888' } + it 'calls Net::Telnet with valid params of proxy' do expect(Net::Telnet).to receive(:new).with('Port' => 8888, 'Host' => 'uriproxy.com.br', diff --git a/spec/lib/heartcheck/checks/process_spec.rb b/spec/lib/heartcheck/checks/process_spec.rb index e5fb7d2..a7299ff 100644 --- a/spec/lib/heartcheck/checks/process_spec.rb +++ b/spec/lib/heartcheck/checks/process_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe Heartcheck::Checks::Process do - let(:opts) { { name: 'worker', file: 'spec/fixtures/files/worker.pid' } } subject { described_class.new.tap { |c| c.add_service(opts) } } + let(:opts) { { name: 'worker', file: 'spec/fixtures/files/worker.pid' } } describe '#validate' do context 'with success' do From a6c4d7404a58a9f26099bf57574f38ba6f8ddbd6 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:20:01 +0200 Subject: [PATCH 11/19] Fix RSpec/EmptyLineAfterSubject --- spec/lib/heartcheck/app_spec.rb | 10 ++++++++++ spec/lib/heartcheck/checks/base_spec.rb | 4 ++++ spec/lib/heartcheck/checks/firewall_spec.rb | 1 + spec/lib/heartcheck/checks/process_spec.rb | 1 + 4 files changed, 16 insertions(+) diff --git a/spec/lib/heartcheck/app_spec.rb b/spec/lib/heartcheck/app_spec.rb index cc3722a..dbf4cdb 100644 --- a/spec/lib/heartcheck/app_spec.rb +++ b/spec/lib/heartcheck/app_spec.rb @@ -7,6 +7,7 @@ include Rack::Test::Methods subject { last_response } + let(:app) { described_class.new } describe '#body' do @@ -30,11 +31,13 @@ describe '#body' do subject { super().body } + it { is_expected.to eq('[]') } end describe '#status' do subject { super().status } + it { is_expected.to eq(200) } end end @@ -62,6 +65,7 @@ describe '#status' do subject { super().status } + it { is_expected.to eq(200) } end end @@ -71,11 +75,13 @@ describe '#body' do subject { super().body } + it { is_expected.to eq('[]') } end describe '#status' do subject { super().status } + it { is_expected.to eq(200) } end end @@ -85,11 +91,13 @@ describe '#body' do subject { super().body } + it { is_expected.to eq(MultiJson.dump({ status: 'ok' })) } end describe '#status' do subject { super().status } + it { is_expected.to eq(200) } end end @@ -99,11 +107,13 @@ describe '#body' do subject { super().body } + it { is_expected.to eq('Not found') } end describe '#status' do subject { super().status } + it { is_expected.to eq(404) } end end diff --git a/spec/lib/heartcheck/checks/base_spec.rb b/spec/lib/heartcheck/checks/base_spec.rb index da5705f..7587923 100644 --- a/spec/lib/heartcheck/checks/base_spec.rb +++ b/spec/lib/heartcheck/checks/base_spec.rb @@ -83,6 +83,7 @@ context 'default is false' do describe '#functional?' do subject { super().functional? } + it { is_expected.to be_falsey } end end @@ -92,6 +93,7 @@ describe '#functional?' do subject { super().functional? } + it { is_expected.to be_truthy } end end @@ -101,6 +103,7 @@ context 'default is false' do describe '#dev?' do subject { super().dev? } + it { is_expected.to be_falsey } end end @@ -110,6 +113,7 @@ describe '#dev?' do subject { super().dev? } + it { is_expected.to be_truthy } end end diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index acaa7eb..1b938fd 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -77,6 +77,7 @@ c.add_service(port: port, host: host, proxy: proxy) end end + let(:host) { 'lala.com' } let(:port) { 443 } let(:proxy) { 'http://uriproxy.com.br:8888' } diff --git a/spec/lib/heartcheck/checks/process_spec.rb b/spec/lib/heartcheck/checks/process_spec.rb index a7299ff..5263c87 100644 --- a/spec/lib/heartcheck/checks/process_spec.rb +++ b/spec/lib/heartcheck/checks/process_spec.rb @@ -4,6 +4,7 @@ describe Heartcheck::Checks::Process do subject { described_class.new.tap { |c| c.add_service(opts) } } + let(:opts) { { name: 'worker', file: 'spec/fixtures/files/worker.pid' } } describe '#validate' do From 9c93baf46129d46694dc3b0860655f8b1f9bd085 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:21:27 +0200 Subject: [PATCH 12/19] Fix RSpec/LetBeforeExamples --- .../heartcheck/controllers/environment_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/lib/heartcheck/controllers/environment_spec.rb b/spec/lib/heartcheck/controllers/environment_spec.rb index e629bfb..2e66b8a 100644 --- a/spec/lib/heartcheck/controllers/environment_spec.rb +++ b/spec/lib/heartcheck/controllers/environment_spec.rb @@ -18,6 +18,15 @@ module Controllers stub_const('Rails::VERSION::STRING', '5.0.0') end + let(:rails_version) do + MultiJson.load(controller.index, symbolize_keys: true)[:rails_version] + end + let(:ruby_version) do + MultiJson.load(controller.index, symbolize_keys: true)[:ruby_version] + end + let(:system_info) do + MultiJson.load(controller.index, symbolize_keys: true)[:system_info] + end it 'gets info from the right constants and functions' do allow(Sys::Uname).to receive(:uname).and_return(system_info_example) expect(subject).to include( @@ -28,17 +37,8 @@ module Controllers expect(Sys::Uname).to have_received(:uname) end - let(:system_info) do - MultiJson.load(controller.index, symbolize_keys: true)[:system_info] - end - let(:ruby_version) do - MultiJson.load(controller.index, symbolize_keys: true)[:ruby_version] - end - let(:rails_version) do - MultiJson.load(controller.index, symbolize_keys: true)[:rails_version] - end it 'gets the info in the expected format' do expect(system_info).to be_a(Hash) From ba407eb2ec7e9db5dbd701989e8643cfa7a0402a Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:20:49 +0200 Subject: [PATCH 13/19] Fix RSpec/EmptyLineAfterFinalLet --- spec/lib/heartcheck/checks/base_spec.rb | 1 + spec/lib/heartcheck/controllers/environment_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/spec/lib/heartcheck/checks/base_spec.rb b/spec/lib/heartcheck/checks/base_spec.rb index 7587923..b22e34b 100644 --- a/spec/lib/heartcheck/checks/base_spec.rb +++ b/spec/lib/heartcheck/checks/base_spec.rb @@ -200,6 +200,7 @@ context 'without error' do let(:response) { { 'version' => '1234' } } + before do allow(subject).to receive(:info).and_return(response) end diff --git a/spec/lib/heartcheck/controllers/environment_spec.rb b/spec/lib/heartcheck/controllers/environment_spec.rb index 2e66b8a..aea3d45 100644 --- a/spec/lib/heartcheck/controllers/environment_spec.rb +++ b/spec/lib/heartcheck/controllers/environment_spec.rb @@ -27,6 +27,7 @@ module Controllers let(:system_info) do MultiJson.load(controller.index, symbolize_keys: true)[:system_info] end + it 'gets info from the right constants and functions' do allow(Sys::Uname).to receive(:uname).and_return(system_info_example) expect(subject).to include( From bc933c5cdf6312ff3acd170d1b56c2b96a59bd13 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:22:14 +0200 Subject: [PATCH 14/19] Fix Layout/EmptyLines --- spec/lib/heartcheck/checks/firewall_spec.rb | 1 - spec/lib/heartcheck/controllers/environment_spec.rb | 3 --- spec/lib/heartcheck_spec.rb | 1 - 3 files changed, 5 deletions(-) diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index 1b938fd..76a8eb5 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -82,7 +82,6 @@ let(:port) { 443 } let(:proxy) { 'http://uriproxy.com.br:8888' } - it 'calls Net::Telnet with valid params of proxy' do expect(Net::Telnet).to receive(:new).with('Port' => 8888, 'Host' => 'uriproxy.com.br', 'Timeout' => 2).ordered.and_return('proxy') diff --git a/spec/lib/heartcheck/controllers/environment_spec.rb b/spec/lib/heartcheck/controllers/environment_spec.rb index aea3d45..c2b8300 100644 --- a/spec/lib/heartcheck/controllers/environment_spec.rb +++ b/spec/lib/heartcheck/controllers/environment_spec.rb @@ -38,9 +38,6 @@ module Controllers expect(Sys::Uname).to have_received(:uname) end - - - it 'gets the info in the expected format' do expect(system_info).to be_a(Hash) expect(system_info).to include( diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index db313c5..e452a3f 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -121,7 +121,6 @@ ) end - it 'instantiates the class passing the given block' do expect(plugin).to receive(:this_is_terrible) From 2e946cf16ec537e71cdb52b19a223afb041e3548 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:29:38 +0200 Subject: [PATCH 15/19] Fix RSpec/ContextWording --- spec/lib/heartcheck/app_spec.rb | 10 +++++----- spec/lib/heartcheck/caching_app_spec.rb | 2 +- spec/lib/heartcheck/checks/base_spec.rb | 20 +++++++++---------- spec/lib/heartcheck/checks/firewall_spec.rb | 4 ++-- spec/lib/heartcheck/checks/watch_file_spec.rb | 4 ++-- .../controllers/environment_spec.rb | 4 ++-- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/spec/lib/heartcheck/app_spec.rb b/spec/lib/heartcheck/app_spec.rb index dbf4cdb..7fb952e 100644 --- a/spec/lib/heartcheck/app_spec.rb +++ b/spec/lib/heartcheck/app_spec.rb @@ -26,7 +26,7 @@ it { is_expected.to eq(200) } end - context 'on GET /functional' do + context 'with GET /functional' do before { get '/functional' } describe '#body' do @@ -42,7 +42,7 @@ end end - context 'on GET /dev' do + context 'with GET /dev' do before do Heartcheck.setup do |monitor| log = Logger.new($stdout) @@ -70,7 +70,7 @@ end end - context 'on GET info' do + context 'with GET info' do before { get '/info' } describe '#body' do @@ -86,7 +86,7 @@ end end - context 'on GET health_check' do + context 'with GET health_check' do before { get '/health_check' } describe '#body' do @@ -102,7 +102,7 @@ end end - context 'on GET other routes' do + context 'with GET other routes' do before { get '/lorem' } describe '#body' do diff --git a/spec/lib/heartcheck/caching_app_spec.rb b/spec/lib/heartcheck/caching_app_spec.rb index 89f4942..4a74086 100644 --- a/spec/lib/heartcheck/caching_app_spec.rb +++ b/spec/lib/heartcheck/caching_app_spec.rb @@ -61,7 +61,7 @@ module Heartcheck end end - context 'on an unknown route' do + context 'with an unknown route' do it 'forwards to the original app' do get '/not-found' diff --git a/spec/lib/heartcheck/checks/base_spec.rb b/spec/lib/heartcheck/checks/base_spec.rb index b22e34b..d8f28fc 100644 --- a/spec/lib/heartcheck/checks/base_spec.rb +++ b/spec/lib/heartcheck/checks/base_spec.rb @@ -80,7 +80,7 @@ end describe '#functional?' do - context 'default is false' do + context 'when functional is not set' do describe '#functional?' do subject { super().functional? } @@ -88,7 +88,7 @@ end end - context 'can change value' do + context 'when functional is set to true' do before { base.functional = true } describe '#functional?' do @@ -100,7 +100,7 @@ end describe '#dev?' do - context 'default is false' do + context 'when dev is not set' do describe '#dev?' do subject { super().dev? } @@ -108,7 +108,7 @@ end end - context 'can change value' do + context 'when dev is set to true' do before { base.dev = true } describe '#dev?' do @@ -212,13 +212,11 @@ end describe '#uri_info' do - context 'for the base class' do - it 'returns a hash with an error message' do - expect(subject.uri_info).to include(:error) - expect(subject.uri_info).not_to include(:host) - expect(subject.uri_info).not_to include(:port) - expect(subject.uri_info).not_to include(:schema) - end + it 'returns a hash with an error message' do + expect(subject.uri_info).to include(:error) + expect(subject.uri_info).not_to include(:host) + expect(subject.uri_info).not_to include(:port) + expect(subject.uri_info).not_to include(:schema) end end end diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index 76a8eb5..6dfe56e 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -91,7 +91,7 @@ subject.validate end - context 'connection refused' do + context 'when getting connection is refused' do it 'avoid to adds errors array' do expect(Net::Telnet).to receive(:new).and_raise Errno::ECONNREFUSED.new subject.validate @@ -100,7 +100,7 @@ end end - context 'timeout' do + context 'when running into a timeout' do let(:proxy_uri) { 'uriproxy.com.br:8888' } let(:error_msg) do "connection refused on: #{host}:443 using proxy: #{proxy_uri}" diff --git a/spec/lib/heartcheck/checks/watch_file_spec.rb b/spec/lib/heartcheck/checks/watch_file_spec.rb index 9209e22..67bbb44 100644 --- a/spec/lib/heartcheck/checks/watch_file_spec.rb +++ b/spec/lib/heartcheck/checks/watch_file_spec.rb @@ -8,14 +8,14 @@ end describe '#validate' do - context 'the watched file as no modifications' do + context 'when the watched file as no modifications' do it 'array errors should be empty' do subject.validate expect(subject.instance_variable_get(:@errors)).to be_empty end end - context 'the watched file have new modifications' do + context 'when the watched file have new modifications' do it 'array erros should not be empty' do allow(subject).to receive(:installed).and_return({ bacon: true }) expect { subject.validate } diff --git a/spec/lib/heartcheck/controllers/environment_spec.rb b/spec/lib/heartcheck/controllers/environment_spec.rb index c2b8300..4a7a5ae 100644 --- a/spec/lib/heartcheck/controllers/environment_spec.rb +++ b/spec/lib/heartcheck/controllers/environment_spec.rb @@ -13,7 +13,7 @@ module Controllers let(:system_info_example) { Struct.new(:example_key).new('example_value') } - context 'given Rails is used' do + context 'when Rails is used' do before do stub_const('Rails::VERSION::STRING', '5.0.0') end @@ -59,7 +59,7 @@ module Controllers end end - context 'given Rails is not used' do + context 'when Rails is not used' do it 'gets the info indicating Rails is not used' do allow(Sys::Uname).to receive(:uname).and_return(system_info_example) expect(subject).to include( From 74c6057907dbed893a2dc3d5828dd8b40fb2777d Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:38:18 +0200 Subject: [PATCH 16/19] Fix RSpec/OverwritingSetup --- spec/lib/heartcheck_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/lib/heartcheck_spec.rb b/spec/lib/heartcheck_spec.rb index e452a3f..43230e9 100644 --- a/spec/lib/heartcheck_spec.rb +++ b/spec/lib/heartcheck_spec.rb @@ -98,10 +98,8 @@ subject(:add) { described_class.add(name, &blk) } let(:name) { :process } - let(:blk) { ->(c) { c.this_is_terrible } } - let(:plugin) { Heartcheck::Checks::Process.new } - let(:blk) { ->(_) {} } + let(:plugin) { Heartcheck::Checks::Process.new } before do allow(Heartcheck::Checks::Process).to receive(:new) @@ -121,10 +119,14 @@ ) end - it 'instantiates the class passing the given block' do - expect(plugin).to receive(:this_is_terrible) + context 'with code in the block argument' do + let(:blk) { ->(c) { c.this_is_terrible } } - add + it 'instantiates the class passing the given block' do + expect(plugin).to receive(:this_is_terrible) + + add + end end end end From 4f1a70d68ba128a694618d0b561fc2e0dcc5fcc7 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:38:26 +0200 Subject: [PATCH 17/19] Fix RSpec/VerifiedDoubles --- spec/lib/heartcheck/caching_app_spec.rb | 4 ++-- spec/lib/heartcheck/checks/firewall_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/heartcheck/caching_app_spec.rb b/spec/lib/heartcheck/caching_app_spec.rb index 4a74086..54e8c58 100644 --- a/spec/lib/heartcheck/caching_app_spec.rb +++ b/spec/lib/heartcheck/caching_app_spec.rb @@ -9,8 +9,8 @@ module Heartcheck let(:app) { described_class.new(super_app, ttl, cache) } let(:ttl) { 5 } - let(:cache) { double(Heartcheck::CachingApp::Cache) } - let(:super_app) { double(Heartcheck::App) } + let(:cache) { instance_double(Heartcheck::CachingApp::Cache) } + let(:super_app) { instance_double(Heartcheck::App) } let(:controller) { Heartcheck::Controllers::Essential } let(:response) { [200, { 'Content-type' => 'application/json' }, ['[]']] } diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index 6dfe56e..df903d3 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -40,7 +40,7 @@ context 'without proxy' do context 'with success' do - let(:telnet) { double(Net::Telnet, close: true) } + let(:telnet) { instance_double(Net::Telnet, close: true) } let(:params) { { 'Port' => 443, 'Host' => 'lala.com', 'Timeout' => 2 } } it 'calls Net::Telnet with valid params' do From 85b897090cb1e0740a7bf8d99a7f58c0a75943e0 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:42:30 +0200 Subject: [PATCH 18/19] Fix RSpec/IteratedExpectation --- spec/lib/heartcheck/executors/base_spec.rb | 4 +--- spec/lib/heartcheck/executors/threaded_spec.rb | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/spec/lib/heartcheck/executors/base_spec.rb b/spec/lib/heartcheck/executors/base_spec.rb index 95687d2..12883b5 100644 --- a/spec/lib/heartcheck/executors/base_spec.rb +++ b/spec/lib/heartcheck/executors/base_spec.rb @@ -22,9 +22,7 @@ module Executors end it 'has a :time key in the checker response' do - subject.dispatch(checkers).each do |current| - expect(current).to include(:time) - end + expect(subject.dispatch(checkers)).to all(include(:time)) end it 'has a float value (time key)' do diff --git a/spec/lib/heartcheck/executors/threaded_spec.rb b/spec/lib/heartcheck/executors/threaded_spec.rb index d910f0d..6bad0b4 100644 --- a/spec/lib/heartcheck/executors/threaded_spec.rb +++ b/spec/lib/heartcheck/executors/threaded_spec.rb @@ -28,9 +28,7 @@ module Executors end it 'has a :time key in the checker response' do - subject.dispatch(checkers).each do |current| - expect(current).to include(:time) - end + expect(subject.dispatch(checkers)).to all(include(:time)) end it 'has a float value (time key)' do From 58c99004adf4d1055ac3ecadcdd014c2962b3af7 Mon Sep 17 00:00:00 2001 From: Gregor Schmidt Date: Sun, 9 Oct 2022 14:45:28 +0200 Subject: [PATCH 19/19] Fix RSpec/RepeatedExampleGroupDescription --- spec/lib/heartcheck/checks/firewall_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/heartcheck/checks/firewall_spec.rb b/spec/lib/heartcheck/checks/firewall_spec.rb index df903d3..b75f1b6 100644 --- a/spec/lib/heartcheck/checks/firewall_spec.rb +++ b/spec/lib/heartcheck/checks/firewall_spec.rb @@ -50,7 +50,7 @@ end end - context 'with success' do + context 'without success' do before { allow(Net::Telnet).to receive(:new).and_raise(Timeout::Error.new) } it 'adds error message' do