зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-04 10:15:50 +03:00
Update rubopcop (#227)
* Update rubopcop [WIP] * Further rubocop fixes * Fix rubocop-rails cops * Fix spec * Disable rubocop suggestions * Run rubocop in github actions rather than in codeclimate
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7bcb0caded
Коммит
57b17f068c
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'integration_helper'
|
||||
|
||||
RSpec.describe DefaultBotController, telegram_bot: :rails do
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'integration_helper'
|
||||
|
||||
RSpec.describe NamedBotController, telegram_bot: :rails do
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'integration_helper'
|
||||
|
||||
RSpec.describe OtherBotController, telegram_bot: :rails do
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'telegram/bot/rspec/integration/rails'
|
||||
require 'action_controller'
|
||||
require 'action_dispatch'
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'pathname'
|
||||
require 'pry'
|
||||
require 'rspec/its'
|
||||
@@ -10,7 +12,7 @@ elsif ENV.key?('COV')
|
||||
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'
|
||||
@@ -18,7 +20,7 @@ require 'telegram/bot/updates_controller/rspec_helpers'
|
||||
require 'telegram/bot/types'
|
||||
require 'active_support/json'
|
||||
|
||||
Dir[GEM_ROOT.join('spec/support/**/*.rb')].each { |f| require f }
|
||||
Dir[GEM_ROOT.join('spec/support/**/*.rb')].sort.each { |f| require f }
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.expect_with :rspec do |expectations|
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::Async::Job do
|
||||
let(:job_class) do
|
||||
described_class = self.described_class
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::Client::RequestBodyFormatter do
|
||||
describe '.format' do
|
||||
subject { described_class.format(input, action) }
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
|
||||
@@ -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 @@ RSpec.describe Telegram::Bot::Client do
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::ConfigMethods do
|
||||
let(:registry) do
|
||||
Object.new.tap do |x|
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rack/mock'
|
||||
|
||||
RSpec.describe Telegram::Bot::Middleware do
|
||||
@@ -11,7 +13,7 @@ RSpec.describe Telegram::Bot::Middleware do
|
||||
let(:env) do
|
||||
Rack::MockRequest.env_for('/',
|
||||
method: :post,
|
||||
input: JSON.dump(update),
|
||||
input: JSON.dump(update),
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
)
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'telegram/bot/routes_helper'
|
||||
|
||||
RSpec.describe Telegram::Bot::RoutesHelper do
|
||||
@@ -46,7 +48,7 @@ RSpec.describe Telegram::Bot::RoutesHelper do
|
||||
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)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'telegram/bot/rspec/integration/poller'
|
||||
|
||||
RSpec.describe 'Integration spec helpers', telegram_bot: :poller do
|
||||
|
||||
@@ -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') }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'telegram/bot/rspec/integration/poller'
|
||||
|
||||
RSpec.describe 'Poller integration spec', telegram_bot: :poller do
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'telegram/bot/rspec/integration/rack'
|
||||
|
||||
RSpec.describe 'Rack integration spec', telegram_bot: :rack do
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
# frozen_string_literal: true
|
||||
# Tested in spec/integration
|
||||
|
||||
@@ -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 @@ RSpec.describe 'Integration: message helpers', telegram_bot: :poller do
|
||||
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
|
||||
|
||||
@@ -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,8 @@ RSpec.describe Telegram::Bot::UpdatesController::CallbackQueryContext do
|
||||
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 +17,12 @@ RSpec.describe Telegram::Bot::UpdatesController::CallbackQueryContext do
|
||||
[: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 +43,19 @@ RSpec.describe Telegram::Bot::UpdatesController::CallbackQueryContext do
|
||||
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
|
||||
|
||||
|
||||
@@ -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 @@ RSpec.describe Telegram::Bot::UpdatesController::Commands do
|
||||
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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Instrumentation do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -6,11 +8,13 @@ RSpec.describe Telegram::Bot::UpdatesController::MessageContext do
|
||||
include described_class
|
||||
|
||||
attr_accessor :filter_done
|
||||
|
||||
before_action only: :context_with_filter do
|
||||
self.filter_done = true
|
||||
end
|
||||
|
||||
attr_reader :callbacks_runs
|
||||
|
||||
before_action { @callbacks_runs = (@callbacks_runs || 0) + 1 }
|
||||
|
||||
def message(*args)
|
||||
|
||||
@@ -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 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
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 }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Rescue do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'action_dispatch'
|
||||
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Testing do
|
||||
@@ -43,7 +45,7 @@ RSpec.describe Telegram::Bot::UpdatesController::Testing do
|
||||
|
||||
context 'when webhook_request is given' do
|
||||
it 'passes it to controller' do
|
||||
webhook_request = ::ActionDispatch::Request.new({})
|
||||
webhook_request = ActionDispatch::Request.new({})
|
||||
dispatch(update, bot, webhook_request)
|
||||
expect(controller.webhook_request).to eq webhook_request
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Translation do
|
||||
def self.stub_translations(translations)
|
||||
around do |ex|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Telegram::Bot::UpdatesController do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
|
||||
@@ -5,7 +7,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
subject { controller.action_for_payload }
|
||||
|
||||
def stub_payload(*fields)
|
||||
Hash[fields.map { |x| [x, double(x)] }]
|
||||
fields.map { |x| [x, double(x)] }.to_h
|
||||
end
|
||||
|
||||
context 'when payload is inline_query' do
|
||||
@@ -90,7 +92,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
|
||||
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 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
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 }
|
||||
|
||||
@@ -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') }
|
||||
|
||||
@@ -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
|
||||
|
||||
Ссылка в новой задаче
Block a user