Class: RSpec::SSE::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- RSpec::SSE::Matchers::BaseMatcher
- Defined in:
- lib/rspec/sse/matchers.rb
Direct Known Subclasses
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected, json: false) ⇒ BaseMatcher
constructor
Initialize the matcher with expected values.
-
#match_arrays(actual_array, expected_array) ⇒ Object
Check if two arrays match element by element Supports RSpec matchers as expected values.
-
#match_items(actual_item, expected_item) ⇒ Object
Check if individual items match Supports RSpec matchers as expected values.
- #matches?(actual) ⇒ Boolean
Constructor Details
#initialize(expected, json: false) ⇒ BaseMatcher
Initialize the matcher with expected values
185 186 187 188 |
# File 'lib/rspec/sse/matchers.rb', line 185 def initialize(expected, json: false) @expected = expected @json = json end |
Instance Method Details
#failure_message ⇒ Object
233 234 235 |
# File 'lib/rspec/sse/matchers.rb', line 233 def "Expected #{description_for(@actual)} to #{description}" end |
#failure_message_when_negated ⇒ Object
238 239 240 |
# File 'lib/rspec/sse/matchers.rb', line 238 def "Expected #{description_for(@actual)} not to #{description}" end |
#match_arrays(actual_array, expected_array) ⇒ Object
Check if two arrays match element by element Supports RSpec matchers as expected values
214 215 216 217 218 219 220 221 222 |
# File 'lib/rspec/sse/matchers.rb', line 214 def match_arrays(actual_array, expected_array) return false unless actual_array.size == expected_array.size actual_array.each_with_index do |actual_item, index| expected_item = expected_array[index] return false unless match_items(actual_item, expected_item) end true end |
#match_items(actual_item, expected_item) ⇒ Object
Check if individual items match Supports RSpec matchers as expected values
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/rspec/sse/matchers.rb', line 196 def match_items(actual_item, expected_item) if expected_item.respond_to?(:===) # It's an RSpec argument matcher (hash_including, etc.) expected_item === actual_item elsif expected_item.respond_to?(:matches?) # It's an RSpec regular matcher expected_item.matches?(actual_item) else actual_item == expected_item end end |
#matches?(actual) ⇒ Boolean
226 227 228 229 230 |
# File 'lib/rspec/sse/matchers.rb', line 226 def matches?(actual) @actual = actual @parsed_events = SseParser.parse(actual.body) match_condition end |