Module: HttpDecoy::Minitest::Assertions

Defined in:
lib/http_decoy/minitest.rb

Overview


Minitest assertions

Instance Method Summary collapse

Instance Method Details

#assert_received_request(server, method, path, times: nil, body: nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/http_decoy/minitest.rb', line 133

def assert_received_request(server, method, path, times: nil, body: nil)
  entries     = server.request_log.for(method, path)
  description = "#{method.to_s.upcase} #{path}"

  if times
    assert_equal times, entries.count,
                 "expected #{description} to have been received #{times} time(s), " \
                 "but it was received #{entries.count} time(s)"
  else
    assert entries.any?, "expected #{description} to have been received, but it was never called"
  end

  return unless body

  assert entries.any? { |e| HttpDecoy::BodyMatcher.matches?(e.body, body) },
         "expected #{description} body to match #{body.inspect}, but received: #{entries.map(&:body).inspect}"
end

#refute_received_request(server, method, path) ⇒ Object



151
152
153
154
# File 'lib/http_decoy/minitest.rb', line 151

def refute_received_request(server, method, path)
  entries = server.request_log.for(method, path)
  assert entries.empty?, "expected #{method.to_s.upcase} #{path} not to have been received"
end