Sha256: 10eb147e200f9c98bfd5dee9899db6340f762fe0b4fc1fc530929c5e431de6a6
Contents?: true
Size: 1.19 KB
Versions: 4
Compression:
Stored size: 1.19 KB
Contents
require 'rspec/expectations' RSpec::Matchers.define :respond_with_error do |error, error_message| match do |actual| client = if respond_to?(:client) send(:client) else SlackRubyBot::Client.new end 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
4 entries across 4 versions & 1 rubygems