Class: Line::Message::RSpec::Matchers::HaveFlexComponent

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

Overview

The flex component matcher for RSpec to search nested flex components in the message array.

Instance Method Summary collapse

Constructor Details

#initialize(expected_desc: nil, &expected) ⇒ HaveFlexComponent

Returns a new instance of HaveFlexComponent.



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

def initialize(expected_desc: nil, &expected)
  @expected = expected
  @expected_desc = expected_desc
end

Instance Method Details

#descriptionObject



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

def description
  return "have flex component" if @expected.nil?
  return "have flex component matching #{@expected_desc}" if @expected_desc

  "have flex component matching #{@expected.inspect}"
end

#failure_messageObject



28
29
30
31
32
33
# File 'lib/line/message/rspec/matchers/have_flex_component.rb', line 28

def failure_message
  return "expected to find a flex component" if @expected.nil?
  return "expected to find a flex component matching #{@expected_desc}" if @expected_desc

  "expected to find a flex component matching #{@expected.inspect}"
end

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

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/line/message/rspec/matchers/have_flex_component.rb', line 22

def matches?(actual)
  @actual = Utils.stringify_keys!(actual, deep: true)
  @actual.any? { |message| match_flex_component?(message) }
end