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

Version Path
bot-0.0.46 lib/bot/rspec/matchers.rb
bot-0.0.45 lib/bot/rspec/matchers.rb
bot-0.0.44 lib/bot/rspec/matchers.rb
bot-0.0.43 lib/bot/rspec/matchers.rb
bot-0.0.42 lib/bot/rspec/matchers.rb
bot-0.0.41 lib/bot/rspec/matchers.rb
bot-0.0.40 lib/bot/rspec/matchers.rb
bot-0.0.39 lib/bot/rspec/matchers.rb
bot-0.0.38 lib/bot/rspec/matchers.rb
bot-0.0.37 lib/bot/rspec/matchers.rb
bot-0.0.35 lib/bot/rspec/matchers.rb
bot-0.0.34 lib/bot/rspec/matchers.rb
bot-0.0.33 lib/bot/rspec/matchers.rb
bot-0.0.32 lib/bot/rspec/matchers.rb
bot-0.0.31 lib/bot/rspec/matchers.rb
bot-0.0.30 lib/bot/rspec/matchers.rb
bot-0.0.29 lib/bot/rspec/matchers.rb
bot-0.0.28 lib/bot/rspec/matchers.rb
bot-0.0.27 lib/bot/rspec/matchers.rb
bot-0.0.26 lib/bot/rspec/matchers.rb