Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RuboCop annotations failures #7

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.6

Layout/LineLength:
Exclude:
- spec/**/*
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Enable Github actions for ruby 3
- Enable Rubocop linting
- Bump compatibility to sidekiq 7
- More stringent RuboCop tests
- Enable RubyGems MFA required

## 0.1.5
- RSpec Matchers for testing, thanks to [rspec-rails](https://github.com/rspec/rspec-rails) for their ActionCable `have_broadcasted_to` matcher as reference
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in teams_connector.gemspec
gemspec

gem 'bundler', '>= 1.17'
gem 'rake', '>= 10.0'
gem 'rspec', '>= 3.0'
gem 'rubocop'
gem 'sidekiq', '< 8'
gem 'simplecov'
gem 'webmock'
2 changes: 1 addition & 1 deletion spec/teams_connector/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe TeamsConnector::Builder do
subject { TeamsConnector::Builder.new {} }
subject { TeamsConnector::Builder.new { nil } }

it 'is a builder' do
is_expected.to be_a TeamsConnector::Builder
Expand Down
8 changes: 4 additions & 4 deletions spec/teams_connector/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def self.application
it 'loads channels from credentials' do
stub_const 'Rails', RailsTest
allow(Rails.application.credentials)
.to receive(:"teams_connector!").and_return({
credentials_default: 'DEFAULT_TEST_URL',
credentials_other: 'OTHER_TEST_URL'
})
.to receive(:teams_connector!).and_return({
credentials_default: 'DEFAULT_TEST_URL',
credentials_other: 'OTHER_TEST_URL'
})
subject.load_from_rails_credentials
channels = [
{ credentials_default: 'DEFAULT_TEST_URL' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def notification(template, channels)
end

it 'passes when negated' do
expect {}.not_to sent_notification_to?(:default)
expect { nil }.not_to sent_notification_to?(:default)
end

it 'passes with multiple channels' do
Expand Down Expand Up @@ -99,7 +99,7 @@ def notification(template, channels)

it 'fails when notification is not sent' do
expect do
expect {}.to sent_notification_to?(:default)
expect { nil }.to sent_notification_to?(:default)
end.to raise_error(/expected to send exactly 1 notifications to default, but sent 0/)
end

Expand All @@ -115,8 +115,7 @@ def notification(template, channels)
it 'reports correct number in fail error message' do
notification(:test_card, :default)
expect do
expect do
end.to sent_notification_to?(:default).exactly(1)
expect { nil }.to sent_notification_to?(:default).exactly(1)
end.to raise_error(/expected to send exactly 1 notifications to default, but sent 0/)
end

Expand Down Expand Up @@ -200,7 +199,7 @@ def notification(template, channels)
end

it 'passes when negated' do
expect {}.not_to sent_notification_to?(nil, :test_card)
expect { nil }.not_to sent_notification_to?(nil, :test_card)
end

it 'counts only notifications sent with the template' do
Expand Down
18 changes: 9 additions & 9 deletions spec/teams_connector/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
it 'delivers the message to the target' do
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://default'
end

it 'delivers the message to the default target' do
TeamsConnector.configuration.always_use_default = true
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://default').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://default').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://localhost'
end

Expand All @@ -48,16 +48,16 @@
it 'delivers the message to all targets' do
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://another').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).to have_requested(:post, 'http://another').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://default'
end

it 'delivers the message only to the default target' do
TeamsConnector.configuration.always_use_default = true
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://default').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://default').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://localhost'
expect(WebMock).not_to have_requested(:post, 'http://another')
end
Expand All @@ -67,9 +67,9 @@
it 'raises an error' do
stub_request(:post, 'localhost').to_return(status: 400)

expect { subject.deliver_later }.to raise_error Net::HTTPServerException
expect { subject.deliver_later }.to raise_error Net::HTTPClientException

expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://default'
end
end
Expand Down Expand Up @@ -107,7 +107,7 @@
it 'delivers notifications' do
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://default'
end
end
Expand Down Expand Up @@ -147,7 +147,7 @@
it 'falls back on bundled cards' do
subject.deliver_later

expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { "Content-Type": 'application/json' }
expect(WebMock).to have_requested(:post, 'http://localhost').with headers: { 'Content-Type': 'application/json' }
expect(WebMock).not_to have_requested :post, 'http://default'
end
end
Expand Down
9 changes: 1 addition & 8 deletions teams_connector.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/Qurasoft/teams_connector'
spec.metadata['changelog_uri'] = 'https://github.com/Qurasoft/teams_connector/blob/main/CHANGES.md'
spec.metadata['rubygems_mfa_required'] = 'true'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -26,12 +27,4 @@ Gem::Specification.new do |spec|
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '>= 1.17'
spec.add_development_dependency 'rake', '>= 10.0'
spec.add_development_dependency 'rspec', '>= 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'sidekiq', '< 8'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'webmock'
end