Sha256: 0986a8e6b9b593cf03344a08a5d0e68f36e547851eefad8171c3c2b9c44b5225

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'

require 'rack/test'
require 'useless/doc'
require 'useless/doc/proxy'
require 'useless/doc/client'

describe Useless::Doc::Proxy do
  include Rack::Test::Methods

  def app
    Useless::Doc::Proxy.new
  end

  it 'should return a 404 if the JSON cannot be retrieved' do
    Useless::Doc::Client.stub.should_receive(:get).
      with('http://some-api.useless.io/some/non-existant/resource').
      and_return(nil)

    get 'http://some-api.doc.useless.io/some/non-existant/resource'
    last_response.should be_not_found
  end

  it 'should return a 404 if the subdomain is unknown' do
    get 'http://some-other-api.doc.useless.io/some/non-existant/resource'
    last_response.should be_not_found
  end

  it 'should return domain HTML for the root path' do
    Useless::Doc::Client.stub.should_receive(:get).
      with('http://useless.io/').
      and_return(Useless::Doc.load.domain(load_document('domain.json').read))

    get 'http://doc.useless.io/'
    last_response.should be_ok
    last_response.body.should =~ /<h1>Useless<\/h1>/
  end

  it 'should return API HTML if proper JSON is retrieved' do
    Useless::Doc::Client.stub.should_receive(:get).
      with('http://some-api.useless.io/').
      and_return(Useless::Doc.load.api(load_document('api.json').read))

    get 'http://some-api.doc.useless.io/'
    last_response.should be_ok
    last_response.body.should =~ /<h1>Twonk API<\/h1>/
  end

  it 'should return resource HTML if proper JSON is retrieved' do
    Useless::Doc::Client.stub.should_receive(:get).
      with('http://some-api.useless.io/some/resource').
      and_return(Useless::Doc.load.resource(load_document('resource.json').read))

    get 'http://some-api.doc.useless.io/some/resource'
    last_response.should be_ok
    last_response.body.should =~ /<h1>\/twonks\/:id<\/h1>/
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
useless-doc-0.6.4 spec/useless/doc/proxy_spec.rb
useless-doc-0.6.3 spec/useless/doc/proxy_spec.rb
useless-doc-0.6.2 spec/useless/doc/proxy_spec.rb
useless-doc-0.6.1 spec/useless/doc/proxy_spec.rb
useless-doc-0.6.0 spec/useless/doc/proxy_spec.rb
useless-doc-0.5.0 spec/useless/doc/proxy_spec.rb