Sha256: d21dc4f8eadfba4f4b27831d5cb6d6009adbde1c8c13eab679c60f52df780bc2

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

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

require 'rack/test'
require 'useless/doc/rack/application'
require 'useless/doc/rack/retriever'

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

  def app
    @app ||= Useless::Doc::Rack::Application.new('some-api')
  end

  it 'should return a 404 if the JSON cannot be retrieved' do
    Useless::Doc::Rack::Retriever::Stub.should_receive(:retrieve).
      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 API HTML if proper JSON is retrieved' do
    Useless::Doc::Rack::Retriever::Stub.should_receive(:retrieve).
      with('http://some-api.useless.io/').
      and_return(load_document('api.json'))

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

  it 'should return resource HTML if proper JSON is retrieved' do
    Useless::Doc::Rack::Retriever::Stub.should_receive(:retrieve).
      with('http://some-api.useless.io/some/resource').
      and_return(load_document('twonk.json'))

    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

1 entries across 1 versions & 1 rubygems

Version Path
useless-doc-0.2.3 spec/useless/doc/rack/application_spec.rb