Sha256: b7b4fd364797118ca06178c566a7d78ea7f4561e52029911b5c5c4dfb36a45db
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require 'rspec/expectations' RSpec::Matchers.define :respond_with_error do |error, error_message| match do |actual| client = respond_to?(:client) ? send(:client) : SlackRubyBot::Client.new message_command = SlackRubyBot::Hooks::Message.new channel, user, message, attachments = parse(actual) allow(Giphy).to receive(:random) if defined?(Giphy) begin expect do message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments)) end.to raise_error error, error_message rescue RSpec::Expectations::ExpectationNotMetError => e @error_message = e.message raise e end true end failure_message do |actual| _, _, message = parse(actual) @error_message || "expected for '#{message}' to fail with '#{expected}'" 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
3 entries across 3 versions & 1 rubygems