Module: BoltRb::Testing::RSpecHelpers
- Defined in:
- lib/bolt_rb/testing/rspec_helpers.rb
Overview
RSpec helper methods for testing Bolt handlers
Include this module in your RSpec configuration to get convenient methods for building contexts and mocking Slack clients.
Instance Method Summary collapse
-
#build_context(payload, client: nil, ack: nil) ⇒ BoltRb::Context
Builds a Context object from a payload for testing.
-
#mock_slack_client ⇒ RSpec::Mocks::Double
Creates a mock Slack Web API client with common methods stubbed.
-
#payload ⇒ Class
Convenience accessor for the PayloadFactory.
Instance Method Details
#build_context(payload, client: nil, ack: nil) ⇒ BoltRb::Context
Builds a Context object from a payload for testing
30 31 32 33 34 35 36 |
# File 'lib/bolt_rb/testing/rspec_helpers.rb', line 30 def build_context(payload, client: nil, ack: nil) BoltRb::Context.new( payload: payload, client: client || mock_slack_client, ack: ack || ->(_) {} ) end |
#mock_slack_client ⇒ RSpec::Mocks::Double
Creates a mock Slack Web API client with common methods stubbed
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bolt_rb/testing/rspec_helpers.rb', line 41 def mock_slack_client client = instance_double(Slack::Web::Client) allow(client).to receive(:chat_postMessage).and_return({ 'ok' => true, 'ts' => '123.456' }) allow(client).to receive(:chat_update).and_return({ 'ok' => true }) allow(client).to receive(:views_open).and_return({ 'ok' => true }) allow(client).to receive(:views_update).and_return({ 'ok' => true }) allow(client).to receive(:assistant_threads_setStatus).and_return({ 'ok' => true }) allow(client).to receive(:assistant_threads_setTitle).and_return({ 'ok' => true }) allow(client).to receive(:assistant_threads_setSuggestedPrompts).and_return({ 'ok' => true }) client end |
#payload ⇒ Class
Convenience accessor for the PayloadFactory
60 61 62 |
# File 'lib/bolt_rb/testing/rspec_helpers.rb', line 60 def payload BoltRb::Testing::PayloadFactory end |