-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
start_typing.rb
32 lines (23 loc) · 917 Bytes
/
start_typing.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
require 'rspec/expectations'
RSpec::Matchers.define :start_typing do |expected|
include SlackRubyBot::SpecHelpers
match do |actual|
client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new
message_command = SlackRubyBot::Hooks::Message.new
allow(client).to receive(:typing) do |options|
@test_options = options
end
channel, user, message, attachments = parse(actual)
message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments))
matcher = have_received(:typing).once
matcher = matcher.with(expected) if expected&.any?
expect(client).to matcher
true
end
failure_message do |_actual|
message = "expected to receive typing with: #{expected} once,\n received:"
message += @test_options&.any? ? @test_options.inspect : ' none'
message
end
end