module SlackMessage::RSpec
TODO: test helpers for scheduled messages, editing and deleting, and notification text. And realistically, overhaul all this.
Constants
- FauxResponse
Public Class Methods
included(_)
click to toggle source
# File lib/slack_message/rspec.rb, line 42 def self.included(_) SlackMessage::Api.undef_method(:post_message) SlackMessage::Api.define_singleton_method(:post_message) do |profile, params| @@listeners.each do |listener| listener.record_call(params.merge(profile: profile)) end response = { "ok" => true, "channel" => "C12345678", "ts" => "1635863996.002300", "message" => { "type"=>"message", "subtype"=>"bot_message", "text"=>"foo", "ts"=>"1635863996.002300", "username"=>"SlackMessage", "icons"=>{"emoji"=>":successkid:"}, "bot_id"=>"B1234567890", "blocks"=> [{"type"=>"section", "block_id"=>"hAh7", "text"=>{"type"=>"mrkdwn", "text"=>"foo", "verbatim"=>false}} ] } }.merge(@@custom_response).to_json return FauxResponse.new(@@response_code, response) end SlackMessage::Api.undef_method(:look_up_user_by_email) SlackMessage::Api.define_singleton_method(:look_up_user_by_email) do |email, profile| response = {"ok"=>true, "user"=>{"id"=>"U5432CBA"}} return FauxResponse.new('200', response.to_json) end end
register_expectation_listener(expectation_instance)
click to toggle source
# File lib/slack_message/rspec.rb, line 27 def self.register_expectation_listener(expectation_instance) @@listeners << expectation_instance end
reset_custom_responses()
click to toggle source
# File lib/slack_message/rspec.rb, line 35 def self.reset_custom_responses @@custom_response = {} @@response_code = '200' end
reset_mock_response()
click to toggle source
# File lib/slack_message/rspec.rb, line 83 def self.reset_mock_response @@custom_response = {} @@response_code = '200' end
respond_with(response = {}, code: '200')
click to toggle source
# File lib/slack_message/rspec.rb, line 76 def self.respond_with(response = {}, code: '200') raise ArgumentError, "custom response must be a hash" unless response.is_a? Hash @@custom_response = response @@response_code = code end
unregister_expectation_listener(expectation_instance)
click to toggle source
# File lib/slack_message/rspec.rb, line 31 def self.unregister_expectation_listener(expectation_instance) @@listeners.delete(expectation_instance) end