зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 17:55:52 +03:00
Testing: run multiple dispatches on same instance
Этот коммит содержится в:
27
spec/telegram/bot/updates_controller/testing_spec.rb
Обычный файл
27
spec/telegram/bot/updates_controller/testing_spec.rb
Обычный файл
@@ -0,0 +1,27 @@
|
||||
RSpec.describe Telegram::Bot::UpdatesController::Testing do
|
||||
include_context 'telegram/bot/updates_controller'
|
||||
let(:controller_class) do
|
||||
Class.new(Telegram::Bot::UpdatesController) do
|
||||
attr_accessor :ivar
|
||||
end
|
||||
end
|
||||
|
||||
describe '#recycle!' do
|
||||
subject { -> { controller.recycle!(full) } }
|
||||
before do
|
||||
controller.ivar = :ival
|
||||
session[:key] = 'sval'
|
||||
end
|
||||
let(:full) {}
|
||||
|
||||
it { should_not change(controller, :ivar).from :ival }
|
||||
it { should_not change { controller.send(:session)[:key] }.from 'sval' }
|
||||
|
||||
context 'when full is true' do
|
||||
let(:full) { true }
|
||||
it { should change(controller, :ivar).from(:ival).to nil }
|
||||
it { should change { controller.instance_variable_defined?(:@ivar) }.to false }
|
||||
it { should_not change { controller.send(:session)[:key] }.from 'sval' }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,7 +8,7 @@ RSpec.describe Telegram::Bot::UpdatesController::TypedUpdate do
|
||||
end
|
||||
|
||||
context 'when `update` is a virtus model' do
|
||||
subject { instance }
|
||||
subject { controller }
|
||||
%w(
|
||||
message
|
||||
inline_query
|
||||
|
||||
@@ -78,7 +78,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
|
||||
describe '#action_for_payload' do
|
||||
subject { instance.action_for_payload }
|
||||
subject { controller.action_for_payload }
|
||||
|
||||
(described_class::PAYLOAD_TYPES - %w(message)).each do |type|
|
||||
context "when payload is #{type}" do
|
||||
@@ -113,7 +113,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
|
||||
context 'when `update` is a virtus model' do
|
||||
subject { instance }
|
||||
subject { controller }
|
||||
let(:update) { Telegram::Bot::Types::Update.new(super()) }
|
||||
%w(
|
||||
message
|
||||
@@ -131,7 +131,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
|
||||
describe '#bot_username' do
|
||||
subject { instance.bot_username }
|
||||
subject { controller.bot_username }
|
||||
|
||||
context 'when bot is not set' do
|
||||
let(:bot) {}
|
||||
@@ -145,7 +145,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
|
||||
describe '#process_action' do
|
||||
subject { -> { instance.process_action(:action) } }
|
||||
subject { -> { controller.process_action(:action) } }
|
||||
|
||||
context 'when callbacks are defined' do
|
||||
let(:controller_class) do
|
||||
@@ -165,8 +165,8 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end
|
||||
end
|
||||
|
||||
it { should change(instance, :hooked).to true }
|
||||
it { should change(instance, :acted).to true }
|
||||
it { should change(controller, :hooked).to true }
|
||||
it { should change(controller, :acted).to true }
|
||||
|
||||
context 'when callback returns false' do
|
||||
before do
|
||||
@@ -178,8 +178,8 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
||||
end)
|
||||
end
|
||||
|
||||
it { should change(instance, :hooked).to true }
|
||||
it { should_not change(instance, :acted).from nil }
|
||||
it { should change(controller, :hooked).to true }
|
||||
it { should_not change(controller, :acted).from nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Ссылка в новой задаче
Block a user