Class: Phlex::Sorbet::RSpec::Matchers::RejectProps
- Inherits:
-
Object
- Object
- Phlex::Sorbet::RSpec::Matchers::RejectProps
- Defined in:
- lib/phlex/sorbet/rspec/matchers.rb
Overview
Matcher for validating that a component rejects invalid props
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(props) ⇒ RejectProps
constructor
A new instance of RejectProps.
- #matches?(component_class) ⇒ Boolean
- #with_error(error_class, message_pattern = nil) ⇒ Object
Constructor Details
#initialize(props) ⇒ RejectProps
Returns a new instance of RejectProps.
207 208 209 210 211 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 207 def initialize(props) @props = props @expected_error = nil @expected_message = nil end |
Instance Method Details
#description ⇒ Object
254 255 256 257 258 259 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 254 def description desc = "reject props #{@props.inspect}" desc += " with #{@expected_error}" if @expected_error desc += " matching #{@expected_message.inspect}" if @expected_message desc end |
#failure_message ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 236 def if @accepted "expected #{@actual} to reject props #{@props.inspect}, but it accepted them" elsif @expected_error && @raised_error && !@raised_error.is_a?(@expected_error) "expected #{@actual} to raise #{@expected_error}, but raised #{@raised_error.class}" elsif @expected_message && @raised_error "expected error message to match #{@expected_message.inspect}, " \ "but was #{@raised_error..inspect}" else "unexpected state in reject_props matcher" end end |
#failure_message_when_negated ⇒ Object
249 250 251 252 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 249 def "expected #{@actual} not to reject props #{@props.inspect}, " \ "but it raised #{@raised_error.class}" end |
#matches?(component_class) ⇒ Boolean
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 219 def matches?(component_class) @actual = component_class begin component_class.build_props(**@props) @accepted = true false rescue StandardError => e @raised_error = e return false if @expected_error && !e.is_a?(@expected_error) return false if @expected_message && @raised_error. !~ @expected_message true end end |
#with_error(error_class, message_pattern = nil) ⇒ Object
213 214 215 216 217 |
# File 'lib/phlex/sorbet/rspec/matchers.rb', line 213 def with_error(error_class, = nil) @expected_error = error_class @expected_message = self end |