Class: Line::Message::RSpec::Matchers::HaveTextMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/line/message/rspec/matchers/have_text_message.rb

Overview

The text message matcher for RSpec to search for text messages in the message array.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveTextMessage

Returns a new instance of HaveTextMessage.



10
11
12
13
# File 'lib/line/message/rspec/matchers/have_text_message.rb', line 10

def initialize(expected)
  @text, @options = expected
  @options = Utils.stringify_keys!(@options || {})
end

Instance Method Details

#descriptionObject



15
16
17
18
19
20
# File 'lib/line/message/rspec/matchers/have_text_message.rb', line 15

def description
  return "have text message" if @text.nil?
  return "have text message matching #{@text.inspect}" if @options.empty?

  "have text message matching #{@text.inspect} with options #{@options.inspect}"
end

#failure_messageObject



33
34
35
36
37
38
# File 'lib/line/message/rspec/matchers/have_text_message.rb', line 33

def failure_message
  return "expected to find a text message" if @text.nil?
  return "expected to find a text message matching #{@text.inspect}" if @options.empty?

  "expected to find a text message matching #{@text.inspect} with options #{@options.inspect}"
end

#matches?(actual) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/line/message/rspec/matchers/have_text_message.rb', line 22

def matches?(actual)
  @actual = Utils.stringify_keys!(actual, deep: true)
  @actual.any? do |message|
    next unless message["type"] == "text"
    next true if @text.nil?

    message["text"].match?(@text) && ::RSpec::Matchers::BuiltIn::Include.new(@options).matches?(message)
  end
end