From 263873dff13753e2c4a39fea5e0fad980ecb7d48 Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Sat, 30 Dec 2023 18:53:19 +0600 Subject: [PATCH] Update rubopcop [WIP] --- .rubocop.yml | 23 ++++++++++++++----- Appraisals | 2 ++ Gemfile | 5 +++- Rakefile | 2 ++ bin/console | 1 + bin/fetch-telegram-methods | 2 ++ bin/install_git_hooks | 3 ++- lib/tasks/telegram-bot.rake | 2 ++ lib/telegram/bot.rb | 2 ++ lib/telegram/bot/async.rb | 2 ++ lib/telegram/bot/client.rb | 4 +++- lib/telegram/bot/client/api_helper.rb | 4 +++- .../bot/client/request_body_formatter.rb | 2 ++ lib/telegram/bot/client/typed_response.rb | 2 ++ lib/telegram/bot/client_stub.rb | 2 ++ lib/telegram/bot/config_methods.rb | 2 ++ lib/telegram/bot/debug_client.rb | 2 ++ lib/telegram/bot/middleware.rb | 2 ++ lib/telegram/bot/railtie.rb | 2 ++ lib/telegram/bot/routes_helper.rb | 2 ++ lib/telegram/bot/rspec.rb | 2 ++ .../bot/rspec/callback_query_helpers.rb | 2 ++ lib/telegram/bot/rspec/client_matchers.rb | 4 +++- lib/telegram/bot/rspec/integration/poller.rb | 2 ++ lib/telegram/bot/rspec/integration/rack.rb | 2 ++ lib/telegram/bot/rspec/integration/rails.rb | 2 ++ lib/telegram/bot/rspec/integration/shared.rb | 2 ++ lib/telegram/bot/rspec/message_helpers.rb | 2 ++ lib/telegram/bot/updates_controller.rb | 4 +++- .../callback_query_context.rb | 2 ++ .../bot/updates_controller/commands.rb | 4 +++- .../bot/updates_controller/instrumentation.rb | 2 ++ .../bot/updates_controller/log_subscriber.rb | 2 ++ .../bot/updates_controller/message_context.rb | 4 +++- .../bot/updates_controller/reply_helpers.rb | 6 +++-- lib/telegram/bot/updates_controller/rescue.rb | 4 +++- .../bot/updates_controller/rspec_helpers.rb | 2 ++ .../bot/updates_controller/session.rb | 2 ++ .../bot/updates_controller/testing.rb | 2 ++ .../bot/updates_controller/translation.rb | 2 ++ .../bot/updates_controller/typed_update.rb | 2 ++ lib/telegram/bot/updates_poller.rb | 4 +++- lib/telegram/bot/version.rb | 2 ++ spec/integration/requests/default_bot_spec.rb | 2 ++ spec/integration/requests/named_bot_spec.rb | 2 ++ spec/integration/requests/other_bot_spec.rb | 2 ++ spec/integration_helper.rb | 2 ++ spec/spec_helper.rb | 4 +++- spec/support/examples/async.rb | 2 ++ spec/support/examples/integration.rb | 2 ++ spec/telegram/bot/async_spec.rb | 2 ++ .../bot/client/request_body_formatter_spec.rb | 2 ++ .../bot/client/typed_response_spec.rb | 2 ++ spec/telegram/bot/client_spec.rb | 6 +++-- spec/telegram/bot/client_stub_spec.rb | 4 +++- spec/telegram/bot/config_methods_spec.rb | 2 ++ spec/telegram/bot/middleware_spec.rb | 2 ++ spec/telegram/bot/routes_helper_spec.rb | 4 +++- .../bot/rspec/callback_query_helpers_spec.rb | 2 ++ .../bot/rspec/client_matchers_spec.rb | 2 ++ .../bot/rspec/integration/poller_spec.rb | 2 ++ .../bot/rspec/integration/rack_spec.rb | 2 ++ .../bot/rspec/integration/rails_spec.rb | 1 + .../bot/rspec/message_helpers_spec.rb | 4 +++- .../callback_query_context_spec.rb | 22 ++++++++++-------- .../bot/updates_controller/commands_spec.rb | 6 +++-- .../instrumentation_spec.rb | 2 ++ .../message_context_spec.rb | 2 ++ .../updates_controller/reply_helpers_spec.rb | 4 +++- .../bot/updates_controller/rescue_spec.rb | 2 ++ .../bot/updates_controller/session_spec.rb | 2 ++ .../bot/updates_controller/testing_spec.rb | 2 ++ .../updates_controller/translation_spec.rb | 2 ++ .../updates_controller/typed_update_spec.rb | 2 ++ spec/telegram/bot/updates_controller_spec.rb | 6 +++-- spec/telegram/bot/updates_poller_spec.rb | 2 ++ spec/telegram/bot_spec.rb | 2 ++ telegram-bot.gemspec | 8 ++++++- 78 files changed, 207 insertions(+), 40 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 53ce884..8e1e2fa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,15 @@ -# Rubocop does not support 2.0 -Gemspec/RequiredRubyVersion: {Enabled: false} +require: rubocop-rails -Rails: {Enabled: true} +AllCops: + TargetRubyVersion: 2.4 + NewCops: enable + Exclude: + - gemfiles/* + - tmp/* -Layout/AlignParameters: +Gemspec/DevelopmentDependencies: {Enabled: false} + +Layout/ParameterAlignment: # Disable, till rubocop supports combination of styles. # Use one of this styles where appropriate, keep it clean, compact and readable. Enabled: false @@ -19,8 +25,10 @@ Layout/AlignParameters: # ) Layout/ClosingParenthesisIndentation: {Enabled: false} Layout/DotPosition: {EnforcedStyle: trailing} +Layout/EmptyLineAfterGuardClause: {Enabled: false} Layout/FirstParameterIndentation: {EnforcedStyle: consistent} # Same as Layout/ClosingParenthesisIndentation +Layout/LineLength: {Max: 100} Layout/MultilineMethodCallBraceLayout: {Enabled: false} Layout/MultilineMethodCallIndentation: {EnforcedStyle: indented} Layout/MultilineOperationIndentation: {EnforcedStyle: indented} @@ -28,6 +36,9 @@ Layout/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space} # Offences named scopes and `expect {}.to change {}`. Lint/AmbiguousBlockAssociation: {Enabled: false} +Lint/EmptyBlock: + Exclude: + - spec/**/* Naming/PredicateName: {Enabled: false} Naming/VariableNumber: {EnforcedStyle: snake_case} @@ -45,12 +56,12 @@ Style/ModuleFunction: {Enabled: false} Style/NestedParenthesizedCalls: {Enabled: false} Style/SignalException: {EnforcedStyle: only_raise} Style/TrailingCommaInArguments: {Enabled: false} -Style/TrailingCommaInLiteral: {EnforcedStyleForMultiline: comma} +Style/TrailingCommaInArrayLiteral: {EnforcedStyleForMultiline: comma} +Style/TrailingCommaInHashLiteral: {EnforcedStyleForMultiline: comma} Metrics/AbcSize: {Max: 21} # Other metrics are just enough. # This one offences all specs, routes and some initializers. Metrics/BlockLength: {Enabled: false} -Metrics/LineLength: {Max: 100} Metrics/MethodLength: {Max: 30} Metrics/CyclomaticComplexity: {Max: 8} diff --git a/Appraisals b/Appraisals index 019d01b..5ce8c11 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise 'rails-71' do gem 'actionpack', '~> 7.1.0' gem 'railties', '~> 7.1.0' diff --git a/Gemfile b/Gemfile index 7499052..b83e6bd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec @@ -14,7 +16,8 @@ group :development do gem 'rspec-its', '~> 1.3.0' gem 'rspec-rails', '~> 4.0.2' - gem 'rubocop', '~> 0.52.1' + gem 'rubocop', '~> 1.59.0' + gem 'rubocop-rails', '~> 2.23.1' gem 'coveralls', '~> 0.8.23', require: false end diff --git a/Rakefile b/Rakefile index a000ffb..de9f76c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' diff --git a/bin/console b/bin/console index 604f587..7d15701 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'telegram/bot' diff --git a/bin/fetch-telegram-methods b/bin/fetch-telegram-methods index 193d19a..e516b02 100755 --- a/bin/fetch-telegram-methods +++ b/bin/fetch-telegram-methods @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # # Fetch list of methods from Telegram docs. # Use it to update client.rb. diff --git a/bin/install_git_hooks b/bin/install_git_hooks index 4b48122..67eca3b 100755 --- a/bin/install_git_hooks +++ b/bin/install_git_hooks @@ -1,6 +1,7 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -root = File.expand_path('../../', __FILE__) +root = File.expand_path('..', __dir__) hooks_dir = "#{root}/bin/git-hooks" `ls -1 #{hooks_dir}`.each_line.map(&:strip).each do |file| diff --git a/lib/tasks/telegram-bot.rake b/lib/tasks/telegram-bot.rake index c62ed89..e0afe34 100644 --- a/lib/tasks/telegram-bot.rake +++ b/lib/tasks/telegram-bot.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :telegram do namespace :bot do desc 'Run poller. It broadcasts Rails.logger to STDOUT in dev like `rails s` do. ' \ diff --git a/lib/telegram/bot.rb b/lib/telegram/bot.rb index 799cefe..54e2d05 100644 --- a/lib/telegram/bot.rb +++ b/lib/telegram/bot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/config_methods' module Telegram diff --git a/lib/telegram/bot/async.rb b/lib/telegram/bot/async.rb index 268bf22..14b9510 100644 --- a/lib/telegram/bot/async.rb +++ b/lib/telegram/bot/async.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot # Telegram clients can perform requests in async way with diff --git a/lib/telegram/bot/client.rb b/lib/telegram/bot/client.rb index 79e018f..d7aa6b5 100644 --- a/lib/telegram/bot/client.rb +++ b/lib/telegram/bot/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/hash/keys' require 'httpclient' @@ -41,7 +43,7 @@ def prepare_async_args(action, body = {}) end def error_for_response(response) - result = JSON.parse(response.body) rescue nil # rubocop:disable RescueModifier + result = JSON.parse(response.body) rescue nil # rubocop:disable Style/RescueModifier return Error.new(response.reason) unless result message = result['description'] || '-' # This errors are raised only for valid responses from Telegram diff --git a/lib/telegram/bot/client/api_helper.rb b/lib/telegram/bot/client/api_helper.rb index ee33d8b..e4a7cda 100644 --- a/lib/telegram/bot/client/api_helper.rb +++ b/lib/telegram/bot/client/api_helper.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'active_support/core_ext/string/inflections' module Telegram module Bot class Client module ApiHelper - METHODS_LIST_FILE = File.expand_path('../api_methods.txt', __FILE__) + METHODS_LIST_FILE = File.expand_path('api_methods.txt', __dir__) class << self def methods_list(file = METHODS_LIST_FILE) diff --git a/lib/telegram/bot/client/request_body_formatter.rb b/lib/telegram/bot/client/request_body_formatter.rb index 385e1a1..bcae116 100644 --- a/lib/telegram/bot/client/request_body_formatter.rb +++ b/lib/telegram/bot/client/request_body_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' module Telegram diff --git a/lib/telegram/bot/client/typed_response.rb b/lib/telegram/bot/client/typed_response.rb index b8ae24d..ad74319 100644 --- a/lib/telegram/bot/client/typed_response.rb +++ b/lib/telegram/bot/client/typed_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/client/api_helper' require 'active_support/core_ext/string/inflections' diff --git a/lib/telegram/bot/client_stub.rb b/lib/telegram/bot/client_stub.rb index 2491bb8..4aa13d1 100644 --- a/lib/telegram/bot/client_stub.rb +++ b/lib/telegram/bot/client_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot # Stubbed client for tests. Saves all requests into #requests hash. diff --git a/lib/telegram/bot/config_methods.rb b/lib/telegram/bot/config_methods.rb index 154371c..6d465e5 100644 --- a/lib/telegram/bot/config_methods.rb +++ b/lib/telegram/bot/config_methods.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/indifferent_access' diff --git a/lib/telegram/bot/debug_client.rb b/lib/telegram/bot/debug_client.rb index 4a8a733..3b32f61 100644 --- a/lib/telegram/bot/debug_client.rb +++ b/lib/telegram/bot/debug_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot module DebugClient diff --git a/lib/telegram/bot/middleware.rb b/lib/telegram/bot/middleware.rb index fa86d74..179b494 100644 --- a/lib/telegram/bot/middleware.rb +++ b/lib/telegram/bot/middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/concern' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/json' diff --git a/lib/telegram/bot/railtie.rb b/lib/telegram/bot/railtie.rb index cc6fee4..366eb39 100644 --- a/lib/telegram/bot/railtie.rb +++ b/lib/telegram/bot/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/routes_helper' module Telegram diff --git a/lib/telegram/bot/routes_helper.rb b/lib/telegram/bot/routes_helper.rb index 8aca8af..bdace0b 100644 --- a/lib/telegram/bot/routes_helper.rb +++ b/lib/telegram/bot/routes_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'base64' require 'openssl' diff --git a/lib/telegram/bot/rspec.rb b/lib/telegram/bot/rspec.rb index aeba788..2186126 100644 --- a/lib/telegram/bot/rspec.rb +++ b/lib/telegram/bot/rspec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot module RSpec diff --git a/lib/telegram/bot/rspec/callback_query_helpers.rb b/lib/telegram/bot/rspec/callback_query_helpers.rb index 64a22fe..51d201d 100644 --- a/lib/telegram/bot/rspec/callback_query_helpers.rb +++ b/lib/telegram/bot/rspec/callback_query_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec' require 'telegram/bot/rspec/message_helpers' diff --git a/lib/telegram/bot/rspec/client_matchers.rb b/lib/telegram/bot/rspec/client_matchers.rb index 3f805f9..dad5b8f 100644 --- a/lib/telegram/bot/rspec/client_matchers.rb +++ b/lib/telegram/bot/rspec/client_matchers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot module RSpec @@ -68,7 +70,7 @@ def initialize(bot, action, description: nil) exactly(1) end - def matches?(proc) # rubocop:disable AbcSize + def matches?(proc) # rubocop:disable Metrics/AbcSize raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc) original_requests_count = bot.requests[action].count proc.call diff --git a/lib/telegram/bot/rspec/integration/poller.rb b/lib/telegram/bot/rspec/integration/poller.rb index 54f7b8d..63c6526 100644 --- a/lib/telegram/bot/rspec/integration/poller.rb +++ b/lib/telegram/bot/rspec/integration/poller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/shared' RSpec.shared_context 'telegram/bot/integration/poller' do diff --git a/lib/telegram/bot/rspec/integration/rack.rb b/lib/telegram/bot/rspec/integration/rack.rb index 520d90c..55ea13f 100644 --- a/lib/telegram/bot/rspec/integration/rack.rb +++ b/lib/telegram/bot/rspec/integration/rack.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/shared' require 'rack/test' diff --git a/lib/telegram/bot/rspec/integration/rails.rb b/lib/telegram/bot/rspec/integration/rails.rb index 1e43e09..ad3aa7c 100644 --- a/lib/telegram/bot/rspec/integration/rails.rb +++ b/lib/telegram/bot/rspec/integration/rails.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/shared' RSpec.shared_context 'telegram/bot/integration/rails', type: :request do diff --git a/lib/telegram/bot/rspec/integration/shared.rb b/lib/telegram/bot/rspec/integration/shared.rb index 73f3087..f63653e 100644 --- a/lib/telegram/bot/rspec/integration/shared.rb +++ b/lib/telegram/bot/rspec/integration/shared.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/json' require 'telegram/bot' require 'telegram/bot/rspec/message_helpers' diff --git a/lib/telegram/bot/rspec/message_helpers.rb b/lib/telegram/bot/rspec/message_helpers.rb index 6585f0c..f3c222f 100644 --- a/lib/telegram/bot/rspec/message_helpers.rb +++ b/lib/telegram/bot/rspec/message_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Shared helpers for testing message updates. RSpec.shared_context 'telegram/bot/message_helpers' do let(:default_message_options) { {from: from, chat: chat} } diff --git a/lib/telegram/bot/updates_controller.rb b/lib/telegram/bot/updates_controller.rb index ced8ed7..79d70c2 100644 --- a/lib/telegram/bot/updates_controller.rb +++ b/lib/telegram/bot/updates_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'abstract_controller' require 'active_support/core_ext/string/inflections' require 'active_support/callbacks' @@ -47,7 +49,7 @@ module Bot # ControllerClass.new(bot, from: telegram_user, chat: telegram_chat). # process(:help, *args) # - class UpdatesController < AbstractController::Base # rubocop:disable ClassLength + class UpdatesController < AbstractController::Base # rubocop:disable Metrics/ClassLength abstract! %w[ diff --git a/lib/telegram/bot/updates_controller/callback_query_context.rb b/lib/telegram/bot/updates_controller/callback_query_context.rb index 1dddff1..13dc3c5 100644 --- a/lib/telegram/bot/updates_controller/callback_query_context.rb +++ b/lib/telegram/bot/updates_controller/callback_query_context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController diff --git a/lib/telegram/bot/updates_controller/commands.rb b/lib/telegram/bot/updates_controller/commands.rb index 7e26abf..894dba2 100644 --- a/lib/telegram/bot/updates_controller/commands.rb +++ b/lib/telegram/bot/updates_controller/commands.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController @@ -34,7 +36,7 @@ def action_for_command(cmd) def action_for_message cmd, args = Commands.command_from_text(payload['text'], bot_username) return unless cmd - [[action_for_command(cmd), type: :command, command: cmd], args] + [[action_for_command(cmd), {type: :command, command: cmd}], args] end alias_method :action_for_channel_post, :action_for_message diff --git a/lib/telegram/bot/updates_controller/instrumentation.rb b/lib/telegram/bot/updates_controller/instrumentation.rb index 112a438..03bd324 100644 --- a/lib/telegram/bot/updates_controller/instrumentation.rb +++ b/lib/telegram/bot/updates_controller/instrumentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController diff --git a/lib/telegram/bot/updates_controller/log_subscriber.rb b/lib/telegram/bot/updates_controller/log_subscriber.rb index 60fe07f..40d0485 100644 --- a/lib/telegram/bot/updates_controller/log_subscriber.rb +++ b/lib/telegram/bot/updates_controller/log_subscriber.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/log_subscriber' module Telegram diff --git a/lib/telegram/bot/updates_controller/message_context.rb b/lib/telegram/bot/updates_controller/message_context.rb index 34d5e31..7443469 100644 --- a/lib/telegram/bot/updates_controller/message_context.rb +++ b/lib/telegram/bot/updates_controller/message_context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController @@ -52,7 +54,7 @@ def action_for_message super || context && begin args = payload['text'].try!(:split) || [] action = action_for_message_context(context) - [[action, type: :message_context, context: context], args] + [[action, {type: :message_context, context: context}], args] end end diff --git a/lib/telegram/bot/updates_controller/reply_helpers.rb b/lib/telegram/bot/updates_controller/reply_helpers.rb index 02a9371..fac4a46 100644 --- a/lib/telegram/bot/updates_controller/reply_helpers.rb +++ b/lib/telegram/bot/updates_controller/reply_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController @@ -59,9 +61,9 @@ def answer_shipping_query(ok, params = {}) # Edit message from callback query. def edit_message(type, params = {}) params = - if message_id = payload['inline_message_id'] # rubocop:disable AssignmentInCondition + if message_id = payload['inline_message_id'] # rubocop:disable Lint/AssignmentInCondition params.merge(inline_message_id: message_id) - elsif message = payload['message'] # rubocop:disable AssignmentInCondition + elsif message = payload['message'] # rubocop:disable Lint/AssignmentInCondition params.merge(chat_id: message['chat']['id'], message_id: message['message_id']) else raise 'Can not edit message without `inline_message_id` or `message`' diff --git a/lib/telegram/bot/updates_controller/rescue.rb b/lib/telegram/bot/updates_controller/rescue.rb index 3a13f8a..37b58b5 100644 --- a/lib/telegram/bot/updates_controller/rescue.rb +++ b/lib/telegram/bot/updates_controller/rescue.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/rescuable' module Telegram @@ -11,7 +13,7 @@ module Rescue def process_action(*) super - rescue Exception => exception # rubocop:disable RescueException + rescue Exception => exception # rubocop:disable Lint/RescueException rescue_with_handler(exception) || raise end end diff --git a/lib/telegram/bot/updates_controller/rspec_helpers.rb b/lib/telegram/bot/updates_controller/rspec_helpers.rb index 16f908d..2f2149a 100644 --- a/lib/telegram/bot/updates_controller/rspec_helpers.rb +++ b/lib/telegram/bot/updates_controller/rspec_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/updates_controller/testing' require 'telegram/bot/rspec/message_helpers' require 'telegram/bot/rspec/callback_query_helpers' diff --git a/lib/telegram/bot/updates_controller/session.rb b/lib/telegram/bot/updates_controller/session.rb index c40313e..086bb2d 100644 --- a/lib/telegram/bot/updates_controller/session.rb +++ b/lib/telegram/bot/updates_controller/session.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack/session/abstract/id' require 'active_support/cache' diff --git a/lib/telegram/bot/updates_controller/testing.rb b/lib/telegram/bot/updates_controller/testing.rb index e1c700b..d4cbdaa 100644 --- a/lib/telegram/bot/updates_controller/testing.rb +++ b/lib/telegram/bot/updates_controller/testing.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController diff --git a/lib/telegram/bot/updates_controller/translation.rb b/lib/telegram/bot/updates_controller/translation.rb index 179f76a..2b4fa84 100644 --- a/lib/telegram/bot/updates_controller/translation.rb +++ b/lib/telegram/bot/updates_controller/translation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController diff --git a/lib/telegram/bot/updates_controller/typed_update.rb b/lib/telegram/bot/updates_controller/typed_update.rb index 78fd985..0cc1aa7 100644 --- a/lib/telegram/bot/updates_controller/typed_update.rb +++ b/lib/telegram/bot/updates_controller/typed_update.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot class UpdatesController diff --git a/lib/telegram/bot/updates_poller.rb b/lib/telegram/bot/updates_poller.rb index c39088c..716858f 100644 --- a/lib/telegram/bot/updates_poller.rb +++ b/lib/telegram/bot/updates_poller.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module Telegram module Bot # Supposed to be used in development environments only. class UpdatesPoller class << self - @@instances = {} # rubocop:disable ClassVars + @@instances = {} # rubocop:disable Style/ClassVars def instances @@instances diff --git a/lib/telegram/bot/version.rb b/lib/telegram/bot/version.rb index d678e4f..05e6cfe 100644 --- a/lib/telegram/bot/version.rb +++ b/lib/telegram/bot/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Telegram module Bot VERSION = '0.16.1'.freeze diff --git a/spec/integration/requests/default_bot_spec.rb b/spec/integration/requests/default_bot_spec.rb index 0f7feed..1ef5753 100644 --- a/spec/integration/requests/default_bot_spec.rb +++ b/spec/integration/requests/default_bot_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'integration_helper' RSpec.describe DefaultBotController, telegram_bot: :rails do diff --git a/spec/integration/requests/named_bot_spec.rb b/spec/integration/requests/named_bot_spec.rb index cccfbd4..0be5575 100644 --- a/spec/integration/requests/named_bot_spec.rb +++ b/spec/integration/requests/named_bot_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'integration_helper' RSpec.describe NamedBotController, telegram_bot: :rails do diff --git a/spec/integration/requests/other_bot_spec.rb b/spec/integration/requests/other_bot_spec.rb index 8ccb783..babd569 100644 --- a/spec/integration/requests/other_bot_spec.rb +++ b/spec/integration/requests/other_bot_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'integration_helper' RSpec.describe OtherBotController, telegram_bot: :rails do diff --git a/spec/integration_helper.rb b/spec/integration_helper.rb index e876124..2bb0796 100644 --- a/spec/integration_helper.rb +++ b/spec/integration_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/rails' require 'action_controller' require 'action_dispatch' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1be5648..1dd9ff9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pathname' require 'pry' require 'rspec/its' @@ -10,7 +12,7 @@ SimpleCov.start end -GEM_ROOT = Pathname.new File.expand_path('../..', __FILE__) +GEM_ROOT = Pathname.new File.expand_path('..', __dir__) $LOAD_PATH.unshift GEM_ROOT.join('lib') require 'telegram/bot' diff --git a/spec/support/examples/async.rb b/spec/support/examples/async.rb index 683a01e..91fb1b3 100644 --- a/spec/support/examples/async.rb +++ b/spec/support/examples/async.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples 'async' do |request_args:| let(:instance) { described_class.new(token: token, id: id, async: async) } let(:id) { :default_bot } diff --git a/spec/support/examples/integration.rb b/spec/support/examples/integration.rb index cb79400..0f78553 100644 --- a/spec/support/examples/integration.rb +++ b/spec/support/examples/integration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.shared_examples 'shared integration examples' do let(:bot) { Telegram::Bot::ClientStub.new('token') } let(:controller_class) do diff --git a/spec/telegram/bot/async_spec.rb b/spec/telegram/bot/async_spec.rb index ce13e43..216aeec 100644 --- a/spec/telegram/bot/async_spec.rb +++ b/spec/telegram/bot/async_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::Async::Job do let(:job_class) do described_class = self.described_class diff --git a/spec/telegram/bot/client/request_body_formatter_spec.rb b/spec/telegram/bot/client/request_body_formatter_spec.rb index 35a1e6a..35f5134 100644 --- a/spec/telegram/bot/client/request_body_formatter_spec.rb +++ b/spec/telegram/bot/client/request_body_formatter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::Client::RequestBodyFormatter do describe '.format' do subject { described_class.format(input, action) } diff --git a/spec/telegram/bot/client/typed_response_spec.rb b/spec/telegram/bot/client/typed_response_spec.rb index d8eb476..681d336 100644 --- a/spec/telegram/bot/client/typed_response_spec.rb +++ b/spec/telegram/bot/client/typed_response_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::Client::TypedResponse do let(:bot) { Telegram::Bot::Client.new('token').tap { |x| x.extend described_class } } diff --git a/spec/telegram/bot/client_spec.rb b/spec/telegram/bot/client_spec.rb index e787ba0..2b1e769 100644 --- a/spec/telegram/bot/client_spec.rb +++ b/spec/telegram/bot/client_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::Client do let(:instance) { described_class.new 'token' } let(:token) { 'token' } @@ -73,8 +75,8 @@ describe '.prepare_async_args' do subject { described_class.prepare_async_args(*input) } - let(:input) { [:action, a: 1, b: :sym, c: [:other], 'd' => 'str'] } - it { should eq ['action', a: 1, b: 'sym', c: '["other"]', 'd' => 'str'] } + let(:input) { [:action, {a: 1, b: :sym, c: [:other], 'd' => 'str'}] } + it { should eq ['action', {a: 1, b: 'sym', c: '["other"]', 'd' => 'str'}] } end describe '.new' do diff --git a/spec/telegram/bot/client_stub_spec.rb b/spec/telegram/bot/client_stub_spec.rb index 655ad08..4d2dfdb 100644 --- a/spec/telegram/bot/client_stub_spec.rb +++ b/spec/telegram/bot/client_stub_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::ClientStub do describe '#stub_all!' do let(:client) { Telegram::Bot::Client.new('token', 'bot_name') } - let(:clients) { ['token', token: 'token2'].map(&Telegram::Bot::Client.method(:wrap)) } + let(:clients) { ['token', {token: 'token2'}].map(&Telegram::Bot::Client.method(:wrap)) } shared_examples 'constructors' do |expected_class| it 'makes Client.new return ClientStub' do diff --git a/spec/telegram/bot/config_methods_spec.rb b/spec/telegram/bot/config_methods_spec.rb index e8acd96..e946378 100644 --- a/spec/telegram/bot/config_methods_spec.rb +++ b/spec/telegram/bot/config_methods_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::ConfigMethods do let(:registry) do Object.new.tap do |x| diff --git a/spec/telegram/bot/middleware_spec.rb b/spec/telegram/bot/middleware_spec.rb index 3a465bf..f4d5113 100644 --- a/spec/telegram/bot/middleware_spec.rb +++ b/spec/telegram/bot/middleware_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack/mock' RSpec.describe Telegram::Bot::Middleware do diff --git a/spec/telegram/bot/routes_helper_spec.rb b/spec/telegram/bot/routes_helper_spec.rb index ed9049b..55b8e4c 100644 --- a/spec/telegram/bot/routes_helper_spec.rb +++ b/spec/telegram/bot/routes_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/routes_helper' RSpec.describe Telegram::Bot::RoutesHelper do @@ -46,7 +48,7 @@ def create_bot(*args) let(:controller) { double(:controller, name: :controller) } before { allow(Telegram).to receive(:bots) { bots } } - def assert_route(bot, controller, path: nil, **expected_options) # rubocop:disable AbcSize + def assert_route(bot, controller, path: nil, **expected_options) # rubocop:disable Metrics/AbcSize path ||= "telegram/#{described_class.token_hash(bot.token)}" expect(mapper).to receive(:post) do |actual_path, actual_options| expect(actual_path).to eq(path) diff --git a/spec/telegram/bot/rspec/callback_query_helpers_spec.rb b/spec/telegram/bot/rspec/callback_query_helpers_spec.rb index f32397e..1820c2d 100644 --- a/spec/telegram/bot/rspec/callback_query_helpers_spec.rb +++ b/spec/telegram/bot/rspec/callback_query_helpers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/poller' RSpec.describe 'Integration spec helpers', telegram_bot: :poller do diff --git a/spec/telegram/bot/rspec/client_matchers_spec.rb b/spec/telegram/bot/rspec/client_matchers_spec.rb index 9292190..c441877 100644 --- a/spec/telegram/bot/rspec/client_matchers_spec.rb +++ b/spec/telegram/bot/rspec/client_matchers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::RSpec::ClientMatchers do let(:bot) { Telegram::Bot::ClientStub.new('TestBot') } let(:other_bot) { Telegram::Bot::ClientStub.new('OtherTestBot') } diff --git a/spec/telegram/bot/rspec/integration/poller_spec.rb b/spec/telegram/bot/rspec/integration/poller_spec.rb index c83723f..5e2d5a0 100644 --- a/spec/telegram/bot/rspec/integration/poller_spec.rb +++ b/spec/telegram/bot/rspec/integration/poller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/poller' RSpec.describe 'Poller integration spec', telegram_bot: :poller do diff --git a/spec/telegram/bot/rspec/integration/rack_spec.rb b/spec/telegram/bot/rspec/integration/rack_spec.rb index 0dcfb53..19a48fa 100644 --- a/spec/telegram/bot/rspec/integration/rack_spec.rb +++ b/spec/telegram/bot/rspec/integration/rack_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/rack' RSpec.describe 'Rack integration spec', telegram_bot: :rack do diff --git a/spec/telegram/bot/rspec/integration/rails_spec.rb b/spec/telegram/bot/rspec/integration/rails_spec.rb index 05c498e..9796c07 100644 --- a/spec/telegram/bot/rspec/integration/rails_spec.rb +++ b/spec/telegram/bot/rspec/integration/rails_spec.rb @@ -1 +1,2 @@ +# frozen_string_literal: true # Tested in spec/integration diff --git a/spec/telegram/bot/rspec/message_helpers_spec.rb b/spec/telegram/bot/rspec/message_helpers_spec.rb index 63fb315..6781641 100644 --- a/spec/telegram/bot/rspec/message_helpers_spec.rb +++ b/spec/telegram/bot/rspec/message_helpers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'telegram/bot/rspec/integration/poller' RSpec.describe 'Integration: message helpers', telegram_bot: :poller do @@ -108,7 +110,7 @@ def start!(*args) end context 'with options' do - let(:args) { ['asd', 'qwe', option: 1] } + let(:args) { ['asd', 'qwe', {option: 1}] } it { should respond_with_message "Start: #{args[0...-1].inspect}, option: 1" } end end diff --git a/spec/telegram/bot/updates_controller/callback_query_context_spec.rb b/spec/telegram/bot/updates_controller/callback_query_context_spec.rb index 757e939..3f0577f 100644 --- a/spec/telegram/bot/updates_controller/callback_query_context_spec.rb +++ b/spec/telegram/bot/updates_controller/callback_query_context_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::CallbackQueryContext do include_context 'telegram/bot/updates_controller' let(:controller_class) do @@ -6,7 +8,7 @@ include described_class attr_accessor :filter_done - before_action only: :ctx2_callback_query do + before_action only: :ctx_2_callback_query do self.filter_done = true end @@ -14,12 +16,12 @@ def callback_query(data) [:no_context, data] end - def ctx1_callback_query(data) - [:ctx1, data] + def ctx_1_callback_query(data) + [:ctx_1, data] end - def ctx2_callback_query(data) - [:ctx2, data] + def ctx_2_callback_query(data) + [:ctx_2, data] end end end @@ -40,19 +42,19 @@ def ctx2_callback_query(data) let(:data) { "#{ctx}:#{text}" } context 'and valid' do - let(:ctx) { 'ctx1' } - its(:call) { should eq [:ctx1, text] } + let(:ctx) { 'ctx_1' } + its(:call) { should eq [:ctx_1, text] } it { should_not change(controller, :filter_done) } context 'and context has callback' do - let(:ctx) { 'ctx2' } - its(:call) { should eq [:ctx2, text] } + let(:ctx) { 'ctx_2' } + its(:call) { should eq [:ctx_2, text] } it { should change(controller, :filter_done) } end context 'and data has multiple colons' do let(:text) { super().tr(' ', ':') } - its(:call) { should eq [:ctx1, text] } + its(:call) { should eq [:ctx_1, text] } end end diff --git a/spec/telegram/bot/updates_controller/commands_spec.rb b/spec/telegram/bot/updates_controller/commands_spec.rb index 5dfb196..2416db3 100644 --- a/spec/telegram/bot/updates_controller/commands_spec.rb +++ b/spec/telegram/bot/updates_controller/commands_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::Commands do describe '#action_for_command' do subject { ->(*args) { object.action_for_command(*args) } } @@ -88,11 +90,11 @@ def assert_subject(input, cmd, *args) context 'with command' do let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" } let(:mention) {} - it { should eq [['test!', type: :command, command: 'test'], %w[arg 1 2]] } + it { should eq [['test!', {type: :command, command: 'test'}], %w[arg 1 2]] } context 'with mention' do let(:mention) { bot.username } - it { should eq [['test!', type: :command, command: 'test'], %w[arg 1 2]] } + it { should eq [['test!', {type: :command, command: 'test'}], %w[arg 1 2]] } end context 'with mention for other bot' do diff --git a/spec/telegram/bot/updates_controller/instrumentation_spec.rb b/spec/telegram/bot/updates_controller/instrumentation_spec.rb index cb0c190..8229bd9 100644 --- a/spec/telegram/bot/updates_controller/instrumentation_spec.rb +++ b/spec/telegram/bot/updates_controller/instrumentation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::Instrumentation do include_context 'telegram/bot/updates_controller' diff --git a/spec/telegram/bot/updates_controller/message_context_spec.rb b/spec/telegram/bot/updates_controller/message_context_spec.rb index 9ab4952..36ed6f4 100644 --- a/spec/telegram/bot/updates_controller/message_context_spec.rb +++ b/spec/telegram/bot/updates_controller/message_context_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::MessageContext do include_context 'telegram/bot/updates_controller' let(:controller_class) do diff --git a/spec/telegram/bot/updates_controller/reply_helpers_spec.rb b/spec/telegram/bot/updates_controller/reply_helpers_spec.rb index e5ad3b8..2577adc 100644 --- a/spec/telegram/bot/updates_controller/reply_helpers_spec.rb +++ b/spec/telegram/bot/updates_controller/reply_helpers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController do include_context 'telegram/bot/updates_controller' let(:params) { {arg: 1, 'other_arg' => 2} } @@ -38,7 +40,7 @@ end context 'when update is not set' do - let(:controller_args) { [bot, chat: deep_stringify(chat)] } + let(:controller_args) { [bot, {chat: deep_stringify(chat)}] } it 'sets chat_id' do expect(bot).to receive("send_#{respond_type}"). with(params.merge(chat_id: chat[:id])) { result } diff --git a/spec/telegram/bot/updates_controller/rescue_spec.rb b/spec/telegram/bot/updates_controller/rescue_spec.rb index d7dd275..8ff5a6e 100644 --- a/spec/telegram/bot/updates_controller/rescue_spec.rb +++ b/spec/telegram/bot/updates_controller/rescue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::Rescue do include_context 'telegram/bot/updates_controller' diff --git a/spec/telegram/bot/updates_controller/session_spec.rb b/spec/telegram/bot/updates_controller/session_spec.rb index 8bb092a..ec2c804 100644 --- a/spec/telegram/bot/updates_controller/session_spec.rb +++ b/spec/telegram/bot/updates_controller/session_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::Session do include_context 'telegram/bot/updates_controller' let(:controller_class) do diff --git a/spec/telegram/bot/updates_controller/testing_spec.rb b/spec/telegram/bot/updates_controller/testing_spec.rb index fcc4fe1..785665b 100644 --- a/spec/telegram/bot/updates_controller/testing_spec.rb +++ b/spec/telegram/bot/updates_controller/testing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'action_dispatch' RSpec.describe Telegram::Bot::UpdatesController::Testing do diff --git a/spec/telegram/bot/updates_controller/translation_spec.rb b/spec/telegram/bot/updates_controller/translation_spec.rb index 3368527..991c11c 100644 --- a/spec/telegram/bot/updates_controller/translation_spec.rb +++ b/spec/telegram/bot/updates_controller/translation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::Translation do def self.stub_translations(translations) around do |ex| diff --git a/spec/telegram/bot/updates_controller/typed_update_spec.rb b/spec/telegram/bot/updates_controller/typed_update_spec.rb index c74586c..877ce3b 100644 --- a/spec/telegram/bot/updates_controller/typed_update_spec.rb +++ b/spec/telegram/bot/updates_controller/typed_update_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController::TypedUpdate do include_context 'telegram/bot/updates_controller' let(:controller_class) do diff --git a/spec/telegram/bot/updates_controller_spec.rb b/spec/telegram/bot/updates_controller_spec.rb index e7e3860..5f63dcf 100644 --- a/spec/telegram/bot/updates_controller_spec.rb +++ b/spec/telegram/bot/updates_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesController do include_context 'telegram/bot/updates_controller' @@ -90,7 +92,7 @@ def stub_payload(*fields) describe '#process' do subject { -> { controller.process(:action, *args) } } - let(:args) { %i[arg1 arg2] } + let(:args) { %i[arg_1 arg_2] } let(:controller_class) do Class.new(described_class) do attr_reader :acted, :hooked @@ -198,7 +200,7 @@ def self.with_reinitialize(&block) end context 'when options hash is given' do - let(:controller_args) { [bot, from: from, chat: chat] } + let(:controller_args) { [bot, {from: from, chat: chat}] } with_reinitialize do its(:bot) { should eq bot } its(:update) { should eq nil } diff --git a/spec/telegram/bot/updates_poller_spec.rb b/spec/telegram/bot/updates_poller_spec.rb index 1a13bbb..aaa5177 100644 --- a/spec/telegram/bot/updates_poller_spec.rb +++ b/spec/telegram/bot/updates_poller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot::UpdatesPoller do let(:instance) { described_class.new(bot, controller) } let(:bot) { Telegram::Bot::Client.new('token') } diff --git a/spec/telegram/bot_spec.rb b/spec/telegram/bot_spec.rb index 19a51f4..fd54622 100644 --- a/spec/telegram/bot_spec.rb +++ b/spec/telegram/bot_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.describe Telegram::Bot do it 'has a version number' do expect(described_class::VERSION).not_to be nil diff --git a/telegram-bot.gemspec b/telegram-bot.gemspec index a71ca53..ae97f06 100644 --- a/telegram-bot.gemspec +++ b/telegram-bot.gemspec @@ -1,4 +1,6 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'telegram/bot/version' @@ -12,6 +14,10 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/telegram-bot-rb/telegram-bot' spec.license = 'MIT' + spec.metadata = { + 'rubygems_mfa_required' => 'true', + } + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) } spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }