Sha256: 3f1309722601730cc68054a82955def58f7c5ff0e2633c92c80436f4c26c291c

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

require 'telegram/bot/updates_controller/testing'
require 'telegram/bot/rspec/message_helpers'
require 'telegram/bot/rspec/callback_query_helpers'

RSpec.shared_context 'telegram/bot/updates_controller' do
  include Telegram::Bot::RSpec::ClientMatchers
  include_context 'telegram/bot/message_helpers'
  include_context 'telegram/bot/callback_query', :callback_query

  let(:controller_class) { described_class }
  let(:controller) do
    controller_class.new(*controller_args).tap do |x|
      x.extend Telegram::Bot::UpdatesController::Testing
    end
  end
  let(:controller_args) { [bot, deep_stringify(update)] }
  let(:update) { {payload_type => payload} }
  let(:payload_type) { :some_type }
  let(:payload) { double(:payload) }
  let(:bot) { Telegram::Bot::ClientStub.new(bot_name) }
  let(:bot_name) { 'bot' }
  let(:session) { controller.send(:session) }

  # Process update.
  def dispatch(update = self.update, bot = self.bot)
    controller.dispatch_again(bot, deep_stringify(update))
  end

  # Same as `.as_json` but mocks-friendly.
  def deep_stringify(input)
    case input
    when Array then input.map(&method(__callee__))
    when Hash then input.map { |k, v| [k.to_s, deep_stringify(v)] }.to_h
    else input
    end
  end
end

Telegram::Bot::RSpec.with_include_context do |config|
  config.include_context 'telegram/bot/updates_controller', type: :telegram_bot_controller
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
telegram-bot-0.15.7 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.6 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.4 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.3 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.2 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.1 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.15.0 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.14.4 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.14.3 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.14.2 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.14.1 lib/telegram/bot/updates_controller/rspec_helpers.rb
telegram-bot-0.14.0 lib/telegram/bot/updates_controller/rspec_helpers.rb