Sha256: 9707d1ff5d81ac58ed9904dbeb9210863b770f2017d842e7dd7da205aedfb475

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 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
    SlackRubyBot.config.user = 'rubybot'
    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.1.0 lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb