Sha256: ad138baec53dc3609b83341a309cf5dbeb44ec332985798d2b62020f432c3928

Contents?: true

Size: 807 Bytes

Versions: 7

Compression:

Stored size: 807 Bytes

Contents

# frozen_string_literal: true

require 'rspec/expectations'

RSpec::Matchers.define :not_respond do
  match do |actual|
    client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new

    message_command = SlackRubyBot::Hooks::Message.new
    channel, user, message, attachments = parse(actual)

    expect(client).not_to receive(:message)
    message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments))
    true
  end

  private

  def parse(actual)
    actual = { message: actual } unless actual.is_a?(Hash)
    attachments = actual[:attachments]
    attachments = [attachments] unless attachments.nil? || attachments.is_a?(Array)
    [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message], attachments]
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
slackrb-0.17.1 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slackrb-0.17.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slack-ruby-bot-0.16.1 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slack-ruby-bot-0.16.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slack-ruby-bot-0.15.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slack-ruby-bot-0.14.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb
slack-ruby-bot-0.13.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb