Class: Logux::Test::Matchers::ResponseChunks

Inherits:
Base
  • Object
show all
Defined in:
lib/logux/test/matchers/response_chunks.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#expected

Instance Method Summary collapse

Methods inherited from Base

#supports_block_expectations?

Constructor Details

#initialize(meta:, includes:, excludes: []) ⇒ ResponseChunks

Returns a new instance of ResponseChunks.



11
12
13
14
15
# File 'lib/logux/test/matchers/response_chunks.rb', line 11

def initialize(meta:, includes:, excludes: [])
  @meta = meta
  @includes = includes
  @excludes = excludes
end

Instance Attribute Details

#excludesObject (readonly)

Returns the value of attribute excludes.



9
10
11
# File 'lib/logux/test/matchers/response_chunks.rb', line 9

def excludes
  @excludes
end

#includesObject (readonly)

Returns the value of attribute includes.



9
10
11
# File 'lib/logux/test/matchers/response_chunks.rb', line 9

def includes
  @includes
end

#metaObject (readonly)

Returns the value of attribute meta.



9
10
11
# File 'lib/logux/test/matchers/response_chunks.rb', line 9

def meta
  @meta
end

Instance Method Details

#failure_messageObject



23
24
25
26
27
28
29
# File 'lib/logux/test/matchers/response_chunks.rb', line 23

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/logux/test/matchers/response_chunks.rb', line 17

def matches?(actual)
  @actual = JSON.parse(actual.body)

  match_includes? && match_excludes?
end