-
Notifications
You must be signed in to change notification settings - Fork 20
/
response_chunks.rb
48 lines (39 loc) · 1.11 KB
/
response_chunks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
require_relative 'base'
module Logux
module Test
module Matchers
class ResponseChunks < Base
attr_reader :includes, :excludes, :meta
def initialize(meta:, includes:, excludes: [])
@meta = meta
@includes = includes
@excludes = excludes
end
def matches?(actual)
@actual = JSON.parse(actual.body)
match_includes? && match_excludes?
end
def failure_message
data = "expected that #{pretty(@actual)} to has " \
"#{includes.join(', ')} chunks"
!excludes.empty? && data += " and doesn't" \
" has #{excludes.join(', ')} chunks"
data
end
private
def match_includes?
@actual.any? do |command|
command.first.in?(includes) &&
(meta.nil? || (meta.present? && command[1] == meta))
end
end
def match_excludes?
@actual.empty? || @actual.none? do |command|
command.first.in?(excludes)
end
end
end
end
end
end