Sha256: e90e12554529f54cb0756f25341d7955ad35d89799d345f135f4ec85e756eba8

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

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

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

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

  def app
    Useless::Doc::Rack.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('twonk.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

3 entries across 3 versions & 1 rubygems

Version Path
useless-doc-0.4.0 spec/useless/doc/rack_spec.rb
useless-doc-0.3.1 spec/useless/doc/rack_spec.rb
useless-doc-0.3.0 spec/useless/doc/rack_spec.rb