Sha256: 13e47b89c81b0d5a2b7b15be7aac4cd4c9b00dcb13ddfc88c8ac8cb3e1c1f251

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

require 'wd_sinatra/test_helpers'

module TestUnitHelpers
  # Custom assertions
  def assert_api_response(response=nil, message=nil)
    response ||= TestApi.json_response
    print response.rest_response.errors if response.status === 500
    assert response.success?, message || ["Body: #{response.rest_response.body}", "Errors: #{response.errors}", "Status code: #{response.status}"].join("\n")
    service = WSList.find(response.verb, response.uri)
    raise "Service for (#{response.verb.upcase} #{response.uri}) 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(" & ") || message
    end
  end

  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wd_sinatra-2.0.0 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.6 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.5 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.4 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.3 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.2 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-1.0.1 lib/wd_sinatra/test_unit_helpers.rb