Sha256: ec6e409d8c82fad2582d1749d52317d2d90acbaf1c6c94123a1a7f5f3707568b
Contents?: true
Size: 1.17 KB
Versions: 27
Compression:
Stored size: 1.17 KB
Contents
require 'rspec/expectations' module Bot module Rspec module Matchers RSpec::Matchers.define :be_to do |to_user| match do |sent_messages| Array.wrap(sent_messages).flatten.any? { |msg| msg["to"] == to_user } end end RSpec::Matchers.define :say do |body| match do |sent_messages| Array.wrap(sent_messages).flatten.any? { |msg| msg["body"] == body } end end RSpec::Matchers.define :match_message do |body| match do |sent_messages| Array.wrap(sent_messages).flatten.any? { |msg| msg["body"].match(body).present? } end end RSpec::Matchers.define :send_a_message_like do |expected_message| match do |sent_messages| Array.wrap(sent_messages).flatten.keep_if { |msg| matches_expected?(msg, expected_message) }.present? end def matches_expected?(sent, expected) !expected.reject { |k, v| sent[k] == v }.present? end end RSpec::Matchers.define :send do |expected_count| match do |sent_messages| Array.wrap(sent_messages).flatten.count == expected_count end end end end end
Version data entries
27 entries across 27 versions & 1 rubygems