Top Level Namespace
Defined Under Namespace
Modules: TestApi, WD, WDSinatra Classes: JsonWrapperResponse, Requester, WeaselDiesel
Instance Method Summary collapse
-
#assert_api_response(response = nil, message = nil) ⇒ Object
Custom assertions.
- #assert_api_response_with_redirection(redirection_url = nil) ⇒ Object
Instance Method Details
#assert_api_response(response = nil, message = nil) ⇒ Object
Custom assertions
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/wd_sinatra/test_helpers.rb', line 184 def assert_api_response(response=nil, =nil) response ||= TestApi.json_response print response.rest_response.errors if response.status === 500 assert response.success?, || ["Body: #{response.rest_response.body}", "Errors: #{response.errors}", "Status code: #{response.status}"].join("\n") service = WSList.all.find{|s| s.verb == response.verb && s.url == response.uri[1..-1]} raise "Service for (#{response.verb.upcase} #{response.uri[1..-1]}) not found" unless service unless service.response.nodes.empty? assert response.body.is_a?(Hash), "Invalid JSON response:\n#{response.body}" valid, errors = service.validate_hash_response(response.body) assert valid, errors.join(" & ") || end end |
#assert_api_response_with_redirection(redirection_url = nil) ⇒ Object
197 198 199 200 201 202 203 204 |
# File 'lib/wd_sinatra/test_helpers.rb', line 197 def assert_api_response_with_redirection(redirection_url=nil) response = TestApi.json_response print response.rest_response.errors if response.status === 500 assert response.status == 302, "Redirection expect, but got #{response.status}" if redirection_url assert response.headers["location"], redirection_url end end |