Class: Phlex::Sorbet::RSpec::Matchers::AcceptProps

Inherits:
Object
  • Object
show all
Defined in:
lib/phlex/sorbet/rspec/matchers.rb

Overview

Matcher for validating that a component accepts specific props

Examples:

expect(MyComponent).to accept_props(user_id: 123)

Instance Method Summary collapse

Constructor Details

#initialize(props) ⇒ AcceptProps

Returns a new instance of AcceptProps.



170
171
172
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 170

def initialize(props)
  @props = props
end

Instance Method Details

#descriptionObject



196
197
198
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 196

def description
  "accept props #{@props.inspect}"
end

#failure_messageObject



187
188
189
190
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 187

def failure_message
  "expected #{@actual} to accept props #{@props.inspect}, " \
    "but it raised #{@raised_error.class}: #{@raised_error.message}"
end

#failure_message_when_negatedObject



192
193
194
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 192

def failure_message_when_negated
  "expected #{@actual} not to accept props #{@props.inspect}, but it did"
end

#matches?(component_class) ⇒ Boolean

Returns:

  • (Boolean)


174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 174

def matches?(component_class)
  @actual = component_class

  component_class.build_props(**@props)
  true
rescue Phlex::Sorbet::InvalidPropsError,
       Phlex::Sorbet::PropsNotDefinedError,
       ArgumentError,
       TypeError => e
  @raised_error = e
  false
end