Sha256: 8bd3c0281989c35ba2459105b931dd8309a1f4b0ca495513d970d975350a0c4f

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 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.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(" & ") || 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

12 entries across 12 versions & 1 rubygems

Version Path
wd_sinatra-1.0.0 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.3.2 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.3.1 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.3.0 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.6 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.5 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.4 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.3 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.2 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.1 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.2.0 lib/wd_sinatra/test_unit_helpers.rb
wd_sinatra-0.1.0 lib/wd_sinatra/test_unit_helpers.rb