зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-04 02:05:52 +03:00
Ruby 3.0 support, drop support for Ruby < 2.4
Этот коммит содержится в:
@@ -1,4 +1,4 @@
|
||||
RSpec.shared_examples 'async' do |request_args: -> {}|
|
||||
RSpec.shared_examples 'async' do |request_args:|
|
||||
let(:instance) { described_class.new(token: token, id: id, async: async) }
|
||||
let(:id) { :default_bot }
|
||||
let(:async) { true }
|
||||
@@ -103,7 +103,7 @@ RSpec.shared_examples 'async' do |request_args: -> {}|
|
||||
end
|
||||
|
||||
describe '#request' do
|
||||
subject { ->(*args) { instance.request(*(args.empty? ? self.args : args)) } }
|
||||
subject { ->(*args) { instance.request(*args) } }
|
||||
let(:args, &request_args)
|
||||
let(:result) { double(:result) }
|
||||
|
||||
@@ -112,7 +112,7 @@ RSpec.shared_examples 'async' do |request_args: -> {}|
|
||||
expect(instance).to_not receive(:http_request)
|
||||
expect(described_class).to receive(:prepare_async_args).with(*args) { args }
|
||||
expect(instance.async).to receive(:perform_later).with(id.to_s, *args) { result }
|
||||
expect(subject.call).to eq result
|
||||
expect(subject.call(*args)).to eq result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,12 +131,11 @@ RSpec.shared_examples 'async' do |request_args: -> {}|
|
||||
context 'when async is disabled' do
|
||||
let(:async) { false }
|
||||
let(:result) { double(status: 200, body: '{"test":"ok"}') }
|
||||
let(:args, &request_args)
|
||||
|
||||
it 'performs request immediately' do
|
||||
expect(instance).to receive(:request).with(*args).and_call_original
|
||||
expect(instance).to receive(:http_request) { result }
|
||||
expect(subject[]).to eq 'test' => 'ok'
|
||||
expect(subject.call(*args)).to eq 'test' => 'ok'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,10 @@ RSpec.describe Telegram::Bot::Client do
|
||||
let(:input) { token }
|
||||
|
||||
it 'treats string as token' do
|
||||
expect(described_class).to receive(:new).with(token, {}) { result }
|
||||
expect(described_class).to receive(:new) do |*args, **kwargs|
|
||||
expect([*args, kwargs]).to eq([token, {}]) # not using .with to support ruby 2.x and 3.x
|
||||
result
|
||||
end
|
||||
should eq result
|
||||
end
|
||||
|
||||
@@ -94,7 +97,9 @@ RSpec.describe Telegram::Bot::Client do
|
||||
end
|
||||
|
||||
describe '.new' do
|
||||
subject { described_class.new(*args) }
|
||||
subject { described_class.new(*args, **kwargs) }
|
||||
let(:args) { [] }
|
||||
let(:kwargs) { {} }
|
||||
let(:token) { 'secret' }
|
||||
let(:username) { 'superbot' }
|
||||
|
||||
@@ -106,7 +111,7 @@ RSpec.describe Telegram::Bot::Client do
|
||||
end
|
||||
|
||||
context 'when hash is given' do
|
||||
let(:args) { [token: 'secret', username: 'superbot'] }
|
||||
let(:kwargs) { {token: 'secret', username: 'superbot'} }
|
||||
its(:token) { should eq token }
|
||||
its(:username) { should eq username }
|
||||
its(:base_uri) { should eq "#{described_class::SERVER}/bot#{token}/" }
|
||||
@@ -114,11 +119,12 @@ RSpec.describe Telegram::Bot::Client do
|
||||
|
||||
context 'with custom server' do
|
||||
let(:server) { 'http://my.server' }
|
||||
let(:args) { [token, username, server: server] }
|
||||
let(:args) { [token, username] }
|
||||
let(:kwargs) { {server: server} }
|
||||
its(:base_uri) { should eq "#{server}/bot#{token}/" }
|
||||
|
||||
context 'and hash options' do
|
||||
let(:args) { [token: token, username: username, server: server] }
|
||||
let(:kwargs) { {token: token, username: username, server: server} }
|
||||
its(:base_uri) { should eq "#{server}/bot#{token}/" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,11 +37,13 @@ RSpec.describe Telegram::Bot::ClientStub do
|
||||
end
|
||||
|
||||
describe '#new' do
|
||||
subject { described_class.new(*args) }
|
||||
subject { described_class.new(*args, **kwargs) }
|
||||
let(:args) { [] }
|
||||
let(:kwargs) { {} }
|
||||
|
||||
context 'when only username is given' do
|
||||
let(:args) { 'superbot' }
|
||||
its(:username) { should eq args }
|
||||
let(:args) { ['superbot'] }
|
||||
its(:username) { should eq args[0] }
|
||||
end
|
||||
|
||||
context 'when username and token are given' do
|
||||
@@ -51,9 +53,9 @@ RSpec.describe Telegram::Bot::ClientStub do
|
||||
end
|
||||
|
||||
context 'when hash config is given' do
|
||||
let(:args) { [token: 'token', username: 'superbot'] }
|
||||
its(:token) { should eq args[0][:token] }
|
||||
its(:username) { should eq args[0][:username] }
|
||||
let(:kwargs) { {token: 'token', username: 'superbot'} }
|
||||
its(:token) { should eq kwargs[:token] }
|
||||
its(:username) { should eq kwargs[:username] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,7 +41,7 @@ RSpec.describe Telegram::Bot::RoutesHelper do
|
||||
end
|
||||
|
||||
describe '#telegram_webhook' do
|
||||
subject { ->(*args) { mapper.telegram_webhook(*args) } }
|
||||
subject { ->(*args, **kwargs) { mapper.telegram_webhook(*args, **kwargs) } }
|
||||
let(:mapper) { double(:mapper).tap { |x| x.extend described_class } }
|
||||
let(:controller) { double(:controller, name: :controller) }
|
||||
before { allow(Telegram).to receive(:bots) { bots } }
|
||||
|
||||
Ссылка в новой задаче
Block a user