Sha256: f2b8ea9c08905e808463de455f3939367265c84daaa2562a32241b9cd5a156c0

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

require 'rspec/expectations'

RSpec::Matchers.define :respond_with_error do |error, error_message|
  match do |actual|
    allow(Giphy).to receive(:random)

    client = if respond_to?(:client)
               send(:client)
             else
               SlackRubyBot::Client.new
             end

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

    begin
      expect do
        message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user))
      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)
    [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-ruby-bot-0.8.2 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb
slack-ruby-bot-0.8.1 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb
slack-ruby-bot-0.8.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb