Sha256: 6c539b574c013c7bffc8934000d413874088985952dab5dee4c68a3a637d9de6

Contents?: true

Size: 824 Bytes

Versions: 1

Compression:

Stored size: 824 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :respond_with_error do |expected|
  match do |actual|
    channel, user, message = parse(actual)
    app = SlackRubyBot::App.new
    allow(Giphy).to receive(:random)
    begin
      expect do
        app.send(:message, text: message, channel: channel, user: user)
      end.to raise_error ArgumentError, expected
    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

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-bot-0.2.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb